html - Dynamically specify height of parent based on the tallest child element? -


i trying best figure out how set 2 columns' a-elements 100% of parent element, without specifying height, having chosen based on taller of 2 columns. @ same time, want vertically align a-element within it's column.

current code:

<div class="post-nav group">                  <div class="post-nav-prev">                     <div class="post-nav-border border-reset-right">                     <?php previous_post('%', '', 'yes'); ?>                     </div>                 </div>                 <div class="post-nav-next">                     <div class="post-nav-border">                     <?php next_post('%', '', 'yes'); ?>                     </div>                 </div>              </div> 

css:

.post-nav {  }  .post-nav-prev, .post-nav-next {     float: left;     width: 50%;     height: 100%; }  .post-nav-prev a, .post-nav-next {     display: flex;     justify-content: center; /* align horizontal */     align-items: center; /* align vertical */     height: 100%;     padding: 10px;       }  .post-nav-prev {     padding-left: 25px; }  .post-nav-next {     padding-right: 25px; }  .post-nav-border {     border: 1px solid #e3e3e3;     height: 100%; } 

what run problem when 2 post titles isn't same amount of lines. had specified height, isn't optimal responsive aspect of website.

so clarify: how go having tallest of '.post-nav-prev a', , '.post-nav-next a' specify height .post-nav, other of 2 elements 100% height. i've seen suggestions display: table, couldn't quite work, keeping vertical alignment of display: flex.

any suggestions?

the simplest solution (without js) indeed fiddle display property , set container table , children table-cell (you might change actual markup table, result same). this, vertically aligning becomes easy hell , css & html simpler. here's how:

.post-nav {       display: table;       border-collapse: collapse;   }  .post-nav-prev a, .post-nav-next {       display: block;       padding: 10px;   }  .post-nav-prev, .post-nav-next {      display: table-cell;      vertical-align: middle;      width: 50%;      height: 100%;      border: 1px solid #e3e3e3;      text-align: center;  }
<div class="post-nav group">      <div class="post-nav-prev"><a href="#">text 1</a></div>      <div class="post-nav-next">         <a href="#">text 2 long , falls in 2 lines example case</a>      </div>  </div>


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -