How to make 2 side by side divs with slanted middle [duplicate] - html

This question already has an answer here:
two divs split with diagonal line - CSS
(1 answer)
Closed 2 years ago.
Please help in making 2 divs side-by-side (50% each) that covers the entire width of the page and that the middle is slanted/skewed (please see attached photo). I have seen a few examples of skewed divs and have had no luck trying to make it work for my needs - especially when changing the size of the browser window.
Thanks in advance for all your help.
.slantContainer{
display:flex;
flex-flow:row;
height: 300px;
}
.slantedShare{
background-color: #6179ff;
color: white;
position: relative;
width:100%;
padding: 10px 30px 10px 10px;
}
.slantedShare::after {
background: #6179ff;
content: " ";
position: absolute;
display: block;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -2;
transform-origin: bottom left;
-ms-transform: skew(-10deg, 0deg);
-webkit-transform: skew(-10deg, 0deg);
transform: skew(-10deg, 0deg);
}
.slantedDonate{
background-color: #7b24f1;
color: white;
position: relative;
width:100%;
padding: 10px 30px 10px 10px;
}
.slantedDonate::after{
background: #7b24f1;
content: " ";
position: absolute;
display: block;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
transform-origin: top left;
-ms-transform: skew(-10deg, 0deg);
-webkit-transform: skew(-10deg, 0deg);
transform: skew(-10deg, 0deg);
}
<div>
<div class="slantContainer">
<div class="slantedShare">
container for left div
</div>
<div class="slantedDonate">
container for right div
</div>
</div>
</div>
<table style="width:100%;">
<tr style="width:100%;">
<td style="width:50%;">
<div class="slantedShare">
Left Div inside Table
</div>
</td>
<td style="width:50%;">
<div class="slantedDonate">
right div inside table
</div>
</td>
</tr>
</table>

If you play with the z-index it works
.slantContainer{
display:flex;
flex-flow:row;
height: 300px;
}
.slantedShare{
background-color: #6179ff;
color: white;
position: relative;
width:100%;
padding: 10px 30px 10px 10px;
}
.slantedShare::after {
background: #6179ff;
content: " ";
position: absolute;
display: block;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -2;
transform-origin: bottom left;
-ms-transform: skew(-10deg, 0deg);
-webkit-transform: skew(-10deg, 0deg);
transform: skew(-10deg, 0deg);
}
.slantedDonate{
background-color: #7b24f1;
color: white;
position: relative;
width:100%;
padding: 10px 30px 10px 10px;
z-index: 1;
}
.slantedDonate::before {
background: #7b24f1;
content: " ";
position: absolute;
display: block;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
transform-origin: top left;
-ms-transform: skew(-10deg, 0deg);
-webkit-transform: skew(-10deg, 0deg);
transform: skew(-10deg, 0deg);
}
<div>
<div class="slantContainer">
<div class="slantedShare">
container for left div
</div>
<div class="slantedDonate">
container for right div
</div>
</div>
</div>
<table style="width:100%;">
<tr style="width:100%;">
<td style="width:50%;">
<div class="slantedShare">
Left Div inside Table
</div>
</td>
<td style="width:50%;">
<div class="slantedDonate">
right div inside table
</div>
</td>
</tr>
</table>

This can be done with a single div:
.slnt {
width: 50%;
min-width: 60vh;
height: calc(50vh / 2);
min-height: 20vw;
background-color: dodgerblue;
}
.slnt::before,
.slnt::after {
content: "";
display: inline-block;
height: 100%;
}
.slnt::before {
background-color: dodgerblue;
transform: skew(-20deg);
margin-right: -30px;
position: relative;
left: 8%;
width: 40%;
z-index: 1;
}
.slnt::after {
background-color: indigo;
width: 60%;
position:relative;
right: -31px;
}
<div class="slnt"></div>

Related

Hover on parent to trigger transform property

I am attempting to use a hover effect to transform my second arrow #arrowDown2 to go down to show both arrows. I am wanting the hover to trigger on arrowDownWrap.
What am I doing wrong?
#blue {
width: 100%;
height: 300px;
background: blue;
}
#arrowDownWrap {
position: absolute;
bottom: 120px;
left: 50%;
-webkit-transform: translate(-50%,0);transform: translate(-50%,0);
cursor: pointer;
}
#arrowDownWrapInner {
position: relative;
bottom: 40px;
}
#arrowDown, #arrowDown2 {
border: solid #FFF;
border-width: 0 3px 3px 0;
width: 25px;
height: 25px;
display: block;
padding: 3px;
-webkit-transform: rotate(45deg);transform: rotate(45deg);
position: absolute;
top: 0;
left: 0;
}
#arrowDownWrap:hover #arrowDown2 {
-webkit-transform: rotate(45deg), translate(0, 40px);transform: rotate(45deg), translate(0, 40px);
}
<div id="blue">
<div id="arrowDownWrap">
<div id="arrowDownWrapInner">
<i id="arrowDown"></i>
<i id="arrowDown2"></i>
</div>
</div>
</div>
To specify multiple CSS transform properties, no comma is necessary.
Just list them one after another.
For example:
transform: rotate(45deg) translate(0, 40px);
Working example:
#blue {
position: relative;
width: 100%;
height: 150px;
background: blue;
}
#arrowDownWrap {
position: absolute;
bottom: 100px;
left: 50%;
-webkit-transform: translate(-50%, 0);
transform: translate(-50%, 0);
cursor: pointer;
}
#arrowDownWrapInner {
position: relative;
bottom: 20px;
}
#arrowDown,
#arrowDown2 {
border: solid #FFF;
border-width: 0 3px 3px 0;
width: 25px;
height: 25px;
display: block;
padding: 3px;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
position: absolute;
top: 0;
left: 0;
background-color: red;
}
#arrowDownWrap:hover #arrowDown2 {
-webkit-transform: translate(0, 50px) rotate(45deg);
transform: translate(0, 50px) rotate(45deg);
}
<div id="blue">
<div id="arrowDownWrap">
<div id="arrowDownWrapInner">
<i id="arrowDown"></i>
<i id="arrowDown2"></i>
</div>
</div>
</div>

How to add rotated underlined message on top of the div

I need to create a box which has a rotated message on top with border-bottom, however I can't make it responsive. The bottom line should always go from border to border.
.holder {
width: 40%;
background-color: yellow;
height: 400px;
}
.rotated-text {
float: right;
text-align: center;
width: 25%;
border-bottom: 1px solid green;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
}
<div class="holder">
<div class="rotated-text">
<p>Hello! <br> This text is rotated</p>
</div>
</div>
I tried to use position: absolute or some clip-path but it didn't work out. Is should look something like this:
If it is not possible I guess I will have to use an image. Thanks!
I have a sample here. In this one the width and and height of rotated-text div is fixed. But it can stick to top right corner of its container always.
.holder {
width: 80%;
background-color: yellow;
height: 400px;
position:relative
}
.rotated-text {
position: absolute;
text-align: center;
width: 100px;
height: 65px;
border-bottom: 1px solid green;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
right:7px;
top: 26px;
background: red;
}
.rotated-text p{
margin:0;
}
.rotated-text:after{
content: "";
position: absolute;
left: -64px;
right:-63px;
bottom:0;
height: 1px;
background: green;
}
<div class="holder">
<div class="rotated-text">
<p>Hello! <br> This text is rotated</p>
</div>
</div>

CSS Arrows with borders

I found this codepen demo which almost does what I need (http://codepen.io/web-tiki/pen/EaKPMK).
HTML:
<div class="wrap">
<div class="arrow"></div>
</div>
CSS:
.wrap {
position: relative;
height:150px;
overflow: hidden;
width: 70%;
margin: 0 auto;
}
.wrap img {
width: 100%;
height: auto;
display: block;
}
.arrow {
position: absolute;
bottom: 0;
width: 100%;
padding-bottom:3%;
background-color: rgba(0, 0, 0, 0.8);
}
.arrow:before, .arrow:after {
content:'';
position: absolute;
bottom: 100%;
width: 100%;
padding-bottom:inherit;
background-color: inherit;
}
.arrow:before {
right: 20%;
-ms-transform-origin: 100% 100%;
-webkit-transform-origin: 100% 100%;
transform-origin: 100% 100%;
-ms-transform: skewX(45deg);
-webkit-transform: skewX(45deg);
transform: skewX(75deg);
}
.arrow:after {
left: 80%;
-ms-transform-origin: 0 100%;
-webkit-transform-origin: 0 100%;
transform-origin: 0 100%;
-ms-transform: skewX(-45deg);
-webkit-transform: skewX(-45deg);
transform: skewX(-75deg);
}
The only thing that's missing is, that I actually need a border around the box. When I add borders to the pseudo elements, the skewed part doesn't produce a closed line.
.arrow:before {
right: 20%;
-ms-transform-origin: 100% 100%;
-webkit-transform-origin: 100% 100%;
transform-origin: 100% 100%;
-ms-transform: skewX(45deg);
-webkit-transform: skewX(45deg);
transform: skewX(75deg);
border-top: 4px solid #df0000;
border-right: 30px solid #df0000;
}
.arrow:after {
left: 80%;
-ms-transform-origin: 0 100%;
-webkit-transform-origin: 0 100%;
transform-origin: 0 100%;
-ms-transform: skewX(-45deg);
-webkit-transform: skewX(-45deg);
transform: skewX(-75deg);
border-top: 4px solid #df0000;
border-left: 30px solid #df0000;
}
Any Ideas how to make this work?
This is my solution, although it inserts a new element: <div class="arrow-head">
.wrap {
position: relative;
height:150px;
overflow: hidden;
width: 70%;
margin: 0 auto;
}
.wrap img {
width: 100%;
height: auto;
display: block;
}
.arrow {
position: absolute;
bottom: 0;
width: 100%;
padding-bottom:3%;
background-color: rgba(0, 0, 0, 0.8);
}
.arrow:before, .arrow:after {
content:'';
position: absolute;
bottom: 100%;
width: 100%;
padding-bottom:inherit;
background-color: inherit;
}
.arrow:before {
right: 20%;
-ms-transform-origin: 100% 100%;
-webkit-transform-origin: 100% 100%;
transform-origin: 100% 100%;
-ms-transform: skewX(45deg);
-webkit-transform: skewX(45deg);
transform: skewX(75deg);
border-top: 4px solid #df0000;
border-right: 30px solid #df0000;
}
.arrow:after {
left: 80%;
-ms-transform-origin: 0 100%;
-webkit-transform-origin: 0 100%;
transform-origin: 0 100%;
-ms-transform: skewX(-45deg);
-webkit-transform: skewX(-45deg);
transform: skewX(-75deg);
border-top: 4px solid #df0000;
border-left: 30px solid #df0000;
}
.arrow-head {
position: absolute;
right: -moz-calc(20% - 30px);
right: webkit-calc(20% - 30px);
right: -o-calc(20% - 30px);
right: calc(20% - 30px);
width: 0;
height: 0;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
border-top: 8px solid #df0000;
}
<div class="wrap">
<div class="arrow">
<div class="arrow-head">
</div>
</div>
</div>
here is one way.i think this is what you are looking for
.arrow:before {
right: 20%;
-ms-transform-origin: 100% 100%;
-webkit-transform-origin: 100% 100%;
transform-origin: 100% 70%;
-ms-transform: skewX(45deg);
-webkit-transform: skewX(45deg);
transform: skewX(75deg);
border-top: 4px solid #df0000;
border-right: 30px solid #df0000;
}
.arrow:after {
left: 80%;
-ms-transform-origin: 0 100%;
-webkit-transform-origin: 0 100%;
transform-origin: 0 100%;
-ms-transform: skewX(-45deg);
-webkit-transform: skewX(-45deg);
transform: skewX(-75deg);
border-top: 4px solid #df0000;
border-left: 30px solid #df0000;
}
you need to decrease the value of the pseudo elements like-
.arrow:after {left:49%}
so your code will be look like-
.wrap {
position: relative;
height:150px;
overflow: hidden;
width: 70%;
margin: 0 auto;
}
.wrap img {
width: 100%;
height: auto;
display: block;
}
.arrow {
position: absolute;
bottom: 0;
width: 100%;
padding-bottom:3%;
background-color: rgba(0, 0, 0, 0.8);
}
.arrow:before, .arrow:after {
content:'';
position: absolute;
bottom: 100%;
width: 50%;
padding-bottom:inherit;
background-color: inherit;
}
.arrow:before {
right: 50%;
-ms-transform-origin: 100% 100%;
-webkit-transform-origin: 100% 100%;
transform-origin: 100% 100%;
-ms-transform: skewX(45deg);
-webkit-transform: skewX(45deg);
transform: skewX(45deg);
border-right:10px solid red;
border-top:10px solid red;
}
.arrow:after {
left: 49%;
-ms-transform-origin: 0 100%;
-webkit-transform-origin: 0 100%;
transform-origin: 0 100%;
-ms-transform: skewX(-45deg);
-webkit-transform: skewX(-45deg);
transform: skewX(-45deg);
border-left:10px solid red;
border-top:10px solid red;
}
it will look like this -
I came up with this solution:
html:
<div class="bar left"></div><!--
--><div class="arrow-outer">
<div class="square left"></div>
<div class="square right"></div>
<div class="border left"></div>
<div class="border right"></div>
</div><!--
--><div class="bar right"></div>
css:
*{
box-sizing: border-box;
}
.bar{
position: relative;
vertical-align: top;
width: 200px;
height: 35px;
display: inline-block;
background-color: #dfdfdf;
border-top: 4px solid #ff0000;
}
.arrow-outer{
display: inline-block;
vertical-align: top;
width: 100px;
height: 35px;
position: relative;
overflow: hidden;
}
.square{
position: absolute;
width: 100px;
height: 100px;
top: 0;
background-color: #dfdfdf;
}
.square.left{
transform-origin:left top;
left: 0;
transform: rotate(30deg);
}
.square.right{
transform-origin:right top;
right: 0;
transform: rotate(-30deg);
}
.border{
width: 58px;
height: 4px;
background-color: #ff0000;
position: absolute;
top: 0;
}
.border.left{
transform-origin:left top;
left: 0;
transform: rotate(30deg) skewX(30deg);
}
.border.right{
transform-origin:right top;
right: 0;
transform: rotate(-30deg) skewX(-30deg);
}
Here's the codepen:
http://codepen.io/swissdoode/pen/OpzEaJ
The only problem is, that the «fake» border doesn't really line up to the other borders because of the rotate and skewX. It's barely visible, though...
Thoughts?

create a responsive triangle

I'm trying to set two triangles in the following way:
The two triangles have to go from the middle to the outside of the browser. I tried to set it up with a wrapper and a background-color and then rotate the wrapper, but I cant get it responsive. The code I tried was:
#page-header-wrapper-triangle {
background-color:#e14b41 ;
-webkit-transform: rotate(-12deg) translate3d(0, 0, 0);
-moz-transform: rotate(-12deg);
-o-transform: rotate(-12deg);
-ms-transform: rotate(-12deg);
transform: rotate(-12deg);
margin: 0 -21px;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
-ms-transform-origin: left center;
transform-origin: left center;
-webkit-backface-visibility: hidden;
outline: 1px solid transparent;
position: relative;
min-height: 204px;
z-index:1000;
width:80%;
}
#page-header-wrapper-triangle-2 {
background-color:#e14b41 ;
-webkit-transform: rotate(12deg) translate3d(0, 0, 0);
-moz-transform: rotate(12deg);
-o-transform: rotate(12deg);
-ms-transform: rotate(12deg);
transform: rotate(12deg);
margin: 0 -54px;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
-ms-transform-origin: left center;
transform-origin: left center;
-webkit-backface-visibility: hidden;
outline: 1px solid transparent;
position: relative;
min-height: 204px;
z-index:1000;
width:80%;
float:right;
top:-520px;
}
<div id="page-header-wrapper-triangle">
<div class="container">
<div class="row">
<div class="right-red col-xs-12 col-sm-6">
</div>
<div class="left-blue col-xs-12 col-sm-6">
</div>
</div>
</div>
</div>
<div id="page-header-wrapper-triangle-2">
<div class="container">
<div class="row">
<div class="right-red col-xs-12 col-sm-6">
</div>
<div class="left-blue col-xs-12 col-sm-6">
</div>
</div>
</div>
</div>
This works when the width of the browser is 1920 px, but s soon as I change the width it doesn't work. I got no clue how I can get this responsive.
I also tried it with background pictures. But this also doesn't work.
You can do it with pseudo selectors :after. It's responsive-ready only for some small and mid widths. But you can easily customize with media queries and change the top and height value.
There is a live example using SCSS
.header {
background-color: grey;
padding-bottom: 60px;
padding-top: 60px;
position: relative;
display: inline-block;
width: 100%;
}
.header .block-left {
float: left;
width: 50%;
}
.header .block-left:after {
background-color: red;
content: ' ';
left: 0;
top: -125px;
height: 200px;
position: absolute;
transform: skew(0deg, -15deg);
width: 50%;
z-index: 20;
}
.header .block-right {
float: right;
width: 50%;
}
.header .block-right:after {
right: 0;
background-color: yellow;
content: ' ';
top: -125px;
height: 200px;
position: absolute;
transform: skew(0deg, 15deg);
width: 50%;
z-index: 20;
}
<div class="header">
<div class="block-left"></div>
<div class="block-right"></div>
</div>
Here's a explanation of how css triangles works : http://codepen.io/chriscoyier/pen/lotjh
#import url(http://fonts.googleapis.com/css?family=Andika);
$stepTiming: 0.8s 0.2s;
.triangle-demo {
width: 100px;
height: 100px;
margin: 0 auto;
background: tan;
border-top: 0 solid #EE7C31;
border-left: 0 solid #F5D97B;
border-bottom: 0 solid #D94948;
border-right: 0 solid #8DB434;
transition: $stepTiming;
.step-1 & {
border-top-width: 10px;
}
.step-2 & {
border-left-width: 10px;
}
.step-3 & {
border-right-width: 10px;
}
.step-4 & {
border-bottom-width: 10px;
}
.step-6 & {
background: transparent;
}
.step-7 & {
width: 0; height: 0;
}
.step-8 & {
border-left-color: transparent;
}
.step-9 & {
border-right-color: transparent;
}
.step-10 & {
border-top-color: transparent;
}
}
.triangle-title {
width: 300px;
padding: 1rem;
color: white;
background: #D94948;
border-radius: 20px;
margin: auto;
opacity: 0;
transition: $stepTiming;
.step-11 & {
opacity: 1;
}
}
body {
background: #333;
font-family: 'Andika', sans-serif;
color: white;
text-align: center;
font-size: large;
transform: translateZ(0);
}
.steps {
position: relative;
height: 45px;
> div {
position: absolute;
top: 0;
left: 0;
width: 100%;
opacity: 0;
background: #333;
transition: 0.3s;
}
.step-0 {
opacity: 1;
}
.step-1 & .step-1 {
opacity: 1;
}
.step-2 & .step-2 {
opacity: 1;
}
.step-5 & .step-5 {
opacity: 1;
}
.step-6 & .step-6 {
opacity: 1;
}
.step-7 & .step-7 {
opacity: 1;
}
.step-8 & .step-8 {
opacity: 1;
}
.step-11 & .step-11 {
opacity: 1;
}
}
h1 {
text-transform: uppercase;
letter-spacing: 1px;
font-size: 1.5rem;
border-bottom: 1px solid #555;
color: #999;
}
FYI http://1stwebdesigner.com/css-shapes/

Add pointer to the bottom of a div as a continuation of its background image

I'm looking for a way to stack divs, with a pointer leading into the next div that is a continuation of the previous div's background image.
I've looked around and I've seen some options, but in all of them the bottom div has to be a solid color.
For example: http://jsfiddle.net/nhqKb/
#container{
height: 300px;
background: url('http://farm8.staticflickr.com/7358/9532233404_58763bd668_b.jpg') no-repeat;
position: relative;
}
#one {
position: absolute;
width: 100px;
left: 0;
bottom: 0;
border-bottom: 20px solid green;
border-right: 20px solid transparent;
}
#two {
position: absolute;
left: 120px;
bottom: 0;
right: 0;
border-bottom: 20px solid green;
border-left: 20px solid transparent;
}
<div id="container">
<div id="one"></div>
<div id="two"></div>
</div>
Is there any way to implement this using divs with background images instead of solid colors?
You can use skewX and pseudo elements to make this.
#container {
background: url('https://images.unsplash.com/photo-1440635592348-167b1b30296f?ixlib=rb-0.3.5&q=80&fm=jpg&w=1080&fit=max&s=a029f986631f264fdbc8c0272cab9c40') no-repeat;
height: 300px;
position: relative;
overflow: hidden;
}
#one {
background-color: rgba(0, 0, 0, 0.3);
bottom: 0;
left: 0;
padding-bottom: 15px;
position: absolute;
width: 100%;
}
#one:before,
#one:after {
background-color: inherit;
bottom: 100%;
content: '';
padding-bottom: inherit;
position: absolute;
width: 50%;
}
#one:before {
right: 50%;
-ms-transform-origin: 100% 100%;
-webkit-transform-origin: 100% 100%;
transform-origin: 100% 100%;
-ms-transform: skewX(45deg);
-webkit-transform: skewX(45deg);
transform: skewX(45deg);
}
#one:after {
left: 50%;
-ms-transform-origin: 0 100%;
-webkit-transform-origin: 0 100%;
transform-origin: 0 100%;
-ms-transform: skewX(-45deg);
-webkit-transform: skewX(-45deg);
transform: skewX(-45deg);
}
HTML code:
<div id="container">
<div id="one"></div>
</div>