amansoni211 amansoni211 - 3 months ago 10
CSS Question

Horizontal scroll content in fixed width div

It is the mobile view. the width in the link div is 100%. I want to horizontally scroll the content of this div without scrolling the whole page. below is the html code.

<div class="links">
<ul>
<li>Home</li>
<li>Private Equity</li>
<li>Venture Capital</li>
<li>M&A</li>
<li>Markets</li>
<li>Industry</li>
<li>Economy</li>
</ul>
</div>


and CSS

.links{
width: 100%

ul{
padding:0px;
margin:0px;

@media only screen and (max-width : 480px){
white-space: nowrap;
}
}

ul li{
list-style-type: none;
display: inline-block;
padding:8px 30px;
text-transform: uppercase;
font-family: $roboto;
font-size: 20px;
font-weight: 300;
font-stretch: condensed;
line-height: 1;
border-right:1px solid #000;

&:last-child{
border-right:0px;
}
}
}

Answer

All you need is an overflow-x: scroll on your div: https://jsfiddle.net/m5k5Lkm4/

Also, I don't know what you're using to load your HTML, but if it's raw HTML, you'll need that & in "M&A" to be escaped as an HTML entity.