开发者

How to make two <div>...</div> in the same row?

I mean, the two tags have the same heig开发者_运维知识库ht.


Try this for all divs.

display:inline-block;


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


Float them with css:

float: left


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜