0

I have a responsive UL List , many Li ImageItem and span are in this Ul. on maximize size 3 item shows in one row and when I resize ( small) my browser, 2 item shows and it works fine. But in smallest size of my browser horizontal scroll appear :( 1 item shows but scroll appear, how I can prevent horizontal scroll?! this is my css :

.myUl {
    font-size:large !important;
    color:#373636 !important;
    text-align:center !important;
}
.myUl li {
    width:350px !important;
}
.myUl li:hover {
    background:rgba(0, 0, 0, 0.2) !important;
}
.myUl li img {
    height:170px !important;
    width:100px !important;
}
.myUl li span {
    float:right !important;
    width:170px;
    padding-right:8px !important;
    padding-top:10px !important;
    text-align:right !important;
    vertical-align:middle !important;
    line-height: 1.5em !important;
}
ul.img-list {
    list-style-type: none;
    margin: 0;
    padding: 0;
    text-align: center;
}
ul.img-list li {
    display: inline-block;
    height: 180px;
    margin: 0 1em 1em 0;
    position: relative;
    width: 150px;
}
ul.img-list li:hover span.text-content {
    opacity: 1;
}

this is my Index.cshtml

<div>
    <ul class="img-list myUl">
        <li>
            <span>
                some text here
            </span>
            <span style="float: left !important; padding-top: 3px !important;">
                <a>
                    <img class="img-responsive img-circle img-thumbnail" src="~/Images/MenuImages/z.jpg"  />
                </a>
            </span>
        </li>
        <li>
           .........
        </li>
  </ul>

an image of my page

3
  • Which element is causing the scrolling? Inspect the element and let me know :) Commented Nov 23, 2015 at 6:07
  • can you please share any jsfiddle or working demo where we can see issue in live? that will help..thanx Commented Nov 23, 2015 at 6:09
  • 1
    really I don't know which element causing this , I changes every thing but still scroll appear Commented Nov 23, 2015 at 6:18

2 Answers 2

3

To prevent horizontal scrolling just add this to your body tag in Css like such :

body {
    overflow-x: hidden;
}

Hope this helped

Sign up to request clarification or add additional context in comments.

1 Comment

No problem glad I could help @shimaamini
0

Your following code may leads to horizontal scrolling when screen width is going less than 360px,

.myUl li {
  width:350px !important;
}


When the browser size goes below 350px your browser will shows a horizontal scrollbar If u need to overcome this issue you are required to write a media query for this, Like the following:

@media only screen and (max-width: 360px) {
  .myUl li {
      width:100% !important;
  }
}

also u can be use the property body { overflow-x: hidden; }

2 Comments

Thanks , myUL li is the reason , when I remove this css , Horizonatl scroll not appear . I insert you Media code but it doesn't work and horizonatll scrool appear :/
ok then you are required to add an body{overflow-x:hidden}. This works fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.