Home  >  Article  >  Web Front-end  >  How to Center Two Images Side-by-Side Using CSS?

How to Center Two Images Side-by-Side Using CSS?

Barbara Streisand
Barbara StreisandOriginal
2024-11-02 20:01:30859browse

How to Center Two Images Side-by-Side Using CSS?

Centering Images Side by Side with CSS

Question:

I'm facing an issue while attempting to center two images adjacent to each other in my HTML document. Despite my efforts, they persistently display one below the other. How can I effectively center the images and place them side-by-side?

HTML Code:

<a href="mailto:[email&#160;protected]">
<img id="fblogo" border="0" alt="Mail" src="http://olympiahaacht.be/wp-content/uploads/2012/07/email-icon-e1343123697991.jpg"/>
</a>
<a href="https://www.facebook.com/OlympiaHaacht" target="_blank">
<img id="fblogo" border="0" alt="Facebook" src="http://olympiahaacht.be/wp-content/uploads/2012/04/FacebookButtonRevised-e1334605872360.jpg"/>
</a>

CSS Code:

#fblogo {
    display: block;
    margin-left: auto;
    margin-right: auto;
    height: 30px;
}

Solution:

To align the images horizontally, modify the CSS code as follows:

.fblogo {
    display: inline-block;
    margin-left: auto;
    margin-right: auto;
    height: 30px;
}

#images{
    text-align:center;
}

Modified HTML:

<div id="images">
    <a href="mailto:[email&#160;protected]">
    <img class="fblogo" border="0" alt="Mail" src="http://olympiahaacht.be/wp-content/uploads/2012/07/email-icon-e1343123697991.jpg"/>
    </a>
    <a href="https://www.facebook.com/OlympiaHaacht" target="_blank">
    <img class="fblogo" border="0" alt="Facebook" src="http://olympiahaacht.be/wp-content/uploads/2012/04/FacebookButtonRevised-e1334605872360.jpg"/>
    </a>
</div>​

Live Demonstration:

[Demo Link]

The above is the detailed content of How to Center Two Images Side-by-Side Using CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn