How to place Text and an Image next to each other in HTML?

I want the text and the image to be next to each other but I want the image to be on the far left of the screen and I want the text to be on the far right of the screen. This is what I currently have....

<body> <img src="website_art.png" height= "75" width= "235"/> <h3><font face="Verdana">The Art of Gaming</font></h3> </body> 

How can I do this?

Thanks

3

3 Answers

img { float:left; } h3 { float:right; } 

jsFiddle example

Note that you will probably want to use the style clear:both on whatever elements comes after the code you provided so that it doesn't slide up directly beneath the floated elements.

2

You want to use css float for this, you can put it directly in your code.

<body> <img src="website_art.png" height= "75" width="235"/> <h3>The Art of Gaming</h3> </body> 

But I would really suggest learning the basics of css and splitting all your styling out to a separate style sheet, and use classes. It will help you in the future. A good place to start is w3schools or, perhaps later down the path, Mozzila Dev. Network (MDN).

HTML:

<body> <img src="website_art.png"/> <h3>The Art of Gaming</h3> </body> 

CSS:

.myImage { float: left; height: 75px; width: 235px; font-family: Veranda; } .heading { float:right; } 

You can use vertical-align and floating.

In most cases you want to vertical-align: middle, the image.

Here is a test:

vertical-align: baseline|length|sub|super|top|text-top|middle|bottom|text-bottom|initial|inherit;

For middle, the definition is: The element is placed in the middle of the parent element.

So you might want to apply that to all elements within the element.

1

You Might Also Like