
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
How do I keep two side-by-side div elements the same height?
We need to keep the two side-by-side div the same height, so that if more content is added to any of the div, the size of the other div matches it. The following two examples are covered −
- Keep two side-by-side div elements the same height using HTML
- Keep two side-by-side div elements the same height using JavaScript
Let us see the example one by one −
Keep two side-by-side div elements the same height using HTML
Example
We will use the following code to keep two side-by-side div elements the same height -
<!DOCTYPE html> <html> <head> <style> .container{ display: table-row; } .box1{ display: table-cell; background: red; color: white; } .box2{ display: table-cell; background: orange; color: white; } </style> </head> <body> <h1>Two Divs</h1> <div class = "container"> <div class ="box1"> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> </div> <div class = "box2"> Nunc et nisl et justo viverra fermentum.<br/> Nunc et nisl et justo viverra fermentum.<br/> Nunc et nisl et justo viverra fermentum.<br/> Nunc et nisl et justo viverra fermentum.<br/> Nunc et nisl et justo viverra fermentum.<br/> </div> </div> </body> </html>
Output

Add more content to the 2nd div and you can see the size of both the divs will increase −
Output

Keep two side-by-side div elements the same height using JavaScript
Example
We will use the following code to keep two side-by-side div elements the same height using JavaScript. The height() is used to match the height of both the divs −
<!DOCTYPE html> <html> <head> <style> .box1{ display: table-cell; background: red; color: white; } .box2{ display: table-cell; background: orange; color: white; } </style> </head> <body> <div class ="box1"> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br/> </div> <div class = "box2"> Nunc et nisl et justo viverra fermentum.<br/> Nunc et nisl et justo viverra fermentum.<br/> Nunc et nisl et justo viverra fermentum.<br/> Nunc et nisl et justo viverra fermentum.<br/> </div> <script> $(".box2").height($(".box1").height()); </script> </body> </html>
Output

- Related Articles
- How do I plot two countplot graphs side by side in Seaborn using Matplotlib?
- How to make two plots side-by-side using Python?
- How to plot two histograms side by side using Matplotlib?
- How to plot two Seaborn lmplots side-by-side (Matplotlib)?
- How we can put two divisions side by side in HTML?
- How to plot bar graphs with same X coordinates side by side in Matplotlib?
- How to align images side by side with CSS?
- How to create side-by-side boxplot in base R?
- How to create side by side histograms in base R?
- How to create side by side barplot in base R?
- Displaying Files Side by Side in Linux
- How we can put three divisions side by side in HTML?
- Apache Storm vs. Spark Side-by-Side Comparison
- If two cubes of dimension 2cm by 2cm by 2cm are placed side by side. What would the dimensions of resulting cuboid be?
- How can I vertically align elements in a div?

Advertisements