I want to cut image corners with transperant background. I have written following code.
body{
background-image:url('http://i.telegraph.co.uk/multimedia/archive/03589/Wellcome_Image_Awa_3589699k.jpg');
}
.Image{
position:absolute;
width:200px;
height:200px;
}
.Image img{
width:100%;
height:100%;
}
.Image:before {
position: absolute;
content: "";
border-top: 60px solid red;
border-right: 60px solid transparent;
top: -1px;
left: -1px;
}
.Image:after {
position: absolute;
content: "";
border-bottom: 60px solid red;
border-left: 60px solid transparent;
bottom: -1px;
right: -1px;
}
.blackBg{
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
background:rgba(0,0,0,0.6);
}
<div class="blackBg"></div>
<div class="Image">
<img src="http://www.w3schools.com/css/img_fjords.jpg">
</div>
How can I cut image corners using css, also I don't want to use canvas or svg for this. I'd like to do it in pure CSS, are there any methods?
I want shape like this.
Removed your before and after pseudo part and added clip-path styling.
body{
background-image:url('http://i.telegraph.co.uk/multimedia/archive/03589/Wellcome_Image_Awa_3589699k.jpg');
}
.Image{
position:absolute;
width:200px;
height:200px;
}
.Image img{
width:100%;
height:100%;
-webkit-clip-path: polygon(20% 0%, 80% 0%, 100% 0%, 100% 80%, 80% 100%, 0% 100%, 0% 86%, 0% 20%);
clip-path: polygon(20% 0%, 80% 0%, 100% 0%, 100% 80%, 80% 100%, 0% 100%, 0% 86%, 0% 20%);
}
}
.blackBg{
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
background:rgba(0,0,0,0.6);
}
<div class="blackBg"></div>
<div class="Image">
<img src="http://www.w3schools.com/css/img_fjords.jpg">
</div>
Rotate the container 45 deg to the right,
set overflow hidden on it.
and make the height bigger so that it won't clip the undesired corners.
Rotate the image -45deg so that it is horizontal again.
And you are done:
body {
background-image: url('http://i.telegraph.co.uk/multimedia/archive/03589/Wellcome_Image_Awa_3589699k.jpg');
}
.Image {
position: absolute;
width: 200px;
height: 400px;
transform: rotate(45deg);
overflow: hidden;
margin-top: -100px;
}
.Image img {
width: 100%;
height: 50%;
margin-top: 100px;
transform: rotate(-45deg);
}
.blackBg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
}
<div class="blackBg"></div>
<div class="Image">
<img src="http://www.w3schools.com/css/img_fjords.jpg">
</div>
You will (hopefully) soon be able to use border-corner-shape
like this (now rounded corners may appear as fallback) and no need to use pseudo elements
body{
background:green;
}
.Image{
position:absolute;
width:200px;
height:200px;
}
.Image img{
width:100%;
height:100%;
border-corner-shape: bevel;
border-radius:30px 0 30px 0;
}
.blackBg{
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
background:rgba(0,0,0,0.6);
}
<div class="blackBg"></div>
<div class="Image">
<img src="http://www.w3schools.com/css/img_fjords.jpg">
</div>
You can achive desire result through adding extra element or through css pseudo elements :before & :after
body{background:#fff;}
.img-ctnr{position:relative;}
.img{width:450px;height:300px;background:purple;}
.img-ctnr:before,.img-ctnr:after{
content:'';position:absolute;display:block;
width:100px;height:100px;
background:#fff;
transform:rotate(45deg);
}
.img-ctnr:before{top:-50px;left:-50px;}
.img-ctnr:after{top:250px;left:400px;}
<div class="img-ctnr">
<div class="img"></div>
</div>
Just do this in your css:
background: linear-gradient(135deg,rgb(72, 72, 245) 95% , rgba(255, 255, 255, 0) 5%) ;
Related
I'm having some problems I'm trying to have two clip path polygons overlap each other when hovered over by the mouse, I'm using z-index's and trying to change them depending on with overlay is being hovered over but I can't seem to get it to work. I've tried changing the z-index when the object is hovered over but that doesn't seem to change anything.
.banner {
position:relative;
bottom 0;
top: 0;
left:0;
right: 0;
width: 100%;
height: 700px;
}
.overlayleft {
position:absolute;
z-index:1;
bottom 0;
top: 0;
left:0;
right: 0;
width: 50%;
height: 100%;
overflow:hidden;
clip-path: polygon(0 0, 75% 0, 100% 100%, 0% 100%);
background: rgba(0,0,0,1);
transition: .5s ease;
}
.overlayright {
position:absolute;
z-index:2;
bottom: 0;
top 0;
left: 50%;
right: 0;
width: 50%;
height: 100%;
overflow:hidden;
clip-path: polygon(0 0, 100% 0, 100% 100%, 25% 100%);
background: rgba(0,0,0,0.6);
transition: .5s ease;
}
.overlayleft:hover{
z-index: 4;
width: 100%;
}
.overlayright:hover{
z-index: 4;
width: 100%;
left: 0;
}
<!DOCTYPE html>
<html>
<body>
<div class="banner">
<div class="overlayright"></div>
<div class="overlayleft"></div>
</div>
</body>
</html>
Its because of this "background: rgba(0,0,0,0.6);"
Its color with opacity, if you change the color to something else, lets say red color, you will see the difference.
Basically left div is black, and the second div is gray, when gray one is hovered its not visible that it is hovering the left one because of its opacity...
How to divide circle into 2 parts, which can be rgb or url image? which looks like
so I wrote code which works just with rgb, but I don't know how it can be with url image... please help me:
.divided-circle {
width: 25px;
height: 25px;
background: linear-gradient( 135deg, #26A0DA 50%, #d92550 50%);
border-radius: 50%;
border: 0.5px solid #9b9b9b;
margin-right: 5px;
}
<div>
<div class="divided-circle"></div>
</div>
you can try like below:
.box {
width:150px;
border-radius:50%;
background:red; /* first background */
position:relative;
overflow:hidden;
}
.box::before {
content:"";
display:block;
padding-top:100%;
background:url(https://picsum.photos/id/1074/800/800) center/cover; /* second background */
/* adjust the below angle to control the rotation */
-webkit-mask:linear-gradient(60deg,#fff 49.8%,transparent 50%);
mask:linear-gradient(60deg,#fff 49.8%,transparent 50%);
}
<div class="box"></div>
With CSS variables to easily control:
.box {
--a:65deg; /* angle of rotation */
/* first background */
--b1:red;
/* second background */
--b2:url(https://picsum.photos/id/1074/800/800) center/cover;
width:150px;
display:inline-block;
border-radius:50%;
background:var(--b1);
position:relative;
overflow:hidden;
}
.box::before {
content:"";
display:block;
padding-top:100%;
background:var(--b2);
-webkit-mask:linear-gradient(var(--a),#fff 49.8%,transparent 50%);
mask:linear-gradient(var(--a),#fff 49.8%,transparent 50%);
}
<div class="box"></div>
<div class="box" style="--b1:blue;--b2:linear-gradient(red,yellow);--a:135deg;"></div>
<div class="box" style="--b1:url(https://picsum.photos/id/1014/800/800?grayscale) center/cover;--b2:url(https://picsum.photos/id/1014/800/800) center/cover;--a:180deg;"></div>
You can use clip-path for this:
.overlap1 {
position: absolute;
clip-path: polygon(0 0, 0% 100%, 100% 0);
}
.overlap2 {
position: absolute;
clip-path: polygon(100% 100%, 0% 100%, 100% 0);
}
<img class="overlap1" src="https://i.ya-webdesign.com/images/avatar-png-1.png"/>
<img class="overlap2" src="https://cdn.iconscout.com/icon/free/png-512/avatar-369-456321.png"/>
More on clip-path here.
You can border-radius this way, and inside the divs you can image or text ...
.divided-circle{
width: 150px;
height: 150px;
margin-right: 5px;
display: flex;
transform: rotate(45deg);
}
.divided-circle .left {
width: 50%;
height: 100%;
border-radius: 100% 0% 0% 100% / 50% 50% 50% 50%;
background: #cdcdcd;
border: 0.5px solid #9b9b9b;
border-right: none;
}
.divided-circle .right {
width: 50%;
height: 100%;
background: #212121;
border-radius: 0% 100% 100% 0% / 50% 50% 50% 50%;
border: 0.5px solid #9b9b9b;
border-left: none;
}
<div>
<div class="divided-circle">
<div class="left"></div>
<div class="right"></div>
</div>
</div>
I have a circle progress bar, only with HTML and CSS, I used keyframes for loading (animation). But the loading is from right to left I wanna reverse it. I edit my CSS keyframes but nothing at all. I try also animation reverse again nothing.
Fiddle:
https://jsfiddle.net/d20wu8e4/
My Result (image):
https://ibb.co/0KCSsZY
What I want:
https://ibb.co/MGCpHqS
* {
box-sizing:border-box;
}
.progress {
width: 150px;
height: 150px;
background: none;
margin: 0 auto;
box-shadow: none;
position: relative;
}
.progress:after {
content: "";
width: 100%;
height: 100%;
border-radius: 50%;
border: 3px solid #fff;
position: absolute;
top: 0;
left: 0;
opacity: 0.5;
}
.progress>span {
width: 50%;
height: 100%;
overflow: hidden;
position: absolute;
top: 0;
z-index: 1;
}
.progress .progress-left {
left: 0;
}
.progress .progress-bar {
width: 100%;
height: 100%;
background: none;
border-width: 2px;
border-style: solid;
position: absolute;
top: 0;
}
.progress .progress-left .progress-bar {
left: 100%;
border-top-right-radius: 80px;
border-bottom-right-radius: 80px;
border-left: 0;
-webkit-transform-origin: center left;
transform-origin: center left;
}
.progress .progress-right {
right: 0;
}
.progress .progress-right .progress-bar {
left: -100%;
border-top-left-radius: 80px;
border-bottom-left-radius: 80px;
border-right: 0;
-webkit-transform-origin: center right;
transform-origin: center right;
animation: loading 1.8s linear forwards;
}
.progress .progress-value {
width: 79%;
height: 79%;
border-radius: 50%;
background: none;
font-size: 24px;
color: black;
line-height: 135px;
text-align: center;
position: absolute;
top: 5%;
left: 5%;
}
.progress.one .progress-bar {
border-color: black;
}
.progress.one .progress-left .progress-bar {
animation: loading-1 1s linear forwards 1.8s;
}
#keyframes loading {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(180deg);
transform: rotate(180deg);
}
}
#keyframes loading-1 {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
}
}
<div class="container bg-danger">
<div class="row mt-5">
<div class="progress one">
<span class="progress-left">
<span class="progress-bar"></span>
</span>
<span class="progress-right ">
<span class="progress-bar"></span>
</span>
<div class="progress-value">73%</div>
</div>
</div>
</div>
As I commented, the trivial solution is to rotate the whole animation:
* {
box-sizing:border-box;
}
.progress {
width: 150px;
height: 150px;
background: none;
margin: 0 auto;
box-shadow: none;
position: relative;
transform: scaleX(-1);
}
.progress-value {
transform: scaleX(-1);
}
.progress:after {
content: "";
width: 100%;
height: 100%;
border-radius: 50%;
border: 3px solid #fff;
position: absolute;
top: 0;
left: 0;
opacity: 0.5;
}
.progress>span {
width: 50%;
height: 100%;
overflow: hidden;
position: absolute;
top: 0;
z-index: 1;
}
.progress .progress-left {
left: 0;
}
.progress .progress-bar {
width: 100%;
height: 100%;
background: none;
border-width: 2px;
border-style: solid;
position: absolute;
top: 0;
}
.progress .progress-left .progress-bar {
left: 100%;
border-top-right-radius: 80px;
border-bottom-right-radius: 80px;
border-left: 0;
-webkit-transform-origin: center left;
transform-origin: center left;
}
.progress .progress-right {
right: 0;
}
.progress .progress-right .progress-bar {
left: -100%;
border-top-left-radius: 80px;
border-bottom-left-radius: 80px;
border-right: 0;
-webkit-transform-origin: center right;
transform-origin: center right;
animation: loading 1.8s linear forwards;
}
.progress .progress-value {
width: 79%;
height: 79%;
border-radius: 50%;
background: none;
font-size: 24px;
color: black;
line-height: 135px;
text-align: center;
position: absolute;
top: 5%;
left: 5%;
}
.progress.one .progress-bar {
border-color: black;
}
.progress.one .progress-left .progress-bar {
animation: loading-1 1s linear forwards 1.8s;
}
#keyframes loading {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(180deg);
transform: rotate(180deg);
}
}
#keyframes loading-1 {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
}
}
<div class="progress one">
<span class="progress-left">
<span class="progress-bar"></span>
</span>
<span class="progress-right ">
<span class="progress-bar"></span>
</span>
<div class="progress-value">73%</div>
</div>
By the way here is another idea that rely on less code. The trick is to consider clip-path where you will adjust the position of the different points in order to create the needed animation
.box {
width:150px;
height:150px;
margin:20px;
box-sizing:border-box;
font-size:30px;
display:flex;
align-items:center;
justify-content:center;
position:relative;
z-index:0;
}
.box:before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
border:5px solid #000;
border-radius:50%;
transform:rotate(45deg);
clip-path:polygon(50% 50%,0 0,0 0,0 0, 0 0,0 0);
animation:change 2s linear forwards;
}
#keyframes change {
25% {
clip-path:polygon(50% 50%,0 0, 0 100%,0 100%,0 100%,0 100%);
}
50% {
clip-path:polygon(50% 50%,0 0,0 100%, 100% 100%, 100% 100%,100% 100%);
}
75% {
clip-path:polygon(50% 50%,0 0,0 100%,100% 100%, 100% 0,100% 0);
}
100% {
clip-path:polygon(50% 50%,0 0,0 100%,100% 100%, 100% 0, 0% 0%);
}
}
body {
background:pink;
}
<div class="box">
73%
</div>
To better understand the animation, add background and remove the radius. We basically have 6 points in the polygon where 2 are fixed (the center (50% 50%) and top one (0 0)) then we move the 4 others to put them in the corners. The trick is to move them together and we leave one at each corner (each state of the animation).
.box {
width:100px;
height:100px;
margin:50px;
box-sizing:border-box;
font-size:30px;
display:flex;
align-items:center;
justify-content:center;
position:relative;
z-index:0;
background:rgba(0,0,0,0.5);
}
.box:before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
border:5px solid #000;
background:red;
transform:rotate(45deg);
clip-path:polygon(50% 50%,0 0,0 0,0 0, 0 0,0 0);
animation:change 5s linear forwards;
}
#keyframes change {
25% {
clip-path:polygon(50% 50%,0 0, 0 100%,0 100%,0 100%,0 100%);
}
50% {
clip-path:polygon(50% 50%,0 0,0 100%, 100% 100%, 100% 100%,100% 100%);
}
75% {
clip-path:polygon(50% 50%,0 0,0 100%,100% 100%, 100% 0,100% 0);
}
100% {
clip-path:polygon(50% 50%,0 0,0 100%,100% 100%, 100% 0, 0% 0%);
}
}
body {
background:pink;
}
<div class="box">
73%
</div>
With this code you have the full animation, simply adjust the final state or remove some states to stop it where you want.
Ex with 75% (we remove the last state)
.box {
width:150px;
height:150px;
margin:20px;
box-sizing:border-box;
font-size:30px;
display:flex;
align-items:center;
justify-content:center;
position:relative;
z-index:0;
}
.box:before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
border:5px solid #000;
border-radius:50%;
transform:rotate(45deg);
clip-path:polygon(50% 50%,0 0,0 0,0 0, 0 0,0 0);
animation:change 3s linear forwards;
}
#keyframes change {
33% {
clip-path:polygon(50% 50%,0 0, 0 100%,0 100%,0 100%,0 100%);
}
66% {
clip-path:polygon(50% 50%,0 0,0 100%, 100% 100%, 100% 100%,100% 100%);
}
100% {
clip-path:polygon(50% 50%,0 0,0 100%,100% 100%, 100% 0,100% 0);
}
}
body {
background:pink;
}
<div class="box">
75%
</div>
With 66% (we remove the last state and we change the percentage of the third one)
.box {
width:150px;
height:150px;
margin:20px;
box-sizing:border-box;
font-size:30px;
display:flex;
align-items:center;
justify-content:center;
position:relative;
}
.box:before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
border:5px solid #000;
border-radius:50%;
transform:rotate(45deg);
clip-path:polygon(50% 50%,0 0,0 0,0 0, 0 0,0 0);
animation:change 2s linear forwards;
}
#keyframes change {
33% {
clip-path:polygon(50% 50%,0 0, 0 100%,0 100%,0 100%,0 100%);
}
66% {
clip-path:polygon(50% 50%,0 0,0 100%, 100% 100%, 100% 100%,100% 100%);
}
100% {
clip-path:polygon(50% 50%,0 0,0 100%,100% 100%, 100% 0,100% 40%);
}
}
<div class="box">
75%
</div>
with 10% (only one state)
.box {
width:150px;
height:150px;
margin:20px;
box-sizing:border-box;
font-size:30px;
display:flex;
align-items:center;
justify-content:center;
position:relative;
}
.box:before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
border:5px solid #000;
border-radius:50%;
transform:rotate(45deg);
clip-path:polygon(50% 50%,0 0,0 0,0 0, 0 0,0 0);
animation:change 1s linear forwards;
}
#keyframes change {
100% {
clip-path:polygon(50% 50%,0 0, 0 40%,0 40%,0 40%,0 40%);
}
}
body {
background:pink;
}
<div class="box">
10%
</div>
This progress works in new blink/webkit browsers since it uses conic-gradient(). In addition, to change the progress we use css variables, so animation will require JS.
The idea is to create a conic gradient of black to transparent, and change the degrees according to the progress. To get a line instead of a circle, I use an inner gradient from white to white, that doesn't cover the border (background-clip: content-box) as suggested by #TemaniAfif.
Play with the values of the input box to see the progress.
const progress = document.querySelector('.circular-progress')
const updateProgress = value => {
progress.style.setProperty('--percentage', `${value * 3.6}deg`)
progress.innerText = `${value}%`
}
updateProgress(36)
document.querySelector('input')
.addEventListener('input', e => {
updateProgress(e.currentTarget.value)
})
.circular-progress {
display: flex;
width: 150px;
height: 150px;
border:5px solid transparent;
border-radius: 50%;
align-items: center;
justify-content: center;
font-size: 1.5em;
background:
linear-gradient(#fff, #fff) content-box no-repeat,
conic-gradient(black var(--percentage,0), transparent var(--percentage,0)) border-box;
--percentage: 0deg;
}
<div class="circular-progress"></div>
<br />
Progress value: <input type="number" min="0" max="100" value="36">
And for the other direction (added by #TemaniAfif):
const progress = document.querySelector('.circular-progress')
const updateProgress = value => {
progress.style.setProperty('--percentage', `${value * 3.6}deg`)
progress.innerText = `${value}%`
}
updateProgress(36)
document.querySelector('input')
.addEventListener('input', e => {
updateProgress(e.currentTarget.value)
})
.circular-progress {
display: flex;
width: 150px;
height: 150px;
border:5px solid transparent;
border-radius: 50%;
align-items: center;
justify-content: center;
font-size: 1.5em;
background:
linear-gradient(#fff, #fff) content-box no-repeat,
conic-gradient(from calc(-1*var(--percentage)), black var(--percentage,0), transparent var(--percentage,0)) border-box;
--percentage: 0deg;
}
<div class="circular-progress"></div>
<br />
Progress value: <input type="number" min="0" max="100" value="36">
A variation on the same idea, is to create progress circle with multiple colors, and then hide it using a gradient from transparent to white. Make the transparent area bigger to expose the colored line.
const progress = document.querySelector('.circular-progress')
const updateProgress = value => {
progress.style.setProperty('--percentage', `${value * 3.6}deg`)
progress.innerText = `${value}%`
}
updateProgress(80)
document.querySelector('input')
.addEventListener('input', e => {
updateProgress(e.currentTarget.value)
})
.circular-progress {
display: flex;
width: 150px;
height: 150px;
border: 5px solid transparent;
border-radius: 50%;
align-items: center;
justify-content: center;
font-size: 1.5em;
background:
linear-gradient(#fff, #fff) content-box no-repeat,
conic-gradient(transparent var(--percentage, 0), white var(--percentage, 0)) border-box,
conic-gradient(green 120deg, yellow 120deg 240deg, red 240deg) border-box;
--percentage: 0deg;
}
<div class="circular-progress"></div>
<br /> Progress value: <input type="number" min="0" max="100" value="80">
I'm kind of new to CSS3 Animations and hope anybody out there could help me realising this.
I'm having a div with text in it. I would like to reveal this div from the center. It looks kind of simple, but until now I didn't find the perfect way to realise it.
Do I need to use
.text-div {
clip-path: inset(top right bottom left);
animate: revealText 3s;
}
#keyframes revealText {
0% {
clip-path: inset(top right bottom left);
},
100% {
clip-path: inset(top right bottom left);
}
}
or would you suggest another way to solve this?
Thanks for your help!
Cara
see here jsfiddle
i used : width:0% on the animation to hide the text , and added white-space:nowrap to initial state of the text so it doesn't go on two separate lines because of the width:0% and added overflow:hidden
play around with the css i gave you , remove some of the things to see how they work
css :
.text-div {
width:100%;
white-space:nowrap;
overflow:hidden;
animation: revealText 3s;
color:white;
text-align:center;
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
top:45%;
}
.content {
background:red;
height:200px;
width:200px;
position:relative;
}
#keyframes revealText {
0% {
width:0%;
}
100% {
width:100%;
}
}
EDIT you could use pseudo-elements like :before and :after , but this only if you have a background color underneath the text . like in this example red
see here : jsfiddle
css :
.text-div {
color:white;
text-align:center;
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
top:45%;
}
.text-div:before {
left:0;
}
.text-div:after {
right:0;
}
.text-div:after,.text-div:before {
position:absolute;
content:"";
height:100%;
width:50%;
background:red;
animation: revealText 3s;
}
.content {
background:red;
height:200px;
width:200px;
position:relative;
}
#keyframes revealText {
0% {
width:50%
}
100% {
width:0%
}
}
That's how I realised it in the end. It appears to me, that until now, there is no easier way to do this.
JSFiddle here
.text-div {
position: absolute;
top: 45%;
right: 0;
left: 0;
margin: 0 auto;
text-align: center;
color: white;
clip-path: inset(0px 50% 0px 50%);
-webkit-clip-path: inset(0px 50% 0px 50%);
animation: revealText 3s;
}
.content {
background:red;
height:200px;
width:200px;
position:relative;
}
#keyframes revealText {
0% {
clip-path: inset(0px 50% 0px 50%);
-webkit-clip-path: inset(0px 50% 0px 50%);
}
100% {
clip-path: inset(0px 0px 0px 0px);
-webkit-clip-path: inset(0px 0px 0px 0px);
}
}
Thanks everybody for input!
i want to seperate 2 floating div's with a slope line, they got different background colors.
Example here:
HTML markup:
<div id="wrap">
<div id="one"></div>
<div id="two"></div>
</div>
i allready tried to rotate them (as u can see in the jsFiddle):
#wrap div {
-moz-transform: rotate(20deg);
-ms-transform: rotate(20deg);
-o-transform: rotate(20deg);
-webkit-transform: rotate(20deg);
float:left;
width:50%;
height:200px;
}
http://jsfiddle.net/F6DgA/
Also i tried smth. with overflow:hidden:
http://jsfiddle.net/F6DgA/1/ (partly corrent, but not very clean solution)
Is there a more easy way (dont wann use an image..)?
I would personally avoid using transforms and use the border property instead. This seems much cleaner to me (and also works in IE8).
Example: http://jsfiddle.net/F6DgA/5/
Note: To make sure the content inside the divs doesn't float on top of the edge, add something like * { box-sizing:border-box; } and then a padding left/right to the divs.
The CSS:
#wrap {
width:300px;
height:100px;
margin:0 auto;
position:relative;
}
#wrap div {
position:relative;
height:100%;
float:left;
}
#one {
background:#333;
width:calc(50% + 15px);
}
#one:after {
content:"";
position:absolute;
right:0;
border-right:30px solid black;
border-top:100px solid transparent;
}
#two {
background:#000;
width:calc(50% - 15px);
}
Use CSS gradient for the #wrap div, check here for an example.
Something like this:
background: #9dd53a;
background: -moz-linear-gradient(-45deg, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%);
background: -webkit-gradient(linear, left top, right bottom, color-stop(0%,#9dd53a), color-stop(50%,#a1d54f), color-stop(51%,#80c217), color-stop(100%,#7cbc0a));
background: -webkit-linear-gradient(-45deg, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%);
background: -o-linear-gradient(-45deg, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%);
background: -ms-linear-gradient(-45deg, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%);
background: linear-gradient(135deg, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9dd53a', endColorstr='#7cbc0a',GradientType=1 );
Whatever the height and width having your parent div you have to double height of your child element. After that give position:absolute to your child elements. Give -50% left position to your first child div and give -50% right position to your second child div
CSS Will be like following:
#wrap {
width:400px;
margin:0 auto;
position:relative;
height:300px;
overflow:hidden;
}
#wrap div {
-moz-transform: rotate(20deg);
-ms-transform: rotate(20deg);
-o-transform: rotate(20deg);
-webkit-transform: rotate(20deg);
float:left;
width:100%;
height:600px;
top:-50%;
position:absolute;
}
#wrap div#one { left:-50%; }
#wrap div#two { right:-50%; }
#one {
background:#333;
}
#two {
background:#000;
}
Please check this Working URL
Demo
css
#one {
border-top: 200px solid gray;
border-right: 100px solid transparent;
height: 0;
width: 30%;
float:left
}
#two {
border-bottom: 200px solid black;
border-left: 100px solid transparent;
height: 0;
width: 30%;
float:left;
margin-left:-100px;
}
#wrap {
width:400px;
margin:0 auto;
}
you can use pseudo element :after or :before
CODEPEN
<div class="rect"></div>
.rect {
background:#000;
height: 50px;
width: 150px;
position: relative;
overflow: hidden;
}
.rect:after {
content: "";
background:#333;
height: 100px;
width: 300px;
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
display: block;
position: absolute;
top:-7px;
right: 10px;
}
Reference this css Shape examples !
This is what I've tried . Demo here !
It's not correctly the same with your need .
But I think , you can approach your need by a little modification !
html
<div Id="parallelogram"></div>
<div Id="parallelogram2"></div>
css
#parallelogram {
width: 130px;
height: 75px;
background: pink;
position:absolute;
overflow:hidden;
/* Skew */
-webkit-transform: skew(-20deg);
-moz-transform: skew(-20deg);
-o-transform: skew(-20deg);
transform: skew(-20deg);
}
#parallelogram2 {
width: 130px;
height: 75px;
margin-left:100px;
background: Black;
position:absolute;
overflow:hidden;
/* Skew */
-webkit-transform: skew(-20deg);
-moz-transform: skew(-20deg);
-o-transform: skew(-20deg);
transform: skew(-20deg);
}