Here is a very simple html code to float the sidebar towards right. The browser output shows the sidebar (floated element) one line below. The link to the picture of my browser output is shown below
How come the floated element is displayed one line below? Even the main content appears one line above the floated element.
#header {
background-color: #af7ac5;
font-size: 90px;
}
#sidebar {
background-color: #bdc3c7;
font-size: 30px;
float: right;
width: 200px;
display: inline-block;
}
#maincontent {
background-color: dc7633;
font-size: 30px;
margin-right: 220px;
}
#footer {
font-size: 50px;
background-color: #2ecc71;
clear: right;
}
<p id="header">Header</p>
<p id="sidebar">Sidebar Sidebar Sidebar Sidebar Sidebar Sidebar Sidebar Sidebar Sidebar Sidebar Sidebar Sidebar Sidebar Sidebar Sidebar Sidebar
</p>
<p id="maincontent">This is main content This is main content This is main content This is main content This is main content This is main content This is main content This is main content This is main content This is main content This is main content This is main content
This is main content This is main content
</p>
<p id="footer">Footer</p>
` tags typically having a margin before and after the element, you'll see margin tops and bottoms on all of the `
` elements in your code.
– user1795832 Sep 25 '17 at 17:25