Reputation: 613
I'm trying to have the layout shown in the picture, facebook icon and text side by side. I cannot get that clearly.
My tried code:
CSS
.iconDetails {
margin-left:2%;
float:left;
height:40px;
width:40px;
}
.container2 {
width:100%;
height:auto;
padding:1%;
}
HTML
<div class='container2'>
<div>
<img src='http://ecx.images-amazon.com/images/I/21-leKb-zsL._SL500_AA300_.png' class='iconDetails'>
</div>
<div style='margin-left:60px;'>
<h4>Facebook</h4>
<div style="font-size:.6em">fine location, GPS, coarse location</div>
<div style="float:right;font-size:.6em">0 mins ago</div>
</div>
</div>
My JSFiddle
Upvotes: 18
Views: 212106
Reputation: 168
HTML
<div class='containerBox'>
<div>
<img src='http://ecx.images-amazon.com/images/I/21-leKb-zsL._SL500_AA300_.png' class='iconDetails'>
<div>
<h4>Facebook</h4>
<div style="font-size:.6em;float:left; margin-left:5px;color:white;">fine location, GPS, coarse location</div>
<div style="float:right;font-size:.6em; margin-right:5px; color:white;">0 mins ago</div>
</div>
</div>
</div>
CSS
.iconDetails {
margin-left:2%;
float:left;
height:40px;
width:40px;
}
.containerBox {
width:300px;
height:60px;
padding:1px;
background-color:#303030;
}
h4{
margin:0px;
margin-top:3%;
margin-left:50px;
color:white;
}
Upvotes: 0
Reputation: 5064
Use following code : jsfiddle.net/KqHEC/
HTML
<div class='container2'>
<div class="left">
<img src='http://ecx.images-amazon.com/images/I/21-leKb-zsL._SL500_AA300_.png' class='iconDetails'>
</div>
<div class="right" >
<h4>Facebook</h4>
<div style="font-size:.7em;width:160px;float:left;">fine location, GPS, coarse location</div>
<div style="float:right;font-size:.7em">0 mins ago</div>
</div>
</div>
CSS
.iconDetails {
margin-left:2%;
float:left;
height:40px;
width:40px;
}
.container2 {
width:270px;
height:auto;
padding:1%;
float:left;
}
h4{margin:0}
.left {float:left;width:45px;}
.right {float:left;margin:0 0 0 5px;width:215px;}
Upvotes: 2
Reputation: 1090
It's always worth grouping elements into sections that are relevant. In your case, a parent element that contains two columns;
HTML:
<div class='container2'>
<img src='http://ecx.images-amazon.com/images/I/21-leKb-zsL._SL500_AA300_.png' class='iconDetails' />
<div class="text">
<h4>Facebook</h4>
<p>
fine location, GPS, coarse location
<span>0 mins ago</span>
</p>
</div>
</div>
CSS:
* {
padding:0;
margin:0;
}
.iconDetails {
margin:0 2%;
float:left;
height:40px;
width:40px;
}
.container2 {
width:100%;
height:auto;
padding:1%;
}
.text {
float:left;
}
.text h4, .text p {
width:100%;
float:left;
font-size:0.6em;
}
.text p span {
color:#666;
}
Upvotes: 2
Reputation: 9947
remove the margin for the h4 tag
h4 {
margin:0px;
}
Fiddle link
http://jsfiddle.net/Vinay199129/s3Qye/
Upvotes: 1
Reputation: 4882
Your h4 has some crazy margin on it, so remove it
h4 {
margin:0px;
}
edit:
for the 0 minutes text, added a float left to the first div, but personally i'd just combine them, although you may have reasons not to.
Upvotes: 26
Reputation: 9117
You're already doing it correctly, it just that the <h4>Facebook</h4>
tag is taking too much vertical margin. You can remove it by using the style margin:0px
on the <h4>
tag.
For your future convenience, you can put border (border:1px solid black
) on your elements to see which part you actually get it wrong.
Upvotes: 6