Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make div inside parent 100% width of body, not parent div

Tags:

css

width

I want to make my inner div 100% width of the body, not 100% of the parent div. Is this possible?

The layout looks like this:

<body>
   <div> /** Width:900px; **/
      <div> /** This I want 100% of BODY, not of parent div **/

      </div>
   </div>
</body>
like image 626
Daniel Avatar asked Nov 22 '12 10:11

Daniel


1 Answers

i hope you are looking like this........... see the DEMO

UPDATED DEMO 2 AS PER YOUR CURRENT REQUIREMENTS

CSS

    .parent {
background:red;
width:900px;
margin:0 auto;
padding:10px;
    -moz-box-sizing:border-box;
    -webkit-box-sizing:border-box;
    box-sizing:border-box;
}

.inner {
background:green;
height:100px;
position:absolute;
  left:0;
  right:0;
}

.child {
  height:100px;
  background:black;
  margin:10px 0;
}

-------------**

Second Answer with without positioning but with a some trick what i used here so please check it the code & demo mentioned below :-

HTML

<body>
   <div class="parent"> /** Width:900px; **/
  <div class="child"></div>
  </div>
  <div class="inner"> /** This I want 100% of BODY, not of parent div  **/</div>
   <div class="parent">
       <div class="child"></div>
       <div class="child"></div>
   </div>
</body>

CSS

.parent {
background:red;
width:900px;
margin:0 auto;
padding:10px;
    -moz-box-sizing:border-box;
    -webkit-box-sizing:border-box;
    box-sizing:border-box;
}

.inner {
background:green;
height:100px;
}

.child {
  height:100px;
  background:black;
  margin:10px 0;
}

DEMO

like image 53
Shailender Arora Avatar answered Oct 15 '22 18:10

Shailender Arora