How to make side by side divs in HTML
In this article, you will learn how to make side by side divs in HTML using float, margin, display, and flex.
Using Float property#
- Create the first div with a unique class or id, ensuring it includes the desired width.
- Add the float: left property to this div, which moves it to the left side of the screen.
- Create a second div and ensure it has a unique class or id.
- Set the width of the second div, also leaving room for any desired padding or margins.
- Add the float: left property to this div, which moves it to the left side of the screen.
- Ensure both divs add up to a total of 100% (or less if they include margins or padding).
Using CSS Margin and display property#
- Create the first div with a unique class or id, along with specifying the width and height.
- Set the margin-right property on the first div to push your second div away from the first.
- Create a second div and ensure it has unique sizing and spacing.
- Set the margin-left property on the second div, pushing it over to the side of the first div.
- Ensure that both divs add up to a total of 100% (or less if they include margins or padding).
Using Display flex property#
- Create a container with unique sizing, and specify its "display" as either "flex" or "grid".
- Add the first div to the container and set its sizing as-needed.
- Add the second div to the container, ensuring its sizing meets your needs.
- Use the "justify-content" property to move divs to the left, right, or center based on your needs.
- Set your desired width for each div, using percentages or pixels.
Flex and Grid are more modern and preferred approaches to creating side by side divs. Float and Margin methods may be better suited for legacy applications or specific scenarios.
save
listen
AI Answer
How to make side by side divs in HTML
0
In this article, you will learn how to make side by side divs in HTML using float, margin…
asked
Apu
0 answers
2915
In this article, you will learn how to make side by side divs in HTML using float, margin…
Answer Link
answered
Apu