Reputation: 67
How should I keep the yellowarea
in middle of redarea
and greenarea
.
https://jsfiddle.net/ashish3506/4wopk1u3/1/
My HTML code
<body>
<span class="redarea"></span>
<span class="yellowarea"></span>
<span class="greenarea"></span>
</body>
My CSS Code
.redarea{
width:300px;
height:300px;
background:red;
float:left;
}
.yellowarea{
width:300px;
height:300px;
background:yellow;
margin-left:400px;
}
.greenarea{
float:right;
width:300px;
height:300px;
background:green;
}
Upvotes: 2
Views: 2452
Reputation: 191
Simply do this
span {
width:300px;
height:300px;
display:inline-block;
}
.redarea{
background:red;
}
.yellowarea{
background:yellow;
}
.greenarea{
background:green;
}
https://jsfiddle.net/theprog/4wopk1u3/7/
Upvotes: 2
Reputation: 3162
Check code once
.redarea{
width:200px;
height:300px;
background:red;
display: inline-block;
vertical-align: middle;
}
.yellowarea{
width:200px;
height:200px;
background:yellow;
display: inline-block;
vertical-align: middle;
margin: 0 20px;
}
.greenarea{
width:200px;
height:300px;
background:green;
display: inline-block;
vertical-align: middle;
}
<body>
<span class="redarea"></span>
<span class="yellowarea"></span>
<span class="greenarea"></span>
</body>
Upvotes: 1
Reputation:
Remove the floats and margins and add display:inline-block
.redarea {
width:300px;
height:300px;
background:red;
display:inline-block;
}
.yellowarea {
width:300px;
height:300px;
background:yellow;
display:inline-block;
}
.greenarea {
width:300px;
height:300px;
background:green;
display:inline-block;
}
Note: This does not resize the blocks for a smaller screen, so on JS Fiddle, it will appear that they stack. If the width of the page is sufficient for 900px, then they will appear side by side.
Upvotes: 0