9

I mean, the two tags have the same height.

6 Answers 6

16

Try this for all divs.

display:inline-block;
1
  • +1 display:inline isn't flexible enough and floats are messy!
    – David Tang
    Commented Dec 3, 2010 at 4:18
9

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>.

2

Float them with css:

float: left
2

Use a div container and put inside all your divs.

.div_container{
    display: flex;
    flex-direction: row;
}

That easy!

1

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 :)

1

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.