简体   繁体   中英

ul and li 100% height of non-fixed parent

I am looking for the easiest way to get a < ul > and it's < li > elements to a 100% height of the < ul >'s parent. The parent is not fixed (and I am trying to avoid that so it is flexible on mobile devices). Here is the JSFiddle

Basically I want the red boxes to be 100% height of the grayish box.

Thanks!

Note: I have tried various things already, its just nothing seemed to work properly.

There are several things you need to do.

  1. Specify the height of the .site-header eg 40px
  2. Every parent of li needs to be 100% heigh
  3. Make the title and nav container inline

This should work

 h1 {
  margin: 0;
  display: inline;
}
.site-header {
  background: rgba( 0,0,0,0.5 );
  width: 100%;
  height: 40px;
}
.row {
  height: 100%;
}
.site-title {
  display: inline;
  font-family: 'Roboto Mono';
  font-weight: 100;
}
h1 {
  margin: 0;
  padding: 0;
  display: inline;
}
.site-nav {
  height: 100%;
  float: right;
}
ul {
  list-style-type: none;
  height: 100%;
  margin: 0;
}
li {
  background: red;
  float: left;
  height: 100%;
  text-align: center;
  width: 150px;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM