How to divide html page in two columns?
I am trying to divide my html page into two columns. One column is supposed to be filled by an image and other by text. I am facing below issues:
Columns not occupying the exact 50-50 width.
There is a thin margin from left before the image starts. Need to remove that margin.
There is a huge gap between the two columns.
It will be really helpful if someone can look at this code and suggest corrections:
.container img {
width: 100%;
}
.thin-black-border {
border-color: black;
border-width: 05px;
border-style: solid;
}
.header {
font: 200 80px'Oleo Script', Helvetica, sans-serif;
color: #2b2b2b;
text-shadow: 4px 4px 0px rgba(0, 0, 0, 0.1);
}
<link href='http://fonts.googleapis.com/css?family=Oleo+Script' rel='stylesheet' type='text/css'>
<div style="width:100%; height: 100px;background-color:green" class="bg-faded">
<!-- Main Div -->
<h1 class="text-center header">Madhubala</h1>
</div>
<div style="float:left;width:50%;" class="container">
<img src="https://nehamalude.files.wordpress.com/2011/02/madhubala.jpg" class="thin-black-border" />
</div>
<div style="float:left; width:50%; background-color:red; ">
Right
</div>
Solution 1:
You can simply use table : Method 1:
<table border="1">
<tr>
<td>You can add content here</td>
<td>You can add content here</td>
</tr>
</table>
Method 2:
<div style="display:block; width:100%;">
<div style="width:50%; float: left; display: inline-block;">Your content</div>
<div style="width:50%; float: left; display: inline-block;">Your content</div>
</div>
Method 3 ( Using Flex ) :
<div class="flexbox-container" style="display:flex;">
<div class="sidebar" style="flex:1;">Test column 1</div>
<div class="main" style="flex:1;">Test column 2</div>
</div>
Solution 2:
body{
margin: 0;
padding: 0;
}
.container img {
width: 100%;
}
.thin-black-border {
border-color: black;
border-width: 05px;
border-style: solid;
}
.header {
font: 200 80px'Oleo Script', Helvetica, sans-serif;
color: #2b2b2b;
text-shadow: 4px 4px 0px rgba(0, 0, 0, 0.1);
}
.main-wrap{
display: flex;
flex-direction: row;
}
.main-wrap > div{
flex: 1;
}
<link href='http://fonts.googleapis.com/css?family=Oleo+Script' rel='stylesheet' type='text/css'>
<div style="width:100%; height: 100px;background-color:green" class="bg-faded">
<!-- Main Div -->
<h1 class="text-center header">Madhubala</h1>
</div>
<div class="main-wrap">
<div class="container">
<img src="https://nehamalude.files.wordpress.com/2011/02/madhubala.jpg" class="thin-black-border" />
</div>
<div style="background-color:red; ">
Right
</div>
</div>
How about using display: flex
?