需要帮助创建slated或angled divs CSS / HTML

时间:2015-01-10 00:20:16

标签: html css responsive-design

我需要帮助创建具有背景图像的响应式div,这些背景图像具有倾斜或角度,没有边框,可以像这样:

http://jsfiddle.net/b4zjs60k/

<div class="rr-left">

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

</div>

我尝试使用此解决方案的背景图像,唯一的问题是成角度的边框是颜色,如果我添加背景图像,它看起来都搞砸了。

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

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

感谢希望这是有道理的

2 个答案:

答案 0 :(得分:1)

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

&#13;
&#13;
#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;
}
&#13;
<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 -->
&#13;
&#13;
&#13;

答案 1 :(得分:0)

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

&#13;
&#13;
.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;
}
&#13;
<div class="header">
    <div class="left">
    <div class="innerleft">
    <div class="leftcontent">LEFT</div>
    </div>
</div>    
    <div class="right"></div>
</div>
&#13;
&#13;
&#13;