Skip to content Skip to sidebar Skip to footer

Overflow-x: Auto And Line Background Color Visibility On Scroll

I have the following HTML and CSS defined to have the horizontal scroll when I have overflow and at the same time, apply the background color for each line: CSS: ul.list { list-s

Solution 1:

You can try to add display: table-row to your css ul.list li

ul.listli {
  margin: 0;
  padding: 010px;
  display: table-row;
}

https://jsfiddle.net/sLbgmq8s/13/

Solution 2:

A solution would be to change your LI elements to

display: inline-block;

Demonstration

Solution 3:

After struggling a bit, I finally figured out the correct answer. Big thanks to @mirek for heading me to the right direction.

First of all, you need to set ul display as table and li display as table-row. Then, set both widths' to 100%. Final touch is to wrap ul inside a div and give that div the scroll behavior. This works well for all the cases. Here is the update version of the jsfiddle: https://jsfiddle.net/sLbgmq8s/22/

CSS:

div.wrapper {
    overflow-x: auto;
}

ul.list {
    list-style-type: none;
    padding: 0;
    margin: 0;
    text-align: left;
    display: table;
    width: 100%;
}
.highlight {
    background-color: red;
}
ul.listli {
    margin: 0;
    padding: 0;
    display: table-row;
    width: 100%;
}
.content-holder {
    font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
    font-size: 12px;
    color: #333;
    white-space: pre;
    overflow: visible;
    -ms-word-wrap: normal;
    word-wrap: normal;
}

HTML:

<divclass="wrapper"><ulclass="list"><li><spanclass="content-holder">foo</span></li><li><spanclass="content-holder">foo foo foo foo foo foo</span></li><liclass="highlight"><spanclass="content-holder">bar bar bar bar bar bar bar barbar bar bar bar bar barbar bar bar bar bar barbar bar bar bar bar bar</span></li></ul></div>

Solution 4:

the problem is you're not targeting the span element containing text

.highlight > span{...}

FIDDLE

Post a Comment for "Overflow-x: Auto And Line Background Color Visibility On Scroll"