css - Why does my <ul> have a background of an element which isn't its parent? -


i trying build page header, includes navigation bar @ bottom. however, navigation bar has background colour of main content, not of header.

i searched site similar problems, , tried overflow: hidden, or adding overflow: auto .main, suggested, none of these solutions worked. have tried removing lines css, such float: left; didn't work. adding background: inherit ul gives background colour small area around nav bar, not width of header.

.main {    background-color: darkolivegreen;    border-radius: 15px;    max-width: 1000px;    margin: 0 auto;    text-align: center;    height: 800px;  }  header {    background: chartreuse;    border-radius: 15px 15px 0 0;    padding: 10px 10px 10px 10px;  }  ul {    float: left;    display: block;    position: absolute;    margin-left: -45px;  }  li {    display: inline;    background: cyan;    border: 2px solid black;    border-radius: 5px 5px 0 0;    margin-left: -5px;  }  h1 {    font-size: 35px;    margin: 10px 0 0 0;  }  img {    max-height: 150px;    max-width: 150px;  }  .item {    display: inline-block;    padding: 60px;    margin-top: 40px;    width: 200px;    height: 200px;    float: left;  }  h2 {    font-size: 25px;  }
<div class="main">    <header>      <h1>gallery</h1>      <ul>        <li><a href="/index.html">home</a>        </li>        <li><a href="/gallery.html">gallery</a>        </li>      </ul>    </header>    <div class="pictures">      <article class="item">        <img src="#">        <h2>image 1</h2>      </article>      <!-- several more .item articles image , h2. -->    </div>  </div>

it due position: absolute , float: left makes element go out of document flow.

.main {    background-color: darkolivegreen;    border-radius: 15px;    max-width: 1000px;    margin: 0 auto;    text-align: center;    height: 800px;  }  header {    background: chartreuse;    border-radius: 15px 15px 0 0;    padding: 10px 10px 10px 10px;  }  ul {    display: block;    margin-left: -45px;    text-align: left;    margin-left: 20px;  }  li {    display: inline;    background: cyan;    border: 2px solid black;    border-radius: 5px 5px 0 0;    margin-left: -5px;  }  h1 {    font-size: 35px;    margin: 10px 0 0 0;  }  img {    max-height: 150px;    max-width: 150px;  }  .item {    display: inline-block;    padding: 60px;    margin-top: 40px;    width: 200px;    height: 200px;    float: left;  }  h2 {    font-size: 25px;  }
<div class="main">    <header>      <h1>gallery</h1>      <ul>        <li><a href="/index.html">home</a>        </li>        <li><a href="/gallery.html">gallery</a>        </li>      </ul>    </header>    <div class="pictures">      <article class="item">        <img src="#">        <h2>image 1</h2>      </article>      <!-- several more .item articles image , h2. -->    </div>  </div>


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -