div with triangle at the bottom with background image
Triangle over a plain color
If the triangle is displayed over a plain color, you can use this approach with an absolutely positioned pseudo element :
div{
position:relative;
background:url('http://i.imgur.com/W27LCzB.jpg');
background-size:cover;
min-height:100px;
padding-bottom:100px;
overflow:hidden;
}
div:after{
content:'';
position:absolute;
bottom:0; left:0;
border-left:50vw solid #fff;
border-right:50vw solid #fff;
border-top:100px solid transparent;
}
<div></div>
How to make a triangle shape in the bottom of the div
I'd go with clip-path
to achieve something like this.
.clipped {
clip-path: polygon(100% 0%, 100% 70%, 50% 90%, 50% 90%, 0 70%, 0 0);
}
img {
max-width: 100%;
width: 100%;
}
<div class="clipped">
<img src="https://loremflickr.com/1280/720">
</div>
Add triangle to top of div with background image in CSS
Could achieve your design using another div. Hope you'll like it :)
.bg {
position: relative;
background: url('http://i.imgur.com/W27LCzB.jpg');
background-size: cover;
width: 100%;
padding-top: 50px;
height: 200px;
}
.bg:before {
content:'';
border-left: 50px solid #fff;
border-right: 50px solid #fff;
border-bottom: 50px solid transparent;
position:absolute;
top: 0;
left: 0;
right: 0;
margin: 0 auto;
width: 0;
}
.helper {
position: absolute;
height: 50px;
top: 0;
left: 0;
right: 0;
}
.helper:before, .helper:after {
content: "";
background: white;
position: absolute;
top: 0;
bottom: 0;
width: calc(50% - 50px);
}
.helper:before {left: 0;}
.helper:after {right: 0;}
<div class="bg">
<div class="helper"></div>
</div>
Triangle bottom CSS with background
I think clip-path
would be best in this situation. See fiddle
background-image: url('image.jpg');
-webkit-clip-path: polygon(0 0, 100% 0, 100% 80%, 50% 100%, 0 80%);
clip-path: polygon(0 0, 100% 0, 100% 80%, 50% 100%, 0 80%);
Make a CSS triangle with transparent background on a div with white bg image?
The Fiddle:
http://jsfiddle.net/JaMH9/2/
The HTML:
<div class="bar">
<span class="home">^<br>Home, sweet home!</span>
</div>
The CSS:
.bar {
position: relative;
width: 90%;
height: 30px;
margin: 0 auto;
}
.home {
position: absolute;
top: 0px;
left: 60%;
width: 20%;
text-align: center;
}
.bar:before, .bar:after {
content:'';
position: absolute;
top: 0;
height: 0;
border-top: 30px solid white;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
.bar:before {
left: 0;
width: 70%;
border-right: 30px solid transparent;
}
.bar:after {
right:0;
width: 30%;
border-left: 30px solid transparent;
}
Putting an image background onto a CSS Triangle
A triangle in CSS is a hack, created by displaying parts of the border of an element. Therefore, the triangle that you see is not an element itself, but a CSS border.
The border cannot be styled using the normal CSS background-image
style, and this is where you start seeing the limitations of CSS triangles, and why it really is a hack rather than a good technique.
There is a CSS solution that may work for you: border-image
.
border-image
is a CSS style that does what you'd expect; it puts an image into the border of an element. Since the CSS triangle is a border, you could use it to put a background image onto your triangle.
However, things do get complicated. The border-image
style is designed to style borders, not triangles; it has features for styling corners and sides, and stretching images appropriately. I haven't tried it with a triangle, but I can predict that it may have some quirks that make it tricky to use. But feel free to give it a go.
The other problem with border-image
is browser support. It's a relatively new CSS style, and is completely unsupported in many current browsers, including all versions of IE. You can see the full browser support table for it at CanIUse.
Because of all these issues, I would suggest that if you want to draw shapes in the browser, you really should consider dropping CSS hacks, and using SVG or Canvas. These are well supported in most browsers, and obviously support all the drawing features you could possibly want.
CSS triangles are great for making the occasional arrow shape, but for anything more complex than that it's a lot easier to use proper graphics rather than trying to pile more and more hacks into your CSS code.
div with css triangle in the background
Try use the Cross browser tecnique of triangle shape.
It is cross browser and not give pixelate effect.
Here is a working demo.
Cascading divs with triangles pointing downwards
This seems a perfect job for clip-path
:
.container {
padding:20px;
background:#dce2cc;
}
.box {
height:200px;
clip-path: polygon(0 0, calc(70% - 30px) 0, 70% 15%, calc(70% + 30px) 0, 100% 0, 100% 85%, calc(70% + 30px) 85%, 70% 100%, calc(70% - 30px) 85%, 0 85%);
background-color:red;
background-size:cover;
background-position:center;
}
.box:first-child {
clip-path: polygon(0 0, 100% 0, 100% 85%, calc(70% + 30px) 85%, 70% 100%, calc(70% - 30px) 85%, 0 85%);
}
.box:last-child {
clip-path: polygon(0 0, calc(70% - 30px) 0, 70% 15%, calc(70% + 30px) 0, 100% 0, 100% 100%,0 100%);
}
.box:not(:first-child) {
margin-top:-10px;
}
<div class="container">
<div class="box" style="background-image:url(https://picsum.photos/500/500?image=0)"></div>
<div class="box" style="background-image:url(https://picsum.photos/500/500?image=1069)"></div>
<div class="box" style="background-image:url(https://picsum.photos/500/500?image=1072)"></div>
<div class="box" style="background-image:url(https://picsum.photos/500/500?image=1052)"></div>
</div>
Related Topics
Apply CSS Style on All Elements Except with a Specific Id
Rounded Corners in Outlook Without Images
How to Achieve Curved Top Pointer
Table with Fixed Header at Top
Header/Footer Layout with 100% Content Height in IE8
Set Margin/Padding for Each Page to Print (Html/Css)
CSS White-Space: Pre Not Working as Expected
Animating with Variables Angular 4
Stray Vertical Line Above 965 Pixels with Border Radius in Safari
It Is Possible to Expand a Textarea Only with CSS
Setting the Granularity of the HTML5 Audio Event 'Timeupdate'
What's the Difference Between HTML's and CSS's Width Attribute
CSS Wrong Appearance of Border-Radius on a Nested Div
How to Center Div Vertically Inside of Absolutely Positioned Parent Div
CSS Table Td Width - Fixed, Not Flexible
Fixed Positioned Header Persists on Desktop But Not on Mobile