我怎么能用css背景形状?

时间:2016-04-26 19:08:20

标签: html css svg css-shapes

我使用具有transform:skew();

的css属性的div实现了类似的功能

image

然而,我希望它有一条曲线,线条正在上升,所以如果你能给我一个正确的方向,或告诉我更多关于插入响应svg图形艺术的最简单的方法特别是元素的背景或页面本身,我们非常感激

编辑:这里使用CSS

onCreate

2 个答案:

答案 0 :(得分:6)

您还可以使用linear-gradient(再次),实际上是2和background-size

body {
  width: 80%;/* whatever , can be a fixed width , basicly to show behavior on resize */
  margin: auto;
}
body>div {
  background: 
    linear-gradient(to bottom right, #830024 50%, transparent 50.5%) no-repeat bottom,
    /* bottom part */
    linear-gradient(0deg, #830024, #830024) no-repeat top;
  /* top portion */
  color: white;
  padding-bottom: 3em;
  background-size: 100% 7em, 100% calc(100% - 7em)
}
<div>
  <h1>HTML Ipsum Presents</h1>

  <p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris
    placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
    tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>

  <h2>Header Level 2</h2>
</div>
<ol>
  <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
  <li>Aliquam tincidunt mauris eu risus.</li>
</ol>

codepen to play with

答案 1 :(得分:3)

您可以将skew变换应用于伪元素(如::after)而不使用SVG或影响主元素(也减少了对额外HTML元素的需求):

&#13;
&#13;
header {
  background: #CCC;
  padding: 2em;
}

.skewed-bg {
    background: #830024;
    color: #FFF;
    padding: 2em;
    position: relative;
    min-height:300px;
    overflow:hidden;
}
.skewed-bg::after {
  content: '';
  position: absolute;
  bottom: -75%; left: 0; right: 0;
  height:100%;
  background:#FFF;
  transform: skew(0deg, -9deg);
}
&#13;
<header>Power</header>
<div class="skewed-bg">
  Quienes Somos.
</div>
&#13;
&#13;
&#13;

jsFiddle:https://jsfiddle.net/w6690acn/1/