html - Why does this HR element stop part way across the page? -


this hard 1 explain. fiddle should show what's going on:

https://jsfiddle.net/m6zfvgp1/1/

what i've done divide page header , content divs. @ bottom of header i've got hr element , i've re-positioned "buttons" - heavily styled links - sit atop middle of hr between header , content div.

here's code:

html,body{   height: 100%;   width:100%;   margin: 0; }  #header {     position: fixed;     top: 0;     left: 0;     right: 0;     height: 100px;     z-index: 5; }  #content {     position: fixed;     top: 100px;     bottom: 100px;     left: 0;     right: 0;     background-color: white;     overflow: auto;     z-index: 4; }  .hr {     border-bottom: 2px solid red;     clear: both;     width: 100%; }  #buttons .hr {     margin-top: -16px;     color: #ddd; }  #buttons {     border: 1px solid #32b8eb;     background-color: white;     padding: 4px 24px;     margin-left: 30px;     height: 32px;     line-height: 32px; }  <body class="page">     <div id="header">          <div id="buttons" style="position: absolute; top: 83px;">             <a class="" href="/home/newjob">new job</a>             <a class="active" href="/">job list</a>             <div class="hr"></div>         </div>      </div>     <div id="content">     </div>  </body> 

however, you'll see in fiddle, there's problem: hr stops displaying after rightmost button though width set 100%. why?

it because div#buttons absolutely positioned , takes width of contents. can make full width either by:

  • width: 100%
  • left: 0; right: 0;

alternatively, can use border-bottom on full width parent element.

#header {   border-bottom: 2px solid #000; } 

html,  body {    height: 100%;    width: 100%;    margin: 0;  }    #header {    position: fixed;    top: 0;    left: 0;    right: 0;    height: 100px;    z-index: 5;  }    #content {    position: fixed;    top: 100px;    bottom: 100px;    left: 0;    right: 0;    background-color: white;    overflow: auto;    z-index: 4;  }    .hr {    border-bottom: 2px solid red;    clear: both;    width: 100%;  }    #buttons .hr {    margin-top: -16px;    color: #ddd;  }    #buttons {    border: 1px solid #32b8eb;    background-color: white;    padding: 4px 24px;    margin-left: 30px;    font-weight: normal;    height: 32px;    font-size: 18px;    text-transform: uppercase;    line-height: 32px;    font-family: calibri;    color: black;    text-decoration: none;    cursor: pointer;  }    #header {    border-bottom: 2px solid #000;  }
<body class="page">    <div id="header">        <div id="buttons" style="position: absolute; top: 83px;">        <a class="" href="/home/newjob">new job</a>        <a class="active" href="/">job list</a>        <a class="" href="/home/pricing">pricing</a>        <div class="hr"></div>      </div>      </div>    <div id="content">      </div>  </body>

check both:

width: 100% technique:

html,  body {    height: 100%;    width: 100%;    margin: 0;  }    #header {    position: fixed;    top: 0;    left: 0;    right: 0;    height: 100px;    z-index: 5;  }    #content {    position: fixed;    top: 100px;    bottom: 100px;    left: 0;    right: 0;    background-color: white;    overflow: auto;    z-index: 4;  }    .hr {    border-bottom: 2px solid red;    clear: both;    width: 100%;  }    #buttons .hr {    margin-top: -16px;    color: #ddd;  }    #buttons {    border: 1px solid #32b8eb;    background-color: white;    padding: 4px 24px;    margin-left: 30px;    font-weight: normal;    height: 32px;    font-size: 18px;    text-transform: uppercase;    line-height: 32px;    font-family: calibri;    color: black;    text-decoration: none;    cursor: pointer;  }    #buttons {    width: 100%;  }
<body class="page">    <div id="header">        <div id="buttons" style="position: absolute; top: 83px;">        <a class="" href="/home/newjob">new job</a>        <a class="active" href="/">job list</a>        <a class="" href="/home/pricing">pricing</a>        <div class="hr"></div>      </div>      </div>    <div id="content">      </div>  </body>

left: 0; right: 0; technique:

html,  body {    height: 100%;    width: 100%;    margin: 0;  }    #header {    position: fixed;    top: 0;    left: 0;    right: 0;    height: 100px;    z-index: 5;  }    #content {    position: fixed;    top: 100px;    bottom: 100px;    left: 0;    right: 0;    background-color: white;    overflow: auto;    z-index: 4;  }    .hr {    border-bottom: 2px solid red;    clear: both;    width: 100%;  }    #buttons .hr {    margin-top: -16px;    color: #ddd;  }    #buttons {    border: 1px solid #32b8eb;    background-color: white;    padding: 4px 24px;    margin-left: 30px;    font-weight: normal;    height: 32px;    font-size: 18px;    text-transform: uppercase;    line-height: 32px;    font-family: calibri;    color: black;    text-decoration: none;    cursor: pointer;  }    #buttons {    left: 0;    right: 0;  }
<body class="page">    <div id="header">        <div id="buttons" style="position: absolute; top: 83px;">        <a class="" href="/home/newjob">new job</a>        <a class="active" href="/">job list</a>        <a class="" href="/home/pricing">pricing</a>        <div class="hr"></div>      </div>      </div>    <div id="content">      </div>  </body>


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -