Pregunta

Any CSS savvy who have some spare time ?

I wonder how can i make such shape using CSS

shape

Thanks, Roee

¿Fue útil?

Solución

Kind of overkill, but this technique uses borders to create triangles:

Demo: 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;
}

Otros consejos

You can achieve this by using gradient background in CSS. This link will help you out.

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

Here is a sample:

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 */

Maybe using css border tricks and a layer acting as background you may accomplish this http://css-tricks.com/snippets/css/css-triangle/

In case you want to fill this with content , you may want to use transform:

Example with skewx(-15deg) on the full height of a page : http://codepen.io/anon/pen/Lvoaf/

HTML to draw 2 boxes aside each other:

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

and CSS that can go along :

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;
}

or a simple gradient http://codepen.io/anon/pen/FdhyG/

  html {
   background:linear-gradient(
    -50deg, 
    #FF4D4D 50%,
    #333333 50%
   );
  min-height:100%;}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top