Home > Article > Web Front-end > How to Center Two Images Side-by-Side Using 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 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 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!