15

親 div の 100% ではなく、ボディの 100% 幅の内部 div を作成したいと考えています。これは可能ですか?

レイアウトは次のようになります。

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

      </div>
   </div>
</body>
4

7 に答える 7

11

私はあなたがこのように見えていることを願っています...........デモを見る

現在の要件に合わせて更新されたデモ 2

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;
}

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

ポジショニングなしの2番目の回答ですが、ここで使用したいくつかのトリックがあるので、以下のコードとデモを確認してください:-

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;
}

デモ

于 2012-11-22T11:05:45.027 に答える
4

vh および vw ユニットを使用できます

.parent {
  width: 900px;
  height: 400px;
  background-color: red;
}
.child {
  width: 100vw;
  height: 200px;
  background-color: blue;
}
<html>
  <body>
   <div class="parent"> 
      <div class="child"> 

      </div>
   </div>
</body>
</html>
于 2015-12-15T14:10:51.557 に答える
2

これを試して:

.inner {
  margin-left: -50vw;
  left: 50%;
  position: fixed;
  height: 100vw;
  width: 100vw;
  top: 0;
}

.outer {
  width: 900px;
  /* your outer div style*/
}
<body>
  <div class="outer"> /** Width:900px; **/
    <div class="inner"> /** This 100% of BODY, not of parent div **/

    </div>
  </div>
</body>

于 2020-01-15T13:16:24.940 に答える
0

あなたが求めていることは不可能だと思います。代わりに、レイアウトを再考することを検討する必要があります。私はよく次のようなことをしていることに気づきます。

html:

<div id="top">
    <div class="wrapper"></div>
</div>
<div id="content">
    <div class="wrapper"></div>
</div>
<div id="footer">
    <div class="wrapper"></div>
</div>

css:

#top {
  background: red;
}

#content {
  background: orange;
}

#footer {
  background: yellow;
}

.wrapper {
  width: 860px;
  margin: 0 auto;
  padding: 20px;
  background: rgba(255, 255, 255, 0.2);
}

デモ-http://jsfiddle.net/bxGH2/

于 2012-11-22T11:14:38.020 に答える
0

これはトリックを作りました。jQuery スクリプト:

$(document).ready(function () {
  var width = $(window).width();
  $('.pane-block-8').attr('style', 'width:' + width + 'px; left:-26.5% !important;');
});

$(window).resize(function () {
  var width = $(window).width();
  $('.pane-block-8').attr('style', 'width:' + width + 'px; left:-26.5% !important;');
});
于 2012-11-22T11:57:11.677 に答える
0

レイアウトを次のように変更することを検討してください。

http://jsfiddle.net/KpTHz/

次に、特定のルールを適用する DIV に ID タグを適用するだけです。

<div class="outer">
 <div class="inner">HEADER</div>
</div>

<div class="outer">
 <div class="inner">CONTENT</div>
</div>

<div class="outer">
 <div class="inner">FOOTER</div>
</div>


.outer {
 width:100%;
 background:#ccc;
}

.inner {
 width:920px;
 background:#999;
 margin:0 auto 20px;
 padding:20px;
}
于 2012-11-22T11:30:44.757 に答える