我怎样才能使用CSS制作这样的背景?

时间:2014-04-09 09:07:28

标签: css background shape

任何有空余时间的CSS精明者?

我想知道如何使用CSS

制作这样的形状

shape

谢谢, Roee

4 个答案:

答案 0 :(得分:2)

您可以通过在CSS中使用渐变背景来实现此目的。此链接将帮助您。

http://www.colorzilla.com/gradient-editor/

以下是一个示例:

background: #000000; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background:     url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMTAwJSI+CiAgICA8c3RvcCBvZmZzZXQ9IjUwJSIgc3RvcC1jb2xvcj0iIzAwMDAwMCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUwJSIgc3RvcC1jb2xvcj0iI2ZmNGQ0ZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
 background: -moz-linear-gradient(-45deg,  #000000 50%, #ff4d4d 50%); /* FF3.6+ */
 background: -webkit-gradient(linear, left top, right bottom, color-stop(50%,#000000),  color-stop(50%,#ff4d4d)); /* Chrome,Safari4+ */
 background: -webkit-linear-gradient(-45deg,  #000000 50%,#ff4d4d 50%); /* Chrome10+,Safari5.1+ */
 background: -o-linear-gradient(-45deg,  #000000 50%,#ff4d4d 50%); /* Opera 11.10+ */
 background: -ms-linear-gradient(-45deg,  #000000 50%,#ff4d4d 50%); /* IE10+ */
 background: linear-gradient(135deg,  #000000 50%,#ff4d4d 50%); /* W3C */
 filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000',   endColorstr='#ff4d4d',GradientType=1 ); /* IE6-8 fallback on horizontal gradient */

答案 1 :(得分:2)

有点矫枉过正,但这种技术使用边框来创建三角形:

演示:http://jsfiddle.net/HNDDr/5/

#bg {
    background: black;
    height: 300px;
    width: 345px;
    position: relative;
    overflow:hidden;
}

#bg:before {
    content: "";
    display: block;
    width: 115px;
    height: 0px;
    border-style: solid;
    border-width: 0 115px 300px 115px;
    border-color: transparent transparent #ef665a transparent;
    position: absolute;
    right: -115px;
}

答案 2 :(得分:0)

也许使用css边框技巧和作为背景的图层可以实现此目的 http://css-tricks.com/snippets/css/css-triangle/

答案 3 :(得分:0)

如果您想用内容填充此内容,可能需要使用transform

在页面的完整高度上使用skewx(-15deg)的示例:http://codepen.io/anon/pen/Lvoaf/

HTML将2个盒子彼此放在一边:

<section>
  <div>
  left side
</div>
</section>
<section>
<div>
  right side
</div>
</section>

和可以携带的CSS:

html, body {
  height:100%;
  width:100%;
  background:#FF4D4D;
}
body {
  margin:0;
  display:table;
  padding-left:10%;
  width:80%;
  background:#333;  
  border-spacing:0;
}
section {
  display:table-cell;
  width:50%;
  color:white;
  background:#333;
  transform:skewx(-15deg);
  height:100%;
}
section + section {
  background:#FF4D4D;
}
section > div {
  transform:skewx(15deg); 
  transform-origin:bottom right;
  min-height:100%;
  padding:1em;
  box-sizing:border-box;
  background-color:inherit;
}
section + section > div {
  transform-origin:top left;
}

或简单的渐变http://codepen.io/anon/pen/FdhyG/

  html {
   background:linear-gradient(
    -50deg, 
    #FF4D4D 50%,
    #333333 50%
   );
  min-height:100%;}