I mean, the two tags have the same height.
6 Answers
Try this for all divs.
display:inline-block;
-
+1 display:inline isn't flexible enough and floats are messy! Commented Dec 3, 2010 at 4:18
Simple: use <span>
s instead.
<div>
by default have display: block
, meaning the next element will be on a new line.
You can change them to display: inline
to get the behavior you want. But remember that an inline <div>
is just a <span>
.
Use a div container and put inside all your divs.
.div_container{
display: flex;
flex-direction: row;
}
That easy!
Make them float:
HTML
<div class="container1"></div>
<div class="container2"></div>
<div class="clear"></div>
CSS
.clear { clear: both; }
.container1, .container2 { float: left; }
You have to clear the float.. so use clear both :)
Float messes up my page center alignment. Here's what I got, I want to get 2 and 3 on the same row without losing the page centering. Float doesn't work because when I resize the browser,it moves with it.
<head>
<meta http-equiv="Content-Language" content="en-us">
<style type="text/css">
.div1 {
background: #faa;
width: 500;
}
.div2 {
background: #ffc;
width: 400;
margin-right: 100px;
}
.div3 {
background: #cfc;
width: 100;
margin-left: 400px;
}
</style>
</head>
<html>
<body>
<center>
<div class="div1"> This is no 1</div>
<div class="div2"> This is no 2</div>
<div class="div3"> This is no 3</div>
</center>
</body>
</html>