代码之家  ›  专栏  ›  技术社区  ›  ItFreak

CSS在一行中拉伸所有div

  •  0
  • ItFreak  · 技术社区  · 8 年前

    border ). 所以我试着加上 align-items: stretch container div
    我可以把这个规则加到每个 部门 ,但这会导致左侧变大,而右侧保持不变。我想避免这种情况,相反,我想要完整的行(两者都是 部门 s) 被拉伸如果一个人被拉伸。
    我希望你能理解我想要达到的目标。
    我知道CSS是相当大的,但我张贴了一切,以确保没有我的错误,我错过了。

    澄清:
    我想最大限度地扩大 当内容不适合时 当窗户变小的时候 (如左一div):标题放在文本内,因为没有空格)


    body {
      margin:0;
    }
    .container {
      display:flex;
      flex-wrap:wrap;     
      height:100vh;
      background-color: white;
    }
    .container > div {
      min-height: 100vh;
      border: 1px solid black;
      box-sizing:border-box;
      background-color: inherit;
    }
    .container > div > a > .dot{
      position: relative;
      transition: background .2s linear;
      left: 50%;
      bottom: 10%;
      z-index: 101;
        height: 25px;
      width: 25px;
      background-color: white;
      border-radius: 50%;
      display: inline-block;
    }
    .container > div > a  > .dot > .arrow-down {
      transition: border .2s linear;
      position: absolute;
      top:11%;
      left: 24%;
      border: solid black;
      border-width: 0 3px 3px 0;
      display: inline-block;
      padding: 5px;
    }
    .container > div > a .dot:hover{
      background: black;
    }
    .container > div > a .dot:hover > .arrow-down{
        border: solid white;
        border-width: 0 3px 3px 0;
        display: inline-block;
        padding: 5px;
    }
    .container > div > a > .dot > .arrow-down{
        transform: rotate(45deg);
        -webkit-transform: rotate(45deg);
    }
    
    .container > div .content{
      height: 100vh;
      width: 100vw;
      background-color: inherit;
    }
    .full-width {
      width:100%;              
    }
    .half-width {
      width:50%;
    }
    
    .video-iframe.fullsize{
      height: 100%;
      width: 100%;
    }
    
    .list{
      text-align: center;
    }
    
    .half-width > .half-width-content{
      position: relative;
      margin-top: 0;
      height: 100%;
      width: 100%;
    }
    .half-width > .half-width-content > .instagram-slideshow{
      position: relative;
      height: 100%;
      width: 100%;
    }
    .half-width > .half-width-content > .instagram-slideshow > img{
      position: absolute;
      width: 60%;
      height: 60%;
      left: 50%;
      top:50%;
      visibility: visible;
      text-align: center;
      -webkit-transform: translate(-50%, -50%);
      transform: translate(-50%, -50%);
    }
    
    .half-width > .half-width-content > .half-width-text {
      position: absolute;
      left: 50%;
      top: 50%;
      visibility: visible;
      -webkit-transform: translate(-50%, -50%);
      transform: translate(-50%, -50%);
    }
    .half-width > .half-width-content > h1{
      position: relative;
      text-align: center;
      top: 15%;
    }
    
    .half-width-text > .middle-text{
      margin-left: -30px;
    }
    
    .list-div {
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    
    .list-div ul {
      padding: 0;
      width: 75%;
    
    }
    
    .list-div li {
      position: relative;
      display: block;
      margin-bottom: 5px;
      padding: 10px;
      text-align: left;
      visibility: visible;
      text-transform: uppercase;
    }
    
    
    .full-width > .content > .third-parent{
      height: 100%;
      display: flex;
    }
    
    .full-width > .content > .third-parent > .third{
      position: relative;
      flex: 1 1 0px;
    
      width: 100%;
    }
    
    .full-width > .content > .third-parent > .third > img{
      position: absolute;
      width: 100%;
      height: auto;
      left: 50%;
      top:50%;
      visibility: visible;
      text-align: center;
      -webkit-transform: translate(-50%, -50%);
      transform: translate(-50%, -50%);
    }
    
    .middle-text{
      position: absolute;
      width: 100%;
      left: 50%;
      top:50%;
      visibility: visible;
      text-align: center;
      -webkit-transform: translate(-50%, -50%);
      transform: translate(-50%, -50%);
    }
    
    .full-width > .content > .third-parent > .third > .middle-text > .list-div2{
        display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
    }
    
    .full-width > .content > .third-parent > .third > .middle-text > .list-div2  li{
       position: relative;
      display: block;
      border: 1px solid red;
      margin-bottom: 5px;
      padding: 10px;
      text-align: left;
      text-transform: uppercase;
      visibility: visible;
    }
    
    .list-div2 li::before{
      content: '\2022';
      margin-right: 10px;
    }
    .items-list2 {
      margin: 0;
      padding: 0;
    }
    <div class="container">
      <div class="full-width">
    <iframe class="video-iframe fullsize" src="https://www.youtube.com/embed/osg9PmkfTB0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
        <a href="#section2">
          <span class="dot">
            <i class="arrow-down"></i>
          </span>
        </a>
      </div>
      <div class="half-width" id="section2">
        <div class="half-width-content">
                  <h1>Headline</h1>
          <div class="half-width-text">
            <div class="text-content">
            <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
              </p>
            </div>
          </div>
        </div>
      </div>
      <div class="half-width">
        <div class="half-width-content">
          <div class="instagram-slideshow" id="1">
            <img class="slide" src="http://placekitten.com/200/300">
            <img class="slide" src="https://placeimg.com/640/480/animals">
            <img class="slide" src="http://placekitten.com/200/300">
          </div>
        </div>
      </div>
      <div class="half-width">
        <div class="half-width-content">
          <div class="instagram-slideshow" id="2">
            <img class="slide" src="https://fakeimg.pl/350x200/?text=Hello">
            <img class="slide" src="https://fakeimg.pl/350x200/?text=Bye">
            <img class="slide" src="https://fakeimg.pl/350x200/?text=BLA">
          </div>
        </div>
      </div>
      <div class="half-width">
        <div class="half-width-content">
    	<div class="middle-text">
    	<h2>Headline</h2>
    	<p>
    	This is some text paragraph
    	</p>
          <div class="list-div">
            <ul class="items-list" id="list">
              <li>Lorem ipsum dolor sit amet, consetetur sadipscing elitr</li>
              <li>sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam </li>
              <li>sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</li>
              <li>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li>
            </ul>
          </div>
        </div>
    	</div>
      </div>
      <div class="full-width">
        <div class="content">
           <div class="third-parent">
             <div class="third" id="one">
               <img src="https://fakeimg.pl/350x200/?text=right">
              </div>
            <div class="third" id="two">
              <div class="middle-text">
                <h1>Headline</h1>
                      <div class="list-div2">
            <ul class="items-list2" id="list">
              <li>Entry A</li>
              <li>Entry B</li>
              <li>Entry C</li>
              <li>Entry D</li>
            </ul>
          </div>
              </div>
            </div>
            <div class="third" id="three">
              <img src="https://fakeimg.pl/350x200/?text=left">
            </div>
             </div>
           </div>
    </div>
    </div>
    1 回复  |  直到 8 年前
        1
  •  1
  •   Nimitt Shah    8 年前

    我想我知道你想要什么。您正在使用 left 和 top 具有 transform: translate(-50%, -50%);

    我已经评论了不需要的CSS并添加了替代。。请检查下面。

    body {
      margin:0;
    }
    .container {
      display:flex;
      flex-wrap:wrap;     
      height:100vh;
      background-color: white;
    }
    .container > div {
      min-height: 100vh;
      border: 1px solid black;
      box-sizing:border-box;
      background-color: inherit;
    }
    .container > div > a > .dot{
      position: relative;
      transition: background .2s linear;
      left: 50%;
      bottom: 10%;
      z-index: 101;
        height: 25px;
      width: 25px;
      background-color: white;
      border-radius: 50%;
      display: inline-block;
    }
    .container > div > a  > .dot > .arrow-down {
      transition: border .2s linear;
      position: absolute;
      top:11%;
      left: 24%;
      border: solid black;
      border-width: 0 3px 3px 0;
      display: inline-block;
      padding: 5px;
    }
    .container > div > a .dot:hover{
      background: black;
    }
    .container > div > a .dot:hover > .arrow-down{
        border: solid white;
        border-width: 0 3px 3px 0;
        display: inline-block;
        padding: 5px;
    }
    .container > div > a > .dot > .arrow-down{
        transform: rotate(45deg);
        -webkit-transform: rotate(45deg);
    }
    
    .container > div .content{
      height: 100vh;
      width: 100vw;
      background-color: inherit;
    }
    .full-width {
      width:100%;   
      position:relative;           
    }
    .half-width {
      width:50%;
      position:relative;
      overflow: auto
    }
    
    .video-iframe.fullsize{
      height: 100%;
      width: 100%;
    }
    
    .list{
      text-align: center;
    }
    
    .half-width > .half-width-content{
      position: relative;
      margin-top: 0;
      height: 100%;
      width: 100%;
    }
    .half-width > .half-width-content > .instagram-slideshow{
      position: relative;
      height: 100%;
      width: 100%;
    }
    .half-width > .half-width-content > .instagram-slideshow > img{
      position: absolute;
      width: 60%;
      height: 60%;
      margin: auto;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      /*left: 50%;
      top:50%;*/
      visibility: visible;
      text-align: center;
      /*-webkit-transform: translate(-50%, -50%);
      transform: translate(-50%, -50%);*/
    }
    
    .half-width > .half-width-content > .half-width-text {
      /*position: absolute;
      left: 50%;
      top: 50%;*/
      visibility: visible;
      /*-webkit-transform: translate(-50%, -50%);
      transform: translate(-50%, -50%);*/
      padding-left: 50px;
        padding-right: 50px;
    }
    .half-width#section2 > .half-width-content, .half-width#section3 > .half-width-content {
        display: flex;
      flex-direction: column;
      justify-content: center;
    }
    
     .half-width > .half-width-content > h1{
      position: relative;
      text-align: center;
      /*top: 15%;*/
    }
    
    .half-width-text > .middle-text{
      margin-left: -30px;
    }
    
    .list-div {
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    
    .list-div ul {
      padding: 0;
      width: 75%;
    
    }
    
    .list-div li {
      position: relative;
      display: block;
      margin-bottom: 5px;
      padding: 10px;
      text-align: center;
      visibility: visible;
      text-transform: uppercase;
    }
    
    
    .full-width > .content > .third-parent{
      height: 100%;
      display: flex;
    }
    
    .full-width > .content > .third-parent > .third{
      position: relative;
      flex: 1 1 0px;
    
      width: 100%;
          display: flex;
        align-items: center;
        align-content: center;
        justify-content: center;
    }
    
    .full-width > .content > .third-parent > .third > img{
      position: absolute;
      width: 100%;
      height: auto;
      left: 50%;
      top:50%;
      visibility: visible;
      text-align: center;
      -webkit-transform: translate(-50%, -50%);
      transform: translate(-50%, -50%);
    }
    
    .middle-text{
      /*position: absolute;
      width: 100%;
      left: 50%;
      top:50%;*/
      visibility: visible;
      text-align: center;
      /*-webkit-transform: translate(-50%, -50%);
      transform: translate(-50%, -50%);*/
    }
    
    .full-width > .content > .third-parent > .third > .middle-text > .list-div2{
        display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
    }
    
    .full-width > .content > .third-parent > .third > .middle-text > .list-div2  li{
       position: relative;
      display: block;
      border: 1px solid red;
      margin-bottom: 5px;
      padding: 10px;
      text-align: center;
      text-transform: uppercase;
      visibility: visible;
    }
    
    .list-div2 li::before{
      content: '\2022';
      margin-right: 10px;
    }
    .items-list2 {
      margin: 0;
      padding: 0;
    }
    <div class="container">
      <div class="full-width">
    <iframe class="video-iframe fullsize" src="https://www.youtube.com/embed/osg9PmkfTB0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
        <a href="#section2">
          <span class="dot">
            <i class="arrow-down"></i>
          </span>
        </a>
      </div>
      <div class="half-width" id="section2">
        <div class="half-width-content">
                  <h1>Headline</h1>
          <div class="half-width-text">
            <div class="text-content">
            <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
            </div>
          </div>
        </div>
      </div>
      <div class="half-width">
        <div class="half-width-content">
          <div class="instagram-slideshow" id="1">
            <img class="slide" src="http://placekitten.com/200/300">
            <img class="slide" src="https://placeimg.com/640/480/animals">
            <img class="slide" src="http://placekitten.com/200/300">
          </div>
        </div>
      </div>
      <div class="half-width">
        <div class="half-width-content">
          <div class="instagram-slideshow" id="2">
            <img class="slide" src="https://fakeimg.pl/350x200/?text=Hello">
            <img class="slide" src="https://fakeimg.pl/350x200/?text=Bye">
            <img class="slide" src="https://fakeimg.pl/350x200/?text=BLA">
          </div>
        </div>
      </div>
      <div class="half-width" id="section3">
        <div class="half-width-content">
    	<div class="middle-text">
    	<h2>Headline</h2>
    	<p>
    	This is some text paragraph
    	</p>
          <div class="list-div">
            <ul class="items-list" id="list">
              <li>Lorem ipsum dolor sit amet, consetetur sadipscing elitr</li>
              <li>sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam </li>
              <li>sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</li>
              <li>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li>
            </ul>
          </div>
        </div>
    	</div>
      </div>
      <div class="full-width" id="section4">
        <div class="content">
           <div class="third-parent">
             <div class="third" id="one">
               <img src="https://fakeimg.pl/350x200/?text=right">
              </div>
            <div class="third" id="two">
              <div class="middle-text">
                <h1>Headline</h1>
                      <div class="list-div2">
            <ul class="items-list2" id="list">
              <li>Entry A</li>
              <li>Entry B</li>
              <li>Entry C</li>
              <li>Entry D</li>
            </ul>
          </div>
              </div>
            </div>
            <div class="third" id="three">
              <img src="https://fakeimg.pl/350x200/?text=left">
            </div>
             </div>
           </div>
    </div>
    </div>

    https://jsfiddle.net/nimittshah/gda5f643/36/