How to Center Two Images Side by Side?

DDD
Release: 2024-11-02 00:39:31
Original
505 people have browsed it

How to Center Two Images Side by Side?

Positioning Two Images Side by Side

When attempting to center two images horizontally, it's common to encounter issues where the images appear vertically aligned instead. To resolve this, consider the following:

Original CSS:

<code class="css">#fblogo {
    display: block;
    margin-left: auto;
    margin-right: auto;
    height: 30px; 
}</code>
Copy after login

Improved CSS:

<code class="css">.fblogo {
    display: inline-block;
    margin-left: auto;
    margin-right: auto;
    height: 30px; 
}

#images{
    text-align:center;
}</code>
Copy after login

Changes:

  • Replace display: block with display: inline-block.
  • Remove the ID selector #fblogo and use the class selector .fblogo instead.
  • Add a new div with the ID images and a text-align property set to center.

Modified HTML:

<code class="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></code>
Copy after login

These modifications ensure that the images are displayed inline within the images div and are horizontally centered within the parent container.

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!