Reputation: 2092
Hi everyone i want o display 3 elements in a row. I have tried the following code but it is not displaying them correctly.
<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>
It is displaying like this
I want to create it like the sample image
Upvotes: 4
Views: 25186
Reputation: 1
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>
Upvotes: 0
Reputation: 2092
Here i have written some code that might solve this issue (:
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>
Upvotes: 0
Reputation: 82231
Give display property inline-block
for inner divs:
display:inline-block;
Update:
you need to set the height for div that has jo will fix it
as other to div have images in them:
<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>
Upvotes: 7
Reputation: 772
To display all <div>
elements in one row you can just try:
display:'flex'
Upvotes: 1
Reputation:
add height to your second div which is not correctly displayed like
<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>
Add like style="height=40px; ..."
Upvotes: 0
Reputation: 5133
Add display: inline-block;
to the child divs.
Set the height of the child divs:
height: 20px /* or in %, em, etc */;
height: inherit;
which gives the height from the parent div to the children divsFrom W3Schools:
The inherit keyword specifies that a property should inherit its value from its parent element.
The inherit keyword can be used for any CSS property, and on any HTML element.
Upvotes: 2
Reputation: 74738
If you want a quick fix then you can use another element with clear:both;
property:
'</div> <br style="clear:both; height:0;" />';
Upvotes: 0