I've tried every suggestion I could find (most of them involving white-space:nowrap
and display:inline-block
) but so far nothing has worked to get these child divs to stay on one line and scroll horizontally.
<div id="list">
<a href="javascript:show('shown','id1','a1');"><div id="a1" class="inactive">link1</div></a>
<div id="spacer"></div>
<a href="javascript:show('shown','id2','a2');"><div id="a2" class="inactive">link2</div></a>
<div id="spacer"></div>
<a href="javascript:show('shown','id3','a3');"><div id="a3" class="inactive">link3</div></a>
<div id="spacer"></div>
<a href="javascript:show('shown','id4','a4');"><div id="a4" class="inactive">link4</div></a>
<div id="spacer"></div>
<a href="javascript:show('shown','id5','a5');"><div id="a5" class="inactive">link5</div></a>
<div id="spacer"></div>
<a href="javascript:show('shown','id6','a6');"><div id="a6" class="inactive">link6</div></a>
</div>
Essentially this is a navigation bar for mobile devices that scrolls horizontally.
The normal version has this bar vertical (working fine) and the "spacer" div is used as a divider, switching from a horizontal rule to a vertical rule.
You can force the content of the HTML <div> element stay on the same line by using a little CSS. Use the overflow property, as well as the white-space property set to “nowrap”.
Set size and make inline Because they're block elements, when reducing the size of Div one to make room for the other div, you're left with space next to Div one and Div two below Div one. To move the div up to the next line both div's need to have the inline-block display setting as shown below.
By default, if we have multiple div tags it will be displayed one below the other. In othere words, each div will be displayed in a separate line. To display multiple div tags in the same line, we can use the float property in CSS styles. The float property takes left, right,none(default value) and inherit as values.
You're looking for white-space: nowrap;
http://jsfiddle.net/ySMdY/1/
#list {
white-space: nowrap;
}
#list a, #list a div, #list .spacer {
display: inline-block;
}
#list a {
/* just some styles so I can see it working */
background-color: rgba(0, 0, 0, 0.5);
padding: 0 50px;
}
ALSO: IDs are supposed to unique per page. You can't have multiple #spacer
div
s, you should only have one. If you want multiple, class
is the way to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With