I am trying to create a div with a background image (background-size:cover) with this shape cut out in the center top of the div.
The div above the div I want to cut this shape out of has background-image:cover on it as well. I'm trying to do this with a CSS shape, moving the lower div up using a negative margin top, so the background image on the div above shows through the cut out shape.
Note: The shape has to look identical or almost identical to the image, as it is part of a site designed by someone else, and they are very specific with their designs.
Anyone out there know how to create this shape?
EDIT: #SZenC offered a really cool solution that I implemented, except it leaves me with colored shapes overlayed on top of background images. See image:
I need the light blue pattern to show through where the gray is, and the purple texture to show through where the white is. I'm not sure at this point if this is possible, at least with CSS.
The best solution using CSS would be to use some nested elements.
You could create a div (.pointy) with two other divs inside it (.curve-left & .curve-right).
The inner divs should be sided so that they each have half of the curve. So if your curve drops 10px and goes 20px horizontal, it's height should be 10px and the width 20px. Then give it a border radius in the top-left or top-right corner of 100%. Now the curve will go trough the entire div. You could then give it a gray background-color and the parent div white in the background. Then some simple CSS-tricks to center the .pointy-div and do the backgrounds, and voila, there is your curvy triangle-y thingy.
So example below.
#c1 {
position: relative;
width: 200px;
height: 190px;
overflow: hidden;
}
#c2 {
position: relative;
top: 0px;
width: 200px;
height: 200px;
background-color: gray;
}
.pointy {
position: absolute;
top: 0px;
left: 50%;
margin-left: -20px;
width: 40px;
height: 10px;
background-image: url("http://lorempixel.com/output/technics-q-c-200-200-4.jpg");
background-position:center bottom;
}
.pointy>.curve-left,
.pointy>.curve-right{
position:absolute;
background-color:red;
width:20px;
height:10px;
background-image:url("http://lorempixel.com/output/technics-q-c-200-200-1.jpg");
}
.pointy>.curve-left{
border-top-right-radius:100%;
background-position:120px 0;
left:0;
}
.pointy>.curve-right{
border-top-left-radius:100%;
background-position:80px 0;
right:0;
}
<div id="c1">
<img src="http://lorempixel.com/output/technics-q-c-200-200-4.jpg" />
</div>
<div id="c2">
<div class="pointy">
<div class="curve-left"></div>
<div class="curve-right"></div>
</div>
<img src="http://lorempixel.com/output/technics-q-c-200-200-1.jpg" />
</div>
Here you could use a couple of pseudo elements with border radius to create that curved shape.
note there are multiple elements in this demo to show how this could be used in practice
.image {
height: 300px;
width: 80%;
background: url(http://lorempixel.com/900/500);
position: relative;
display: inline-block;
}
.shape {
position: absolute;
bottom: 0;
width: 100%;
height: 30px;
background: url(http://lorempixel.com/900/400);
background-position: 0 60px;
}
.shape:before,
.shape:after {
content: "";
position: absolute;
background: inherit;
height: 100%;
top: 0;
width: 50%;
transform: translateY(-100%);
}
.shape:before {
left: 0;
border-radius: 0 50% 0 0;
background-position: 0 90px;
}
.shape:after {
left: 50%;
border-radius: 50% 0 0 0;
background-position: -100% 90px;
}
<div class="image">
<div class="shape"></div>
</div>
Another, more in practical approach (with responsiveness), would be something like:
.wrap{
width:100%;display:inline-block;
position:relative;
height:600px;
}
.wrap img:first-child{
top:0;z-index:5;
}
.wrap img:last-child{
top:40%;
}
.wrap img{
position:absolute;
height:50%;width:100%;
}
.wrap .splitter{
z-index:10;
position:absolute;
top:40%; width:100%;
height:10%;
}
.wrap .splitter:before, .wrap .splitter:after{
content:"";
position:absolute;
width:50%;
height:100%;
background-size:200% 500%;
border-radius: 0 100% 0 0;
}
.wrap .splitter:after{
left:50%;
background-position:-100% 0;
border-radius: 100% 0 0 0;
}
.wrap .partA:before, .wrap .partA:after{ background-image:url("http://lorempixel.com/450/250");}
<div class="wrap">
<img src="http://lorempixel.com/900/500"/>
<span class="splitter partA"></span>
<img src="http://lorempixel.com/450/250"/>
</div>
Related
As you can see, in the title block, only the upper half has background, I want the whole title block to have the same background. Of course, I can set background for the title block itself, but this way the background won't look continuous, as you can see in the fiddle.
Is there a way to achieve this with pure css?
.header {
width: 100%;
padding-top: 30%;
background: url('https://cchc-herald.org/images/discuss_cavatar/titleSampleBG.jpg') no-repeat 50% 50%;
background-size: cover;
position: relative;
}
.title {
position: absolute;
transform: translateY(-50%);
padding: 8px 24px;
font-size: 24px;
background: none;
border-radius: 50px;
border: 4px solid white;
left: 10%
}
body {
background-color: #eee
}
.title.b {
background: url('https://cchc-herald.org/images/discuss_cavatar/titleSampleBG.jpg') no-repeat 50% 50%;
background-size: contain
}
<div class="header">
<div class="title"> Title Title </div>
</div>
<div class="header" style="margin-top:60px">
<div class="title b">
Title Title
</div>
</div>
Fiddle: https://jsfiddle.net/s7pkr2w8/1/
Here is an idea using clipping and masking
.header {
padding-top: 30%;
position: relative; /* relative here !! **/
display:flex;
z-index:0;
}
.title {
font-size: 24px;
color:#fff;
border-radius: 50px;
margin:auto auto 0 10%; /* position the element using flexbox instead of absolute */
-webkit-mask:linear-gradient(#fff 0 0); /* clip the pseudo element to only the title shape*/
}
/* extra div needed for the white border*/
.title > div {
padding: 8px 24px;
border:4px solid #fff;
position:relative;
border-radius: inherit;
}
/**/
/* two pseudo element relative to the container having the same background
to have the continuous effect
*/
.title::before,
.header::before{
content:"";
position:absolute;
z-index:-1;
top:0;
bottom:0;
left:0;
right:0;
background: url('https://cchc-herald.org/images/discuss_cavatar/titleSampleBG.jpg') no-repeat 50% 50%/cover;
}
.header::before {
clip-path:inset(0 0 20px 0); /* cut 20px from the bottom to be around the middle of the title */
}
body{
background-color:#eee
}
<div class="header">
<div class="title">
<div>Title Title</div>
</div>
</div>
you can try to set the background on a parent element or just event to the whole body:
body{
background:url('https://cchc-herald.org/images/discuss_cavatar/titleSampleBG.jpg') no-repeat 50% 50%;
background-size:cover;
}
I Designed a measurement card where the profile image is cutted out by an half elips, i tried several methos (svg mask, svg clipping), but all these methods didn't work. Specially on Safari.
Does anyone has an idea how to realize this layout?
Here is the SVG Half Circle if it helps ya
SVG CIRCLE
You can use the border radius to achieve this layout:
If you want an elliptic shape you have to oversize the clipping element and place the image offsetted inside it:
document.getElementById('button1').addEventListener('click', function(){
document.getElementById('profile').classList.toggle('view');
});
.profile{
background: #1111cc;
width:300px;
height:100px;
position:relative;
overflow:hidden;
margin: 20px;
}
.clip{
position:absolute;
background: red;
width: 100px;
height:130px;
top: -15px;
border-top-right-radius: 50px 65px;
border-bottom-right-radius: 50px 65px;
overflow:hidden;
}
.img{
position: absolute;
top: 15px;
background: rgba(100,100,100,0.8);
width:100px;
height:100px;
}
.name{
position: absolute;
bottom: 15px;
margin: 0;
padding: 0 10px 0 0;
background: rgba(255, 255, 255, 0.8);
box-sizing: border-box;
width: 100px;
}
.profile.view .clip{
overflow: initial;
}
.profile.view{
overflow: initial;
}
<div id="profile" class="profile">
<div class="clip">
<img class="img" src="https://i.stack.imgur.com/oiszU.png">
<p class="name">My name is too long for this world..</p>
</div>
</div>
<button id="button1">view all shapes</button>
I know html and css very well , i'm looking for something like this with css not with images ?
is there any trick that can do this with Css ?
HTML
<div id="zone-user-wrapper" class="zone-wrapper"></div>
CSS
.zone-wrapper{
background: none repeat scroll 0 0 #01b888;
height:150px;
}
i made a fiddle
Thx
You can try something like this:
Fiddle
HTML:
<div class="zone-wrapper"></div>
<div id="shape"></div>
CSS:
.zone-wrapper{
background: none repeat scroll 0 0 #01b888;
height:150px;
}
#shape {
height: 20px;
background-color: white;
border-top-left-radius: 5000px 300px;
border-top-right-radius: 5000px 300px;
top: -20px;
position: relative;
}
<------------------------------------------------------------ Edit ------------------------------------------------------------->
Replicating the one on this website as you requested.
Here, I've added the border-top-left-radius: 4000px 150px and border-top-right-radius: 4000px 150px; to .content and .seperator. Then, gave appropriate z-index to all elements. .content has the highest z-index value, .zone-wrapper has the lowest z-index value and .seperator is in the middle.
<--------------------[ Fiddle | Full Screen Demo | With the Image from your website ]-------------------->
HTML:
<div class="zone-wrapper"></div>
<div class="seperator"></div>
<div class="content"></div>
CSS:
body {
margin: 0 0;
}
.zone-wrapper{
background: url(http://s25.postimg.org/4lur4kk23/pattern.png) repeat scroll 0 0 #01b888;
height:180px;
z-index: 0;
}
.seperator {
height: 50px;
background-color: #00533D;
border-top-left-radius: 4000px 150px;
border-top-right-radius: 4000px 150px;
top: -47px;
width: 100%;
position: relative;
z-index: 1;
}
.content {
top: -90px;
position: relative;
height: 800px;
background-color: #93fbdf;
border-top-left-radius: 4000px 150px;
border-top-right-radius: 4000px 150px;
z-index: 2;
}
The Flexible Option with a single HTML element
I have focused on creating the shape with a:
single HTML element — <header></header>
flexible percentage units
The CSS
The :before and :after pseudo elements overlap to create the curve
The pseudo elements are given 100% width and will expand and retract
The box shadow helps smooth out the jagged curve and the textured background image distracts the eyes from the remaining jagged pixels
The left: -20px and padding-right: 20px hide the rounded corner and are cut-off with overflow: hidden
Image Attribution: The background image used in the example below is obtained from transparenttextures.com and was created by Atle Mo.
The Example
Open full-screen and watch it re-size.
body {
margin: 0;
}
header {
background: url(http://i.stack.imgur.com/TIgas.png);
height: 80px;
position: relative;
overflow: hidden;
}
header:after,
header:before {
content: '';
display: block;
background: #FFF;
height: 60%;
width: 100%;
position: absolute;
border-radius: 100% 100% 0 0;
top: 50%;
left: -20px;
padding: 0 20px;
box-shadow: inset 0 0 2px #333;
}
header:before {
background: #333;
margin-top: -5px;
}
<header></header>
.zone-wrapper{
background: none repeat scroll 0 0 #01b888;
height:150px;
border-radius: 40px 40px 40px 40px;
overflow:hidden;
}
.zone-wrapper2{
margin-top:10px;
display:inlin-block;
background: black;
height:130px;
border-radius: 40px 40px 40px 40px;
}
<div id="zone-user-wrapper" class="zone-wrapper">
<div id="div2" class="zone-wrapper2">
</div>
</div>
The trick is to have 2 divs. The first could be your actual header and another just beneath it having a border-radius property. So your whole header could be a wrapper around the 2.
Did some tinkering to the html of your code.
Added a div in the main header wrapper.
Check the image below:
Hope it is of help.
You can use something like this from (https://stackoverflow.com/a/4777943/3905567):
<div id="header">
<div id="cover-left"></div>
<div id="cover-right"></div>
</div>
http://jsfiddle.net/p2hH7/215/
Hello I want to achieve similar to this image.
Here is my css code
*{
background:#444;
margin:0;
padding:0;
}
.display{
width:100%;
min-height:100%;
background:green;
position:fixed;
}
.one{
width:100%;
height:300px;
margin-top:-200px;
background:red;
transform: rotate(45deg);
}
.two{
width:100%;
height:450px;
margin-top:200px;
background:blue;
transform: rotate(45deg);
}
I've try to achieve similar positioning here is my Code is here
My question is - What could you suggest me to achieve similar positioning?
Is it good to use transform for 4 div images and positioning them?
Assuming this is a background, let's simplify it with a single HTML element.
Top and bottom background colors are a single gradient with two colors
left and right background colors are :before and :after pseudo elements rotated with transform: rotate
The before and after pseudo elements get z-index: 1. Elements that should be above them get position: relative and z-index: 2
Example
body {
background: #212121;
}
div {
background: #F00;
height: 500px;
width: 500px;
position: relative;
overflow: hidden;
background: linear-gradient(to bottom, #EB1249 0%, #EB1249 50%, #251F39 50%, #251F39 100%);
margin: 0 auto;
}
div:before {
content: '';
display: block;
position: absolute;
top: 0;
left: -70%;
transform: rotate(45deg);
background: #fce4ec;
width: 100%;
height: 100%;
z-index: 1;
}
div:after {
content: '';
display: block;
position: absolute;
top: 0;
right: -59.3%;
transform: rotate(45deg);
background: #F5B8A2;
width: 90%;
height: 100%;
z-index: 1;
}
<div></div>
This is pretty easy if you set the transform-origin to the corners of your boxes. Basically, instead of rotating from the middle, you can rotate from the corner. So You'd have two boxes at, for instance:
right : 200px;
bottom : 200px;
transform-origin : 100% 100%;
one rotated 45deg, the other -45deg. Then the other two at 190, 210 or whatever. Note that you also need -webkit-transform-origin, -ms-transform-origin, -moz-transform-origin, -o-transform-origin
I would like to create something like on attached image using only CSS. Until now I have come-up with:
.block5-header:after {
content:"";
position:absolute;
top:0;
left:0;
bottom:0;
right:0;
width:100%;
background: url({template_relativeimagepath}{template_imagesfolder}blocks/elipsa.png) no-repeat;
background-size: contain;
}
But this solution requires to use a lot of different png images, as i have many different sizes of header blocks. I have tried to use pseudo elements with radial gradients, but to no avail. If there is some simpler solution please let me know ;)
Pic of what i would like to achieve. http://i.imgur.com/pwN54o1.png
Alright, I used css position, circles, and rgba.
Pure CSS Solution (Fixed width)
It is also responsive to width changes
HTML
<header class="subNav">
<span class="headCirc"></span>
Something
</header>
CSS
.subNav {
width: 285px;
height: 60px;
overflow: hidden;
background: #4679bd;
display: block;
position: relative;
left: 30px;
top: 30px;
line-height: 60px;
font-size: 20px;
color: #fff;
padding-left: 15px;
border-radius: 10px 10px 0 0;
}
.headCirc {
position: absolute;
top: -30px;
left: -5%;
display: block;
width: 110%;
height: 70px;
background: rgba(255, 255, 255, 0.2);
border-radius: 50%;
}
What I did was positioned the circle absolutely inside of the header, I then gave the header an overflow: hidden to hide anything of the circle that came out of the box.
You wont be able to get the curved line but if you don't mind that you can try out http://www.colorzilla.com/gradient-editor/