[英]How can i Display div Elements in one row
大家好,我想連續顯示 3 個元素。 我嘗試了以下代碼,但沒有正確顯示它們。
<div id="mainDiv" style="background-color:#f77f00; width:90%; margin-right:5%; margin-left:5%; margin-bottom:1%; margin-top:1%;" >
<div id="left" onclick="Deletefav(this)" style="display: inline; width:20%; float:left; ">'+
'<img style="display: inline;" src="" />
</div>'+
<div id="center" onclick="" style=" width:30%; display: inline;text-align: center; margin:10%;">
<p style="display: inline;"><font color="#fff" face="verdana" size="4">testing</font></p>
</div>
<div id="right" onclick="Callfav(this)" style="display: inline; width:20%; float:right;">
<img style="display: inline;" src="" />
</div>
</div>
它是這樣顯示的
我想像示例圖像一樣創建它
為內部 div 提供顯示屬性inline-block
:
display:inline-block;
更新:
您需要設置具有jo will fix it
,因為其他 div 中包含圖像:
<div id="${id}" style=" background-color: #f77f00; width: 90%; margin-right: 5%; margin-left: 5%; margin-bottom: 1%; margin-top: 1%; " > <div id="${_id}" onclick="Deletefav(this)" style="background-color: #f77f00; float: left; width: 20%; display: inline-block" > <img style="" src="${del_image}" /> <font color="#fff" face="verdana" size="1">delete</font> </div> <div id="${_id}" onclick="" style="background-color: #f77f00; float: left; width: 50%; display: inline-block; height: 25px" > <font color="#fff" face="verdana" size="4">${name}</font> </div> <div id="${_id}" onclick="Callfav(this)" style="background-color: #f77f00; float: left; width: 20%; display: inline-block" > <img style="" src="${call_image}" /><font color="#fff" face="verdana" size="1">call</font> </div> </div>
添加display: inline-block;
給孩子的div。
設置子 div 的高度:
height: 20px /* or in %, em, etc */;
height: inherit;
它給出了從父 div 到子 div 的高度來自 W3Schools:
inherit 關鍵字指定屬性應從其父元素繼承其值。
inherit 關鍵字可用於任何 CSS 屬性和任何 HTML 元素。
如果你想快速修復,那么你可以使用另一個元素clear:both;
財產:
'</div> <br style="clear:both; height:0;" />';
將高度添加到您的第二個未正確顯示的 div
<div id="${_id}" onclick="" style="height=40px; background-color:#f77f00; float:left; width:50%;">
<p style="">
<font color="#fff" face="verdana" size="4">${name}</font>
</p>
</div>
添加like style="height=40px; ..."
在這里,我編寫了一些可能解決此問題的代碼(:
section > div { display: table-cell; width: 33%; text-align: center; background-color:#f77f00; text-align: center; vertical-align: middle; margin:10%; } section { display: table; width: 100%; margin:1%; }
<section style="background-color:#f77f00; text-align: center; vertical-align: middle;"> <div> <img style=" " src="http://i58.tinypic.com/16c9ulk.png" /> </div> <div> <p style=""><font color="#000" face="verdana" size="4">JO willl fix it </font> </p> </div> <div> <img style="" src="http://i59.tinypic.com/b4ddtu.png" /> </div> </section> <section style="background-color:#f77f00; text-align: center; vertical-align: middle;"> <div> <img style=" " src="http://i58.tinypic.com/16c9ulk.png" /> </div> <div> <p style=""><font color="#fff" face="verdana" size="4">JO willl fix it </font> </p> </div> <div> <img style="" src="http://i59.tinypic.com/b4ddtu.png" /> </div> </section>
要在一行中顯示所有<div>
元素,您可以嘗試:
display:'flex'
body { margin: 0; padding: 0; } .container { margin: 25% 5%; display: inline-flex; column-gap: 10px; justify-content: center; align-items: center; width: 100%; } .container .child { border: 0 solid #000; padding: 5px; width: 40%; text-align: center; background-color: #ff0012; color: #ffffff; border-radius: 5px; }
<html> <body> <div class="container"> <div class="child"> <p>Some text</p> </div> <div class="child"> <p>Some more text</p> </div> <div class="child"> <p>Much more text</p> </div> </div> </body> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.