【问题标题】:How to make vertical split screens with two divs?如何用两个div制作垂直分屏?
【发布时间】:2022-01-27 04:34:42
【问题描述】:

我想使用htmlcss 创建拆分页面,但不幸的是它会一个接一个。

@import url('https://fonts.googleapis.com/css?family=Open+Sans:300,400,800');

@media (min-width: 500px) {
  .col-sm-6 {
    width: 50%;
  }
}
html, body {
  height: 100%;
  min-height: 18em;
}

.frontend-side {
  background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/74452/website-code.png");
}

.uiux-side {
  background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/74452/website-post-its.png");
}

.split-pane {
  padding-top: 1em;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center center;
  height: 50%;
  min-height: 9em;
  font-size: 2em;
  color: white;
  font-family: 'Open Sans', sans-serif;
  font-weight:300;
;
}
@media(min-width: 500px) {
  .split-pane {
    padding-top: 2em;
    height: 100%;
  }
}
.split-pane > div {
  position: relative;
  top: 50%;
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
  text-align: center;
}
.split-pane > div .text-content {
  line-height: 1.6em;
  margin-bottom: 1em;
}
.split-pane > div .text-content .big {
  font-size: 2em;
}
.split-pane > div img {
  height: 1.3em;
}
@media (max-width: 500px) {
  .split-pane > div img {
    display:none;
  }
}
.split-pane button, .split-pane a.button {
  font-family: 'Open Sans', sans-serif;
  font-weight:800;
  background: none;
  border: 1px solid white;
  -moz-border-radius: 5px;
  -webkit-border-radius: 5px;
  border-radius: 5px;
  width: 15em;
  padding: 0.7em;
  font-size: 0.5em;
  -moz-transition: all 0.2s ease-out;
  -o-transition: all 0.2s ease-out;
  -webkit-transition: all 0.2s ease-out;
  transition: all 0.2s ease-out;
  text-decoration: none;
  color: white;
  display: inline-block;
  cursor: pointer;
}
.split-pane button:hover, .split-pane a.button:hover {
  text-decoration: none;
  background-color: white;
  border-color: white;
  cursor: pointer;
}
.uiux-side.split-pane button:hover, .split-pane a.button:hover {
  color: violet;
}
.frontend-side.split-pane button:hover, .split-pane a.button:hover {
  color: blue;
}

#split-pane-or {
  font-size: 2em;
  color: white;
  font-family: 'Open Sans', sans-serif;
  text-align: center;
  width: 100%;
  position: absolute;
  top: 50%;
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
}
@media (max-width: 925px) {
  #split-pane-or {
    top:15%;
  }
}
#split-pane-or > div img {
  height: 2.5em;
}
@media (max-width: 500px) {
  #split-pane-or {
    position: absolute;
    top: 50px;
  }
  #split-pane-or > div img {
    height:2em;
  }
}
@media(min-width: 500px) {
  #split-pane-or {
    font-size: 3em;
  }
}
.big {
  font-size: 2em;
}

#slogan {
  position: absolute;
  width: 100%;
  z-index: 100;
  text-align: center;
  vertical-align: baseline;
  top: 0.5em;
  color: white;
  font-family: 'Open Sans', sans-serif;
  font-size: 1.4em;
}
@media(min-width: 500px) {
  #slogan {
    top: 5%;
    font-size: 1.8em;
  }
}
#slogan img {
  height: 0.7em;
}
.bold {
  text-transform:uppercase;
}
.big {
  font-weight:800;
}
<head>
<title>Wybierz Swój Maraton! </title>
<link rel ="stylesheet" href="/wybierzmaraton.css" />
</head>
<div class='split-pane col-xs-12 col-sm-6 uiux-side'>
  <div>
    <img src='myContent1.png.png'>
    <div class='text-content'>
      <div class="bold">YOU WANT</div>
      <div class='big'>MARATON MATURZYSTY?</div>
    </div>
    <button>
      KLIKNIJ
    </button>
  </div>
</div>
<div class='split-pane col-xs-12 col-sm-6 frontend-side'>
  <div>
    <img src='myContent.png'>
    <div class='text-content'>
      <div class="bold">YOU WANT</div>
      <div class='big'>this?</div>
    </div>
    <a class='button'>
      KLIKNIJ
    </a>
  </div>
</div>
<div id='split-pane-or'>
  <div>
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/74452/bcr-white.png'>
  </div>
</div>

效果是我将这些 div 放在另一个之下。

如何更改并正确制作? 我也尝试使用此链接中的自定义形状,但我只得到空白。 vertical split-screen custom shape

我从这个网站得到它 https://speckyboy.com/snippets-split-screen-layouts/

【问题讨论】:

    标签: html css twitter-bootstrap flexbox bootstrap-5


    【解决方案1】:

    默认情况下,您的 DIV 是“块”,这意味着它们的宽度是 100%,您不能将两个 div 并排放置。解决此问题的方法是使用 CSS FLEX 显示属性,我强烈建议您观看 Youtube 视频,因为如果您真正看到元素如何放置它们,就会更容易理解。

    简而言之,在一个元素上使用“display: flex”意味着他们的子元素将根据自己的宽度尝试适应一行或多行。还有一些其他的 CSS 属性可以帮助你以你想要的方式定位你的 div。在您的情况下,您只想将两个元素放在同一行,因此一个简单的解决方案可能是添加一个新的 div 来包装您的两个现有 div 并使其具有弹性,因此您将看到您正在获得 2 个 div同一行

    @import url('https://fonts.googleapis.com/css?family=Open+Sans:300,400,800');
    
    @media (min-width: 500px) {
      .col-sm-6 {
        width: 50%;
      }
    }
    html, body {
      height: 100%;
      min-height: 18em;
    }
    
    .frontend-side {
      background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/74452/website-code.png");
    }
    
    .uiux-side {
      background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/74452/website-post-its.png");
    }
    
    .split-pane {
      padding-top: 1em;
      background-size: cover;
      background-repeat: no-repeat;
      background-position: center center;
      height: 50%;
      min-height: 9em;
      font-size: 2em;
      color: white;
      font-family: 'Open Sans', sans-serif;
      font-weight:300;
    ;
    }
    @media(min-width: 500px) {
      .split-pane {
        padding-top: 2em;
        height: 100%;
      }
    }
    .split-pane > div {
      position: relative;
      top: 50%;
      -webkit-transform: translateY(-50%);
      -ms-transform: translateY(-50%);
      transform: translateY(-50%);
      text-align: center;
    }
    .split-pane > div .text-content {
      line-height: 1.6em;
      margin-bottom: 1em;
    }
    .split-pane > div .text-content .big {
      font-size: 2em;
    }
    .split-pane > div img {
      height: 1.3em;
    }
    @media (max-width: 500px) {
      .split-pane > div img {
        display:none;
      }
    }
    .split-pane button, .split-pane a.button {
      font-family: 'Open Sans', sans-serif;
      font-weight:800;
      background: none;
      border: 1px solid white;
      -moz-border-radius: 5px;
      -webkit-border-radius: 5px;
      border-radius: 5px;
      width: 15em;
      padding: 0.7em;
      font-size: 0.5em;
      -moz-transition: all 0.2s ease-out;
      -o-transition: all 0.2s ease-out;
      -webkit-transition: all 0.2s ease-out;
      transition: all 0.2s ease-out;
      text-decoration: none;
      color: white;
      display: inline-block;
      cursor: pointer;
    }
    .split-pane button:hover, .split-pane a.button:hover {
      text-decoration: none;
      background-color: white;
      border-color: white;
      cursor: pointer;
    }
    .uiux-side.split-pane button:hover, .split-pane a.button:hover {
      color: violet;
    }
    .frontend-side.split-pane button:hover, .split-pane a.button:hover {
      color: blue;
    }
    
    #split-pane-or {
      font-size: 2em;
      color: white;
      font-family: 'Open Sans', sans-serif;
      text-align: center;
      width: 100%;
      position: absolute;
      top: 50%;
      -webkit-transform: translateY(-50%);
      -ms-transform: translateY(-50%);
      transform: translateY(-50%);
    }
    @media (max-width: 925px) {
      #split-pane-or {
        top:15%;
      }
    }
    #split-pane-or > div img {
      height: 2.5em;
    }
    @media (max-width: 500px) {
      #split-pane-or {
        position: absolute;
        top: 50px;
      }
      #split-pane-or > div img {
        height:2em;
      }
    }
    @media(min-width: 500px) {
      #split-pane-or {
        font-size: 3em;
      }
    }
    .big {
      font-size: 2em;
    }
    
    #slogan {
      position: absolute;
      width: 100%;
      z-index: 100;
      text-align: center;
      vertical-align: baseline;
      top: 0.5em;
      color: white;
      font-family: 'Open Sans', sans-serif;
      font-size: 1.4em;
    }
    @media(min-width: 500px) {
      #slogan {
        top: 5%;
        font-size: 1.8em;
      }
    }
    #slogan img {
      height: 0.7em;
    }
    .bold {
      text-transform:uppercase;
    }
    .big {
      font-weight:800;
    }
    
    .div-flex {
      /* And this is your new CSS Class */
      display: flex
    }
    <div class='div-flex'> <!-- This is your new DIV -->
      <div class='split-pane col-xs-12 col-sm-6 uiux-side'>
        <div>
          <img src='myContent1.png.png'>
          <div class='text-content'>
            <div class="bold">YOU WANT</div>
            <div class='big'>MARATON MATURZYSTY?</div>
          </div>
          <button>
            KLIKNIJ
          </button>
        </div>
      </div>
      <div class='split-pane col-xs-12 col-sm-6 frontend-side'>
        <div>
          <img src='myContent.png'>
          <div class='text-content'>
            <div class="bold">YOU WANT</div>
            <div class='big'>this?</div>
          </div>
          <a class='button'>
            KLIKNIJ
          </a>
        </div>
      </div>
    </div>
    <div id='split-pane-or'>
      <div>
        <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/74452/bcr-white.png'>
      </div>
    </div>

    【讨论】:

      【解决方案2】:

      您似乎已经在使用 Bootstrap。所以在这种情况下,我建议使用两个col-6 来分割页面。见下文。

      img {
        width: 100%;
      }
      
      .frontend-side {
        background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/74452/website-code.png");
        background-size: cover;
        background-repeat: no-repeat;
        height: 100vh;
      }
      
      .uiux-side {
        background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/74452/website-post-its.png");
        background-size: cover;
        background-repeat: no-repeat;
        height: 100vh;
      }
      
      .col-6 {
        padding: 0 !important;
      }
      
      body {
        overflow-x: hidden;
      }
      <head>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
      </head>
      
      <body>
        <div class="row">
          <div class="col-6">
            <div class="uiux-side"></div>
          </div>
          <div class="col-6">
            <div class="frontend-side"></div>
          </div>
        </div>
      </body>

      编辑 ~ 我将您使用的实际图像添加为 div 上的background-images 并设置背景属性,以便它们显示全高。 col-6 默认情况下会给你半个半宽度,但为了让它看起来每一边都在使用 50vw 你必须添加 padding: 0 !important; 来覆盖引导程序在 col 上的默认填充。

      【讨论】:

        猜你喜欢
        • 2019-12-30
        • 1970-01-01
        • 1970-01-01
        • 2012-08-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-22
        • 1970-01-01
        • 2013-09-23
        相关资源
        最近更新 更多