双方'切'页面

时间:2016-09-27 17:57:35

标签: html css

我想在两边“剪切”我的页面,如下所示:

http://i.stack.imgur.com/ngZrp.jpg

DEMO https://jsfiddle.net/r2g0eyxf/3/

#left {
   background: url(https://static.pexels.com/photos/24353/pexels-photo.jpg);
   width: 50%;
   position: absolute;
   left: 0px;
   height: 100%;
}

#right {
   background: url(http://media.caranddriver.com/images/media/51/25-cars-worth-waiting-for-lp-ferrari-488gtb-photo-658256-s-original.jpg);
   width: 50%;
   position: absolute;
   right: 0px;
   height: 100%;
}

可是:

  • 我需要这个图片响应
  • 我想创建这个'斜杠'

我该怎么做?

修改
This没有解决我的问题 - 我在整页上需要它,图像之间没有空格。

2 个答案:

答案 0 :(得分:1)

提示是使用变换和一些填充。

average example



body {
  margin: 0;
  padding: 0;
  width:100%;
  overflow-x:hidden;
  color:turquoise;
  text-shadow:0 0  white;
  font-size:2em;
}

#left {
  position: absolute;
  left: -10%;
  height: 100%;
}

#left,
#right {
  width: 60%;
  transform: skew(-15deg);
  overflow: hidden;
}

#left .content {
  background: url(https://static.pexels.com/photos/24353/pexels-photo.jpg);
  height: 100%;
}

#right .content {
  height: 100%;
  background: url(http://media.caranddriver.com/images/media/51/25-cars-worth-waiting-for-lp-ferrari-488gtb-photo-658256-s-original.jpg);
}

#right {
  position: absolute;
  right: -10%;
  height: 100%;
}

#left .content, 
#right .content{
  width: 100%;
  padding: 0 20%;
  margin: 0 -15%;
  transform: skew(15deg);
  display: flex;
  align-items: center;
  justify-content: center;
  background-size: cover;
}

<div id="left">
  <div class="content">Content here</div>
</div>
<div id="right">
  <div class="content">Content here</div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以使用clip-pathsupport

.clipped-img {
  position: relative;
}
.clipped-img img {
  position: absolute;
  width: 50%;
}
.clipped-img img:nth-child(1) {
  -webkit-clip-path: polygon( 0% 0, 100% 0, 80% 100%, 0 100% );
  clip-path: polygon( 0% 0, 100% 0, 80% 100%, 0 100% );
}
.clipped-img img:nth-child(2) {
  right: 10%;
  -webkit-clip-path: polygon( 20% 0, 100% 0, 100% 100%, 0 100% );
  clip-path: polygon( 20% 0, 100% 0, 100% 100%, 0 100% );
}
<div class="clipped-img">
  <img src="http://placehold.it/500x300/FC0/">
  <img src="http://placehold.it/500x300/CC0/">
</div>