【问题标题】:Need help creating slated or angled divs CSS/HTML需要帮助创建 slated 或有角度的 div CSS/HTML
【发布时间】:2015-01-13 04:00:53
【问题描述】:

我需要帮助创建具有倾斜或角度的背景图像的响应式 div,以实现如下所示:

http://jsfiddle.net/b4zjs60k/

<div class="rr-left">

</div>
<div class="rr-right">

</div>

我已经尝试在这个解决方案中使用背景图片,唯一的问题是有角度的边框是彩色的,如果我添加背景图片,它看起来全乱了。

我见过这个:http://codepen.io/jefflupinski/pen/azvsA,但歪斜的唯一问题是我需要左右两边是直的

所以我想知道是否有人找到了一种解决方案,可以让两个 div 都触摸并具有响应式背景,或者将两者结合起来以合并图像

谢谢,希望这是有道理的

【问题讨论】:

  • 除非背景图像是可平铺的,否则您将无法对背景图像执行此操作,因为有角度的部分是伪:before/:after 元素。跨度>
  • 有没有办法不用伪元素来做到这一点
  • 分割背景图片,在元素中使用一张,在伪元素中使用一张。使用背景定位直到它对齐。
  • 或许可以使用-webkit-clip-path。见this example

标签: html css responsive-design


【解决方案1】:

尝试以下方法并根据需要进行调整。

#holder {
  height: auto;
  width: auto;
  float: left;
  overflow: hidden;
  font-family: calibri;
  background-color: white;
  position: relative;
}
#holder .content {
  display: inline-block;
  width: 45%;
  text-align: center;
  position: relative;
  color: white;
  cursor: pointer;
  background: #2c3e50;
  margin-left: 0;
  z-index: 2;
}
#holder .content:hover {
  background-color: #425160;
}
.content:hover .line {
  background: #425160!important;
}
#holder .line {
  -ms-transform: rotate(10deg);
  /* IE 9 */
  -webkit-transform: rotate(10deg);
  /* Chrome, Safari, Opera */
  transform: rotate(10deg);
  border-left: solid 1px white;
  position: absolute;
  right: 89%;
  display: block;
  width: 40px;
  background: inherit;
  height: 250px;
  bottom: -10px;
  z-index: -1;
}
p,
h3 {
  padding: 0 30px 0 30px;
  text-align: left;
  width: 70%;
}
h3 {
  font-size: 24px;
  line-height: 24px;
  margin-bottom: 0;
}
<div id="holder">

  <div class="content">

    <h3>This is a header</h3>
    <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>

  </div>

<div class="content">

    <div class="line"></div>

    <h3>This is a header</h3>
    <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>

  </div>


</div>
<!-- End Holder -->

【讨论】:

    【解决方案2】:

    这是我的答案,使用倾斜,但在一个隐藏溢出的容器中

    .header {
        width: 100%;
        height: 0%;
        padding-bottom: 25%;
        position: relative;
        overflow: hidden;
    }
    
    .left {
        width: 60%;
        height: 100%;
        position: absolute;
        right: 50%;
        top: 0px;
        transform: skew(-20deg);
        overflow: hidden;}
    
    .right {
        width: 60%;
        height: 100%;
        position: absolute;
        left: 50%;
        top: 0px;
        transform: skew(-20deg);
        overflow: hidden;
    }
    
    .innerleft {
        content: "";
        position: absolute;
        width: 100%;
        height: 100%;
        background-image: url(http://placekitten.com/800/400);
        transform: skew(20deg);
        left: 10%;
        background-size: cover;
    }
    .leftcontent {
        position: absolute;
        left: 100px;
        top: 60px;
        color: white;
        font-size: 40px;
    
    }
    
    .right:after {
        content: "";
        position: absolute;
        width: 100%;
        height: 100%;
        background-image: url(http://placekitten.com/600/500);
        transform: skew(20deg);
        right: 10%;
        background-size: cover;
    }
    <div class="header">
        <div class="left">
        <div class="innerleft">
        <div class="leftcontent">LEFT</div>
        </div>
    </div>    
        <div class="right"></div>
    </div>

    【讨论】:

    • 太好了,效果很好,但是当我尝试将任何内容放入其中时,它只会将背景推到任何修复中,谢谢
    • 添加一个带有文本的内部 div。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    • 1970-01-01
    • 2020-03-06
    相关资源
    最近更新 更多