0

The shape under red border:

enter image description here

I tried very hard to achieve this shape using CSS3 but all time I failed. I also tried to add border-bottom and border-left. See CSS code for understanding what I was doing:

#trapezoid {
  background: blue;
  height: 100px;
  width: 100px;
  margin: auto;
}
#trapezoid:before {
  content: "";
  position: absolute;
  border-top: 50px solid red;
  border-left: 50px solid transparent;
  margin: 50px 0px 0px -50px;
  transform: rotate(0deg);
}
#trapezoid:after {
  content: "";
  position: absolute;
  border-top: 50px solid red;
  border-right: 50px solid transparent;
  margin: 50px 0px 0px 100px;
  transform: rotate(0deg);
}
<div id="trapezoid"></div>

This CSS shape almost close to my requirement but we can't use image in extended area. Please suggest me some other method. Challenge is this, I have to create same layout and at place of grey background I've to show some content

2
  • 1
    Use SVG. Unless you can have non-transparent background where currently is grey color Commented Jul 11, 2017 at 6:49
  • Challenge is this, I have to create same layout and at place of grey background I've to show some content (may be Sliders or Other Image) Commented Jul 11, 2017 at 8:20

4 Answers 4

2

If you have a solid background color try this

body {
  background: grey;
  margin: 0;
}

.container {
  width: 100%;
  height: 200px;
  background: url("http://lorempixel.com/1000/300/nature/3");
  background-size:cover;
}

.content {
  height: 100px;
  color: #fff;
}

.shape {
  position: relative;
  height: 100px;
  overflow:hidden;
}

.shape:after {
  content: "";
  position: absolute;
  width: 40%;
  height: 100%;
  background: grey;
  top: 0;
  transform: skew(30deg);
  left: -10%;
}

.shape:before {
  content: "";
  position: absolute;
  width: 40%;
  height: 100%;
  background: grey;
  top: 0;
  transform: skew(-30deg);
  right: -10%;
}
<div class="container">
  <div class="content">
    Contents
  </div>
  <div class="shape"></div>
</div>

Sign up to request clarification or add additional context in comments.

4 Comments

You could do this with just one div though.
@VilleKoo yes i used two (childs) so that contents can be added and styled (vertical centering is also possible now)
This trick is pretty much ok, But What If I want to display some other info in at grey background? Challenge is this, I have to create same layout and at place of grey background I've to show some content
@AmarArya For that you will have to use svg
1

Depending on the browser support needed, You can use clip-path:

#trapezoid {
  background: url(https://upload.wikimedia.org/wikipedia/commons/8/83/Jho_Arce_User_Profile_Image.jpg) no-repeat;
  background-size: cover;
  height: 100px;
  width: 200px;
  margin: auto;
  -webkit-clip-path: polygon(100% 0, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0 0);
  clip-path: polygon(100% 0, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0 0)
}

body {
  background: silver;
}
<div id="trapezoid"></div>

Comments

0

Using :before and :after to place 2 triangles at the bottom

#trapezoid {
width: 200px;
height: 100px;
background-color: red;
position: relative;
}
#trapezoid:before {
content: "";
width: 0;
height: 0;
border-style: solid;
border-width: 0 30px 30px 30px;
border-color: transparent transparent white transparent;
display: block;
transform: rotate(-135deg);
position: absolute;
bottom: -5px;
left: -20px;
}
#trapezoid:after {
content: "";
width: 0;
height: 0;
border-style: solid;
border-width: 0 30px 30px 30px;
border-color: transparent transparent white transparent;
display: block;
transform: rotate(135deg);
position: absolute;
bottom: -5px;
right: -20px;
}
<div id="trapezoid"></div>

Comments

0

I think this will do the trick. Hope it will works for you.

.main-box{
  background:#ddd;
  width:300px;
  height:100px;
  display:inline-block;
  position:relative;
  text-align:center;
}
.main-box:after{
  content:'';
  width: 0;
  height: 0;
  border-bottom: 70px solid #999;
  border-right: 70px solid transparent;
  position:absolute;
  left:0;
  bottom:0;
}
.main-box:before{
  content:'';
  width: 0;
  height: 0;
  border-bottom: 70px solid #999;
  border-left: 70px solid transparent;
  position:absolute;
  right:0;
  bottom:0;
}
<div class="main-box"> #trial</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.