You can make the contents of HTML <p>, <div>, and <span> elements not to wrap by using some CSS. You need the white-space property.
You can add white-space: nowrap to the p tag css and it will stop the wrapping.
Add white-space: nowrap; to your . layout style declaration. This will do exactly what you need: preventing the divs from wrapping.
All you need to do is apply display:inline-block to the appropriate <a> tags. This is nice, since it also prevents wrapping after hyphens.
Try using white-space: nowrap;
in the container style (instead of overflow: hidden;
)
If I don't want to define a minimal width because I don't know the amount of elements the only thing that worked to me was:
display: inline-block;
white-space: nowrap;
But only in Chrome and Safari :/
The following worked for me without floating (I modified your example a little for visual effect):
.container
{
white-space: nowrap; /*Prevents Wrapping*/
width: 300px;
height: 120px;
overflow-x: scroll;
overflow-y: hidden;
}
.slide
{
display: inline-block; /*Display inline and maintain block characteristics.*/
vertical-align: top; /*Makes sure all the divs are correctly aligned.*/
white-space: normal; /*Prevents child elements from inheriting nowrap.*/
width: 100px;
height: 100px;
background-color: red;
margin: 5px;
}
<div class="container">
<div class="slide">something something something</div>
<div class="slide">something something something</div>
<div class="slide">something something something</div>
<div class="slide">something something something</div>
</div>
The divs may be separated by spaces. If you don't want this, use margin-right: -4px;
instead of margin: 5px;
for .slide
(it's ugly but it's a tricky problem to deal with).
The combo you need is
white-space: nowrap
on the parent and
display: inline-block; // or inline
on the children
This worked for me:
.container {
display: inline-flex;
}
.slide {
float: left;
}
<div class="container">
<div class="slide">something1</div>
<div class="slide">something2</div>
<div class="slide">something3</div>
<div class="slide">something4</div>
</div>
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
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