Separate 2 div's with slope line - html

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

Related

circle divided by two css with image

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>

Rotate background image height 100%

I'm trying to make my images responsive with some rotation angle (10deg) but my height is increasing too much, and it's not at center and full width.
This is the design (colors are background-image), as you can see, with the rotation, I can't fill all the top side and same with bottom, and another problem, is my full height increase.
*CSS: CODE
.rotate > div {
transform: scale(1) rotate(-10deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg);
}
.rotate > div > div > div {
transform: scale(1) rotate(10deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg);
}
.full {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.list {
position: relative;
width: 100%;
height: 100%;
}
.item {
height: 50%;
}
.wrapper {
width: 100%;
height: 100%;
}
Thank you so much guys.
Use the images within a pseudo element and allow some overflow to cover the white space:
body {
margin:0;
min-height:500px;
height:100vh;
overflow:hidden;
}
.box {
height:50%;
box-sizing:border-box;
position:relative;
}
.box:before {
content:"";
position:absolute;
top:-40%;
left:-10%;
right:-10%;
bottom:-40%;
transform:rotate(-10deg);
background:var(--i) center/cover no-repeat;
}
.box.first::before {
bottom:0;
}
.box.last::before {
top:0;
}
<div class="box first" style="--i:url(https://picsum.photos/1000/800?image=0)">
</div>
<div class="box last" style="--i:url(https://picsum.photos/1000/800?image=1069)">
</div>

Cut corners of Image using css

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%) ;

CSS get the before pseudo element to appear below the actual element

I have the following CSS which places the before pseudo element on top of the actual element, but I need it to appear below.
Is this possible. I've seen lots of similar posts and taken all the advice but still can't get it to work. Any ideas?
http://jsfiddle.net/6wsyqrwx/
div {
height: 224px;
width: 294px;
border:7px solid #FFF;
box-shadow: 2px 2px 5px;
margin:50px;
-ms-transform: rotate(-3deg); /* IE 9 */
-webkit-transform: rotate(-3deg); /*Chrome, Safari, Opera */
transform: rotate(-3deg);
z-index:auto;
background:red;
position: relative;
}
div::before {
height: 224px;
width: 294px;
border:7px solid #FFF;
box-shadow: 2px 2px 5px;
-ms-transform: rotate(6deg); /* IE 9 */
-webkit-transform: rotate(6deg); /*Chrome, Safari, Opera */
transform: rotate(6deg);
background:blue;
display:block;
content:'';
z-index:-1;
position:absolute;
}
The problem is with the transform properties. It will not go well with position items. Have a look at below fiddle without transform.
http://jsfiddle.net/kiranvarthi/6wsyqrwx/7/
div {
height: 224px;
width: 294px;
border:7px solid #FFF;
box-shadow: 2px 2px 5px;
margin:50px;
z-index:auto;
background:red;
position: relative;
}
div::before {
height: 224px;
width: 294px;
border:7px solid #FFF;
box-shadow: 2px 2px 5px;
background:blue;
display:block;
content:'bottom';
z-index:-1;
position:absolute;
}
As Kiran Varthi mentions in his answer, this seems to be a problem due to the transform properties. You could achieve the desired effect by using the ::after pseudo element instead of styling the div.
div {
height: 238px;
width: 308px;
margin:50px;
position: relative;
}
div::after {
height: 224px;
width: 294px;
border:7px solid #FFF;
box-shadow: 2px 2px 5px;
-ms-transform: rotate(-3deg); /* IE 9 */
-webkit-transform: rotate(-3deg); /*Chrome, Safari, Opera */
transform: rotate(-3deg);
display:block;
content:'top';
background:red;
position: absolute;
}
div::before {
height: 224px;
width: 294px;
border:7px solid #FFF;
box-shadow: 2px 2px 5px;
-ms-transform: rotate(6deg); /* IE 9 */
-webkit-transform: rotate(6deg); /*Chrome, Safari, Opera */
transform: rotate(6deg);
background:blue;
display:block;
content:'bottom';
position:absolute;
}
<div></div>
JS Fiddle: http://jsfiddle.net/tkd3L6ns/
You can switch divs places - put :after on the top element:
div {
height: 224px;
width: 294px;
border:7px solid #FFF;
box-shadow: 2px 2px 5px;
-ms-transform: rotate(6deg);
/* IE 9 */
-webkit-transform: rotate(6deg);
/*Chrome, Safari, Opera */
transform: rotate(6deg);
background:blue;
position:relative;
}
div:after {
content:'top';
position:absolute;
height: 224px;
width: 294px;
border:7px solid #FFF;
box-shadow: 2px 2px 5px;
margin:50px;
-ms-transform: rotate(-3deg);
/* IE 9 */
-webkit-transform: rotate(-3deg);
/*Chrome, Safari, Opera */
transform: rotate(-3deg);
background:red;
}
<div>bottom</div>
JSFiddle
Note: I didn't position them like you did, this just shows that it can be done with one pseudo element (:after) and using transform.

How to create a responsive 4 div diamond?

I am working on a project where I have a div diamond of pictures that needs to be responsive.
The picture below shows the diamond in div I have created, but it doesn't work in all sizes. I want the diamond to react responsively to the browser size, so it always fits.
I have a jsFiddle, but it is not responsive. Just to show what I want, and I have been trying to create.
<div id="page">
<div id="main">
<div class="box blue"></div>
<div class="box green"></div>
<div class="box red"></div>
<div class="box yellow"></div>
</div>
</div>
#page {
width:100%;
height:100%;
min-height:500px;
min-width:500px;
}
#main {
height:80px;
width:80px;
position:relative;
display:block;
transform: rotate(45deg);
-ms-transform: rotate(45deg); /* IE 9 */
-webkit-transform: rotate(45deg); /* Safari and Chrome */
}
.box {
display: inline-block;
height:35%;
width:35%;
margin-right:5%;
margin-top:5%;
}
.blue {
background-color:blue;
}
.green {
background-color:green;
}
.red {
background-color:red;
}
.yellow {
background-color:#ffd54f;
}
Any help is very much appreciated :-)
Start with a responsive base:
#main {
width: 35%;
height: 0;
position: relative;
padding-bottom: 35%;
border: solid 1px black;
margin: auto;
}
The trick is to set the vertical dimension as padding percentage, that is calculated on the width of the parent. (So it is always a square)
Now set the diamonds, translated as percentages.
.box {
height:100%;
width:100%;
position: absolute;
}
.blue {
background-color:blue;
-webkit-transform: translate(-75%, 100%) rotate(45deg);
}
.green {
background-color:green;
-webkit-transform: translate(0, 25%) rotate(45deg);
}
.red {
background-color:red;
-webkit-transform: translate(75%, 100%) rotate(45deg);
}
.yellow {
background-color:#ffd54f;
-webkit-transform: translate(0, 175%) rotate(45deg);
}
fiddle
EDIT: OK it can be done with CSS alone. Updated fiddle here:
http://jsfiddle.net/5CfNb/5/
Not sure if this can be done with CSS alone, but here's my solution using a few lines of jQuery. Depending on the aspect ratio though, it won't be a perfect 'diamond', so still needs some tweaking. But I hope this helps.
$('#main').height($(window).height());
$('#main').width($(window).width());
$(window).resize(function() {
$('#main').height($(window).height());
$('#main').width($(window).width());
});
http://jsfiddle.net/5CfNb/4/
This could also help you a bit: http://jsfiddle.net/maximgladkov/bJLYn/1/
#main {
position: absolute;
top: 50%;
left: 50%;
margin: -15% 0 0 -15%;
height: 0px;
width: 30%;
padding-top: 30%;
overflow: visible;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
.box {
display: block;
width: 45%;
height: 45%;
position: absolute;
}
.blue {
background: blue;
top: 0;
left: 0;
}
.green {
background: green;
top: 0;
right: 0;
}
.red {
background: red;
bottom: 0;
right: 0;
}
.yellow {
background: #ffd54f;
bottom: 0;
left: 0;
}