css - 单边倾斜与CSS

标签 css skew

我想创建一个单边倾斜,但没有成功。到目前为止,这是我尝试过的:

    .bg-style1 {
      background: #ccc;
      position: relative;
      display: block;
      z-index: 2;
    }
    .bg-style1:after {
      content: " ";
      position: absolute;
      display: block;
      width: 30%;
      height: 100%;
      top: 0;
      left: 0;
      z-index: -1;
      background: #333333;
      -ms-transform: skew(-30deg, 0deg);
      -webkit-transform: skew(-30deg, 0deg);
      transform: skew(-30deg, 0deg);
    }
<section class="page">
  <div class="bg-style1">
    .....content goes here
  </div>
</section>

但它不起作用。看:enter image description here

我想完成的事情:enter image description here

最佳答案

overflow:hidden 添加到您的 .bg-style1 规则并将 transformX(-40%) 添加到 transform:.bg-style1:after

.bg-style1 {
  padding-top: ;
  background: #ccc;
  position: relative;
  display: block;
  z-index: 2;
  overflow: hidden;
}
.bg-style1:after {
  content: " ";
  position: absolute;
  display: block;
  width: 30%;
  height: 100%;
  left: 0;
  top: 0;
  z-index: -1;
  background: #333333;
  -ms-transform: skew(-30deg, 0deg);
  -webkit-transform: skew(-30deg, 0deg);
  transform: skew(-30deg, 0deg) translateX(-50%);
}
<section class="page">
  <div class="bg-style1">
    <h1>What is lorem ipsum</h1>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
    survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
    software like Aldus PageMaker including versions of Lorem Ipsum.
  </div>
</section>

关于css - 单边倾斜与CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30279790/

相关文章:

r - 如何在 R 中生成给定的均值、SD、偏斜和峰度分布?

java - 如何将 BufferedImage 转换为 javaxt.io.Image?

java - Leptonica findSkew 返回 0.0

CSS:绝对(?)定位倾斜元素(无JS!重要)

css - 在表格前面显示弹出菜单

jquery - 添加覆盖元素背景属性的类

javascript - chart.js 在 div 和 Canvas 之外呈现

wpf - 在 XAML 中从菱形的偏斜因子创建偏斜 AngleY

javascript - 有没有办法使媒体打印 css 显示为普通 View ?

html - 删除标题(标题 img ?)和导航之间的间隙