I'm trying to have the [as shown in picture] , facebook icon and text side by side. I cannot able to 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
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;}
remove the margin for the h4 tag
h4 {
margin:0px;
}
Fiddle link
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.
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;
}
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;
}
Source: Stackoverflow.com