0

 .one{
        position: relative;
        height: 100px;
        border: 1px solid #000;
        width: 600px;
        margin: 0 auto;
    }   
    .two{
        position: absolute;
        height: 30px;
        background-color: #ccc;
        top: 35px;
        width: 100%;
    }
<div class="one">
    <div class="two">

    </div>
</div>

2 ответа 2

2

В .one убрать position. В .two добавить left:0

 .one {  
   height: 100px;
   border: 1px solid #000;
   width: 600px;
   margin: 0 auto;
 }
 
 .two {
   position: absolute;
   height: 30px;
   background-color: #ccc;
   top: 35px;
   width: 100%;
   left:0;
 }
<div class="one">
  <div class="two">

  </div>
</div>

1

Вытащите второй div из первого, и добавьте в стили второго дива width: 100vw; и left: 0;

    .one{
        position: relative;
        height: 100px;
        border: 1px solid #000;
        width: 600px;
        margin: 0 auto;
    }   
    .two{
        position: absolute;
        height: 30px;
        background-color: #ccc;
        top: 35px;
        left: 0;
        width: 100vw;
    }
<div class="one"></div>
<div class="two"></div>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.