Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML element display in horizontal line

Tags:

html

css

I have two HTML elements inside a div. I want to display them in a row or a horizontal line. Let's say I have two images with the code shown below. How would I make it so there is no line break after the first element so they will be displayed one after the other horizontally. Right now the second image is displayed below the first. I want the second image to be displayed to the right of the first. I am pretty sure this can be done in CSS. Please Help.

<img src="image one.jpg">
<img src="image two.jpg">
like image 995
Web_Designer Avatar asked Dec 28 '10 22:12

Web_Designer


3 Answers

Option 1

img {
 display:inline;
}

Option 2

img {
 display:block;
 float:left;
}

Updated to reflect current browser capabilities

Option 3

img {
 display:inline-block;
}

However, this will only work if there is enough horizontal space for the images in question.

like image 148
Sandwich Avatar answered Oct 17 '22 16:10

Sandwich


The hack is to set position: relative; on the parent div and

position: absolute; 
top: 0px; 
left: {left image's computed width}px; 

on the second one. Other wise you simple increase the div size.

like image 6
Babiker Avatar answered Oct 17 '22 16:10

Babiker


The image elements are inline elements, so they display horizontally, unless you changed the "display" CSS rule. I think you don't have enough space for them to fit horizontally.

like image 3
Pikrass Avatar answered Oct 17 '22 17:10

Pikrass