Explanation
I want to line up three boxes in one line horizontally but the last one falls down.
When I remove the scrollbar, it lines up fine.
So, the problem is caused by the scrollbar width.
How can I ignore the scrollbar width in css?
Do I need to write JavaScript code to calculate the scrollbar width and adjust the width of the wrapper dom element?
DEMO & CODE
I posted html and css code in codePen.io.
http://codepen.io/anon/pen/kXAPap
HTML
<div id="main">
<ul id="window-list">
<li class="window">
<div class="window-thumbnail">
</div>
</li><!--
--><li class="window">
<div class="window-thumbnail">
</div>
</li><!--
--><li class="window">
<div class="window-thumbnail">
</div>
</li><!--
--><li class="window">
<div class="window-thumbnail">
</div>
</li><!--
--><li class="window">
<div class="window-thumbnail">
</div>
</li>
</ul>
</div>
CSS
body {
border-top: solid 1px #a3a1a3;
margin: 0;
padding: 20px;
background-color: #e7e7e7;
}
ul, li, p {
margin: 0;
padding: 0;
}
/*
1px(border-left) + 30px(padding-left) + 158px(width) + 18px(margin-right) + 158px(width) + 18px(margin-right) + 158px(width) + 30px(padding-right) + 1px(border-right) = 572px
*/
#main {
width: 572px;
}
#window-list {
background-color: #ffffff;
border: solid 1px #b8b8b8;
width: 510px;
height: 350px;
margin: 0 0 8px 0;
overflow: scroll; /*This line causes the problem*/
padding: 10px 30px;
list-style-type: none;
}
.window {
display: inline-block;
margin: 0 18px 18px 0;
}
.window:nth-child(3n) {
margin-right: 0;
}
.window-thumbnail {
margin: 0 0 8px 0;
height: 158px;
width: 158px;
border-radius: 8px;
cursor: pointer;
background-color: #e0e0e0;
}