I have a parent div (main) with the horizontal overflow set to auto. I then have a child element (columns) that has all of my column properties on it. The problem is that once the content goes further than the viewport I can no longer control the right hand margins or padding as the column only seems to go as far as the viewport. For example when I put a background color on “columns” the background only goes as far as the edge of the viewport even though the content scrolls further than that.
.main {
overflow-x: visible;
overflow-y: hidden;
width: 100%;
}
.columns {
background: red;
column-fill: auto;
column-width: 670px;
column-gap: 80px;
height: 120px;
padding: 20px;
width: auto;
}
<div class="main">
<div class="columns">
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
</div>
</div>
Here is an example: http://jsfiddle.net/fyG24/
New Answer: Use Pseudo-Elements to Help
Based on your comments, here is new the fiddle that I believe meets your desires. It adds an extra
divwrapping.columnsI labeled.scroller, and the following css:I use a pseudo-element in
.mainto give the background for.columnsset to the explicit height you intend for those, then I also use another pseudo-element in the lastpto force rendering the final 20px of the column. It should work no matter how long or what part it takes up, and atheight: 1pxandmargin-top: -1pxit should not generate a new column if it falls right at the end of a column of text.Original Answer: Move Overflow and Set a Right Margin
To get the
backgroundto transfer, you need to change some CSS, namely:This seems to be because the
.columnbackground is being limited by the100%width on the.mainwhich is in control of the horizontal scroll bar in your original code. By making.mainpurely hidden, then settingoverflow-x: autoon.columns, the scroll is now controlled by the.columnsdiv, and allows itsbackgroundto be seen.To fix the absence of padding on the far right side, the only think I could come up with was to add the following:
This puts a right margin on the last
pelement of the immediate children of.columnswhich then gave the look I assume you are going for.Here’s the fiddle modified (tested only in Firefox).