html - Pseudo Element 100% width is not taking container size -


i'm using pseudo element (before) put border on top of container inside 2 column layout. want border on top of 1 container.

shouldn't width of pseudo element (being set 100%) make width of container it's inside?

#singlewrapper {    margin: auto;    max-width: 1100px;    }  .single #singlewrapper {    margin: auto;    max-width: 1100px;    /*box-shadow: inset 0 650px rgba(0,0,0,0.30);*/    position: relative;    overflow: hidden;  }  #leftcolumn .content-area {    padding-right: 310px;    width: 100%;  }  .articlewrapper:before {    content: "";    position: absolute;    top: 0;    left: 0;    background: #009cff;    background: linear-gradient(to right, #1d0027, #935cd2, #1d0027);    height: 2px;    width: 100%;  }  #leftcolumn .content-area #main {    background: #000;    background: rgba(0, 0, 0, 0.30);    padding-left: 20px;    padding-right: 20px;  }  #singlewrapper .contentholder {    margin-right: -310px;    width: 100%;    float: left;    position: relative;  }  #rightcolumn {    float: right;    position: relative;    display: block;    width: 290px;  }  #leftcolumn,  #rightcolumn {    display: inline-block;    vertical-align: top;    margin-top: 1.1em;  }
<div id="singlewrapper">    <div id="leftcolumn" class="contentholder">      <div id="primary" class="content-area">        <main id="main" class="site-main" role="main">          <div class="articlewrapper">            <h1>title</h1>            <div class="articlebody">              article body            </div>          </div>        </main>      </div>    </div>    <div id="rightcolumn">      side bar area    </div>  </div>

the problem using position:absolute

from mdn

absolute positioning

elements positioned relatively still considered in normal flow of elements in document. in contrast, element positioned absolutely taken out of flow , takes no space when placing other elements. absolutely positioned element positioned relative nearest positioned ancestor. if positioned ancestor doesn't exist, initial container used

a fix add css:

.articlewrapper {   position:relative; } 

and change top:0; in .articlewrapper:before negative value best.

here snippet

#singlewrapper {    margin: auto;    max-width: 1100px;  }  .single #singlewrapper {    margin: auto;    max-width: 1100px;    /*box-shadow: inset 0 650px rgba(0,0,0,0.30);*/    position: relative;    overflow: hidden;  }  #leftcolumn .content-area {    padding-right: 310px;    width: 100%;  }  .articlewrapper {    position:relative;  }  .articlewrapper:before {    content: "";    position: absolute;    top: -30%;    left: 0;    background: #009cff;    background: linear-gradient(to right, #1d0027, #935cd2, #1d0027);    height: 2px;    width: 100%;  }  #leftcolumn .content-area #main {    background: #000;    background: rgba(0, 0, 0, 0.30);    padding-left: 20px;    padding-right: 20px;  }  #singlewrapper .contentholder {    margin-right: -310px;    width: 100%;    float: left;    position: relative;  }  #rightcolumn {    float: right;    position: relative;    display: block;    width: 290px;  }  #leftcolumn,  #rightcolumn {    display: inline-block;    vertical-align: top;    margin-top: 1.1em;  }
<div id="singlewrapper">    <div id="leftcolumn" class="contentholder">      <div id="primary" class="content-area">        <main id="main" class="site-main" role="main">          <div class="articlewrapper">            <h1>title</h1>            <div class="articlebody">              article body            </div>          </div>        </main>      </div>    </div>    <div id="rightcolumn">      side bar area    </div>  </div>


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -