While developing a side scrolling div for mobile devices, I encountered an unusual issue. When the font-size is commented out for the body style in the code snippet below, extra margin is added to the sides of the .scroll_item. However, when the font-size is set to 0, everything works fine. I am trying to find a solution without setting the font size directly in the .scroll_item style and instead inherit it from the previous page element.
What could be causing this behavior and is there an alternative way to resolve it without having to set the font-size to 0?
body {
background-color: gray;
padding: 0;
margin: 0;
overflow: hidden;
/*font-size: 0;*/
}
#scroll_cont {
height: auto;
background-color: red;
margin: 0;
padding: 0;
white-space: nowrap;
overflow: auto;
}
.scroll_item {
width: 120px;
height: 120px;
padding: 5px;
margin: 2px;
background-color: blue;
box-sizing: border-box;
white-space: normal;
display: inline-block;
font-size: 20px;
color: white;
}
<html>
<head>
<title>Side Scroll Test</title>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1, user-scalable=no">
</head>
<body>
<div id="scroll_cont">
<div class="scroll_item">Test1</div>
<div class="scroll_item">Test2</div>
<div class="scroll_item">Test3</div>
<div class="scroll_item">Test4</div>
<div class="scroll_item">Test5</div>
</div>
</body>
</html>