I’m trying to use padding in a div and which is wrapped by another div (‘container’), apologize for this simple question, but I couldn’t find an answer.
As long as I don’t use padding:10px; the structure of the page is stable.
i.e. the right div is floating to the left (‘content’ is aside ‘sidebar’).
<html>
<head>
<style type="text/css">
.container {
max-width: 960px;
background-color: RED;
height: 200px;}
.sidebar {
background-color: GREEN;
width: 30%;
float: left;}
.content {
background-color: YELLOW;
float: left;
width: 70%;
padding: 10px;}
</style>
</head>
<body>
<div class="container">
<div class="sidebar">
<p>text in sidebar</p>
</div>
<div class="content">
<p>text in content</p>
</div>
</div>
</body>
</html>
When using padding:10px; the right div (‘content’) goes down under ‘sidebar’ instead floating to the side of ‘sidebar’.
I’ve tried clear: left; (right, both) but it doesn’t help me.
Any solution for the above and which is not particular style to <p> ,would be appreciated.
In order to avoid going over 100% of the page width and bumping
.contentdown, you may have to make some compromises. I can think of a few solutions:1) Pad all direct children of
.content
2) Pad
.contentusing percentage3) Change the behavior of the box model
All three of these solutions incur some bad things.
.contentcould cause problems down the line when you want to give an element padding other than 10px..contentusing percentage will look slightly different on different sized windows.