How to have images in line with text in css

Viewed 84992

I'm creating the footer of my website using html and css.

I want to have the two facebook and twitter images in line with the text so that everything in the footer is in line with eachother

At the moment my footer code is

HTML -

<div class="footer content">

        <img src="Images/facebook.png">
        <img src="Images/twitter.png">

        <p> Address line 1
                        Address line 2
                        Address line 3

  </p>

</div> <!--end of footer--> 

Can anyone help please?

7 Answers

<p> tags are block-level elements. Use an inline element such as <span>:

<div class="footer content">
    <img src="Images/facebook.png" />
    <img src="Images/twitter.png">
    <span> 
        Address line 1
        Address line 2
        Address line 3
    </span>
</div>

Alternatively, if you're able to use CSS, you can define both elements as inline-block:

.footer.content > img,
.footer.content > p {
    display: inline-block;
}

Example 1 jsFiddle

Example 2 jsFiddle

EDIT: It might also be wise for semantics to use <address>, rather than <span>. For example:

<div class="footer content">
    <img src="Images/facebook.png" />
    <img src="Images/twitter.png">
    <address> 
        Address line 1
        Address line 2
        Address line 3
    </address>
</div>

Since <address> is also a block-level element, you'll need to include the correct CSS as follows:

.footer.content > img,
.footer.content > address {
    display: inline-block;
}

Final jsFiddle example

The simplest way is to use <span> instead of <p>. <p> makes a new paragraph which is quit "independent".

Check out this working example here.

.channels li {
    float: left;
    margin-left: 0.625em;
}

.content img, .content p { float:left } float: left/right - depending where you want it to be

If you want to use new tags specific for footer and address this is my example:

<footer id="footer">

    <span><img src="Images/facebook.png" alt="some text" /></span>
        <span> <img src="Images/twitter.png" alt="some text"/></span>
                <span>
                    <address>
                        Address line 1
                        Address line 2
                    Address line 3
                    </address>    
            </span>
</footer>


#footer {display:inline;}
#footer address {display:inline }

The alt to images was added to help with disability and standards.

Use display:inline-block css property for image ad text to display image and text in same line

Related