简体   繁体   English

如何制作两个 <div> ... </div> 在同一行?

[英]How to make two <div>…</div> in the same row?

我的意思是,这两个标签具有相同的高度。

试试这个所有的div。

display:inline-block;

Simple: use <span> s instead . 简单: 使用<span> s代替

<div> by default have display: block , meaning the next element will be on a new line. 默认情况下, <div>display: block ,表示下一个元素将在新行上。

You can change them to display: inline to get the behavior you want. 您可以更改它们以display: inline以获得所需的行为。 But remember that an inline <div> is just a <span> . 但请记住,内联<div>只是一个<span>

用css浮动它们:

float: left

Use a div container and put inside all your divs. 使用div容器并放入所有div。

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

That easy! 那简单!

Float messes up my page center alignment. Float弄乱我的页面中心对齐。 Here's what I got, I want to get 2 and 3 on the same row without losing the page centering. 这就是我得到的,我希望在同一行上获得2和3而不会丢失页面居中。 Float doesn't work because when I resize the browser,it moves with it. Float不起作用,因为当我调整浏览器大小时,它随之移动。

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

Make them float: 让他们漂浮:

HTML HTML


<div class="container1"></div>
<div class="container2"></div>
<div class="clear"></div>

CSS CSS


.clear { clear: both; }
.container1, .container2 { float: left; } 

You have to clear the float.. so use clear both :) 你必须清除浮动..所以使用清除两个:)

如何在引导程序的同一行中制作两个不同的表。 用过的<div class="row"><div class="col">并排的两张桌子</div><div id="text_translate"><p>我需要那个总表或总行在同一行。 如需更多说明,请查看以下两张图片。</p><p> <a href="https://i.stack.imgur.com/xg9vH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xg9vH.png" alt="示例图片 1"></a></p><p> <a href="https://i.stack.imgur.com/c85e7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c85e7.png" alt="示例图像 2"></a></p></div></div> - How to make two different tables total in same line in bootstrap. Used <div class="row"><div class="col"> for two tables side by side

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使div在同一行中 - how to make to div in same row 如何使两个div和居中高度相同 - How to make same height two div and center 如何使div的一行文本和div的两个高度相同? - how to make div with one line of text and div with two the same height? 如何使同一行中的所有图像根据父 div 缩放? - How to make all images in the same row scale accordingly to parent div? 如何使具有两个元素的 div 行在移动设备中响应 - How to make a div row with two elements responsive in mobile 如何在引导程序的同一行中制作两个不同的表。 用过的<div class="row"><div class="col">并排的两张桌子</div><div id="text_translate"><p>我需要那个总表或总行在同一行。 如需更多说明,请查看以下两张图片。</p><p> <a href="https://i.stack.imgur.com/xg9vH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xg9vH.png" alt="示例图片 1"></a></p><p> <a href="https://i.stack.imgur.com/c85e7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c85e7.png" alt="示例图像 2"></a></p></div></div> - How to make two different tables total in same line in bootstrap. Used <div class="row"><div class="col"> for two tables side by side 如何使一个div里面有两个div? - How to make a div with two div inside? 如何使div跳起来 - How to make a div jump a row 如何在两个div中使用不同的数据提供相同的作用域? - How to make the same scope available in two div's with different data? 如何在同一列中的两个 DIV 之间制造间隙 - How to make a gap between two DIV within the same column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM