2

I want to make my specific div element's child will be equal height with out using any jquery plugin or Javascript. I want to make this by CSS.

So can any one give me an idea how can i make this?

Saifur Rahman
  • 445
  • 5
  • 11

2 Answers2

4

Yes you can. You have to use css3 dispaly: table; for the equal height wrapper and display: table-cell; for the each element of equal height wrapper.

Here is the simple way.

HTML & CSS Code:

.equal-height-row{
  display: table;
}
.equal-height-row > .equal-height-box{
  display: table-cell;
  vertical-align: middle;
  padding: 2em;
  box-sizing: border-box;
  background-color: lightgrey;
}
<div class="equal-height-row">
  
   <div class="equal-height-box">Box1<br>box 1 content</div>
   <div class="equal-height-box">Box2</div>
   <div class="equal-height-box">Box3</div>
  
</div>
Giulio Bambini
  • 4,695
  • 4
  • 21
  • 36
3

A modern and preferred way is to use flexbox, which aims at providing a more efficient way to lay out, align and distribute space among items in a container, even when their size is unknown and/or dynamic (thus the word "flex").

At this link, A guide to flexbox, you will find a really good start how it works.

.row {
  display: flex;
}
.row > div {
  flex: 1;
  background-color: lightblue;
  padding: 10px;
  margin: 5px 10px;
}
<div class="row">
   <div>First</div>
   <div>Second<br>having<br>more than<br>one line</div>
   <div>Third</div>
</div>
Asons
  • 84,923
  • 12
  • 110
  • 165
  • FYI: http://caniuse.com/#feat=flexbox – NBTX Apr 08 '17 at 17:43
  • @SamMearns Yes, I know, about 97% browser support...is that bad?? .... Or do you mean `display: table` is the correct way for doing layout?? – Asons Apr 08 '17 at 17:53
  • 97% is fine - the problem that I see is that it has only IE11 partial-support - however, for some reason, every copy of IE (even 11) that I've tested with uses IE7 rendering mode by default (for some bizarre reason) so this will require a META tag. (and I wanted to mention prefixes) – NBTX Apr 08 '17 at 17:56
  • Oh, by the way - in a modern context, I would say `display: flex;` is the way to go. – NBTX Apr 08 '17 at 17:57
  • @SamMearns I call them `CSS Table` and `CSS Flexbox`, and so does W3C, but can't see why that matter and why you mark my wording? ... IE11 has full support though it is buggy, hence the call it _partial support_, and IE11 does not use IE7 rendering mode by default, so I don't understand where you got that from, I have been using it since it hit the market and never run into any such issues ... and regarding prefix, there was a reason why I linked to _A guide to flexbox_ – Asons Apr 08 '17 at 18:11
  • That's my fault I didn't read your answer correctly - as to the IE7 rendering mode, I'm not sure what circumstances this has occurred under but I will see if I can find an example. – NBTX Apr 08 '17 at 18:19
  • Found it: "Internet Explorer makes the assumption that most webpages were written to target earlier versions of IE [...]. Even with a HTML5 doctype IE will still place your website in compatibility mode if it's an intranet site." - I was building an intranet site. (Snippet from http://stackoverflow.com/a/13287226/2872279) – NBTX Apr 08 '17 at 18:20
  • @SamMearns If you do Windows development and use the `webbrowser` control it does use the IE7 rendering mode, or, as they call it, compatibility mode .... and as you found, intranet sites, which is understandable ... good we cleared that out :) – Asons Apr 08 '17 at 18:20