Home > Article > Web Front-end > How to Right-Align Div Elements While Keeping a Third Div Left-Aligned?
Problem Statement:
A user aims to right-align two div elements (a button and a form) while keeping a third div (a canvas) left-aligned. However, attempting to align the first two elements results in them appearing side-by-side instead of one after the other.
Solution using Margins and Floats:
The provided code utilizes floating to align the button and form. While floating can work in general, it is known to have issues with IE 6 & 7.
To resolve this, consider using margins instead of floating for the inner div containing the button and form. Here's the revised CSS:
#addEventForm { position: relative; margin-left: auto; margin-right: 0; border: 2px solid #003B62; font-family: verdana; background-color: #B5CFE0; padding-left: 10px; }
Explanation:
Using margins provides more consistent behavior across different browsers, including IE, ensuring that the elements are aligned as intended.
The above is the detailed content of How to Right-Align Div Elements While Keeping a Third Div Left-Aligned?. For more information, please follow other related articles on the PHP Chinese website!