Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text floating in block next to image

Tags:

html

css

I would like to achieve the following placement:

Two different texts (in block) floating / inline next to image. (Everything inside div).

I have been trying with different display settings (block + inline for text etc.) but it is still not working.

enter image description here

HTML:

<div class="res"> <img src="<?php echo 'img/'.$row["sType"].'.png';?>"/> <span>TITLEe</span> <span>Description</span> </div>   

CSS:

.res {      height:60px;     background-color:yellow;     border-bottom:1px solid black;     text-align:left;  }  .res img {      margin-top:8.5px;     margin-left:5px;     display:inline }  .res span {      display:block; } 
like image 859
John Avatar asked Aug 07 '12 11:08

John


People also ask

How do I float text beside a picture?

in order to have text on the left or right of the image you can style your img as style="float:left"; or style="float:right"; If the text is too close to the image you can play with padding: 10px; or less.

How do I align text next to an image in HTML?

Use display: inline-block and vertical-align: top to Place the Text Next to an Image in HTML. We can use the display and vertical-align properties to place a text next to an image in HTML. The display defines how an element displays in HTML.

How do I put text and images side by side in CSS?

This is achieved with the CSS property float, which allows text to flow around the left-aligned image to its right side (or around a right-aligned image to its left side).


1 Answers

.content {      width: 400px;      border: 4px solid red;      padding: 20px;      overflow: hidden;  }    .content img {      margin-right: 15px;      float: left;  }    .content h3,  .content p{      margin-left: 15px;      display: block;      margin: 2px 0 0 0;  }
<div class="content">      <img src="http://cdn4.iconfinder.com/data/icons/socialmediaicons_v120/48/google.png"/ alt="" >      <h3>Title</h3>      <p>Some Description</p>  </div>​
like image 81
Ahsan Khurshid Avatar answered Oct 04 '22 13:10

Ahsan Khurshid