CreateaFreeWebsite  with Responsive Web Design

General

 

9 Step Tutor

How to Add Text next to a Picture in HTML using the Paragraph Tag

Then Make it Responsive

We've already learned how to add an image to a page, so the next step is placing it in a paragraph next to the text.

Remember the rules:
DO NOT add height and width dimensions to your images.

<img src="path/imagename" width="400px" height="400px" alt="alt text">

Rather use relative values (percentages) defined in your style sheet.

<img src="path/imagename" class="l-img" alt="alt text">

img.l-img {
float:left;
max-width:50%;  /*Can use no more than 50% of available space*/
margin:1% 1%;
box-shadow: 0 2px 4px #000003
}

Add margins to your image using css to keep text from laying against it.
margin:1% 1%;

Use CSS to add or remove borders, round corners or place box shadow.

Another way to make images responsive is using the swapping technique demonstrated in our Download Template #402 - 6 Page Kit

Methods of Alignment

Here are the methods used for left, right and center placement in paragraphs and making them responsive, where they adjust to the width of the viewing device.

There are also inline methods for placement.

First of all, you must begin with an already responsive container. That just means your web page already adjusts to the width of visiting devices.

Aligning Responsive Pictures to Left of Text

In HTML5 Use:
<p><img src="imagename" alt="alt text" class="l-img">Text here</p>

buddy aligned to left of textIn this paragraph the alignment attribute of the image is set using the float property float:left.(Style settings for .l-img below)

When the float left property is chosen text will flow to the right of the image.

Notice that in the style sheet we set the width using percentages

img.l-img{
float:left;
max-width:50%;/*Can use no more than 50% of available space*/
margin:1% 1%;
box-shadow: 0 2px 4px #000003
}

Ensuing paragraphs and elements like h1-h6 will also flow upward to the right of the image to fill any vacant space.

We prevented that from happening on this page by placing a the following code after the desired amount of text that we wanted next to the picture.

<p class="clear">&nbsp;</p>  The CSS: p.clear {clear: both}

 

Aligning Responsive Pictures to Right of Text

In HTML5 Use:
<p><img src="imagename" alt="alt text" class="r-img">Text here</p>

Buddy aligned to right of textIn this paragraph the alignment attribute of the image is set to float:right. When the float right property is chosen text will flow to the left of the picture.

The styling for class r-img

img.r-img{
float:right;
max-width:50%;
margin:1% 1%;
box-shadow: 0 2px 4px #000003
}

Ensuing paragraphs and page elements will also flow upward and to the left of the image. You can prevent that using the simple method shown above.

See also: The float Property

 

Centering Responsive Images

Buddy centered

Here's the HTML code for centering a naked image:

<img src="imagename" class="centerimg" alt="alt text">

The style sheet for class centerimg.

img.centerimg{ 
max-width:96%;
float:none;
display:block;
margin: 0 auto;
box-shadow: 0px 2px 4px #000000
}

These 3 lines do the centering:

float:none;
display:block;
margin: 0 auto;

Do not set the image in a paragraph unless you center it.

Inline Images

You've seen the instruction manuals that place icons in the text of a paragraph.

HTML5 makes it very simple to do this.

IndigoAmpp includes an option during installation for attaching the start up icon start up iconto the task bar.

The HTML5 code:

<p>IndigoAmpp includes an option during installation for attaching the start up icon <img src="images/start-up-icon.PNG" style="border: 0; display:inline; margin: 0 2px; box-shadow: none" alt="start up icon">to the task bar.</p>

Use of Classes

Rather than using inline code, a better option for adding the style settings would be to create customized classes.

You might use imager for right aligned images, imagel for left aligned and imagec for centered.

 

Note: When placing images in web pages, always use optimized, interlaced images. Large bulky image files will cause your pages to display very slowly. Size of files can be reduced by limiting them to the least amount of colors that will allow the image to display properly. Interlacing gives the appearance of an image loading in layers. If the image is slow in loading the user will see something on the screen rather than just a blank page. Interlaced images don't normally load faster than non-interlaced, but they do give that appearance.

 

Free Tools and Resources We Recommend

Need more advanced information? Visit our Web Developer Resources page for a collection of other great tutorials and reference guides on the subjects of HTML5, CSS3, Responsive Design and SEO.

 

Free Responsive Web Design Certification freeCodeCamp
freeCodeCamp is a proven path to your first software developer job.
More than 40,000 people have gotten developer jobs after completing this – including at big companies like Google and Microsoft.
Finally, you'll learn how to make webpages that respond to different screen sizes by building a Twitter card with Flexbox, and a complex blog layout with CSS Grid.
FREE Certification Courses!!
Free Ebook How to Code in HTML5 and CSS3
"How to Code in HTML5 and CSS3" is a free e-book about making websites in HTML5 and CSS for absolute beginners. It doesn't require any experience in IT to start....
FREE HTML Editor (Windows): NoteTab Light
All the features of a commercial HTML editor.
FREE Apache Server (Windows): IndigoAmpp
Set up a real time server environment right on your PC. Test forms and scripts before uploading to your web space.
Linux Users
If like us, you've left the insane world of Microsoft Windows for the even worse experience of Linux, we recommend the BlueFish HTML editor. You'll find it in your software repository. It does have some QUIRKS, but it's FREE.
For image resizing we've found the easiest Linux tool to be Krita.

Have you tried our FREE Responsive Design template kit? Download Template #402 - 6 Page Kit