Hi I'm trying to create the following Angled Strip Look in HTML & CSS:
Just the Blue and Purple area with white after.
I can obviously see how to do it using an image but what about HTML/CSS only?
Is this possible?
Its used on the site - www.africa.dating
I know I should have more example code but I'm actually not sure where to begin so I only have the following HTML:
Fiddle: http://jsfiddle.net/e2dr5udr/3/
<div id="container">
<div id="blue"></div>
<div id="purple"></div>
</div>
#container {
width: 100%;
height: 100px;
background-color: white;
position: absolute;
}
#blue {
width: 100%;
height: 100px;
background-color: blue;
position: absolute;
}
#purple {
width: 100%;
height: 100px;
background-color: purple;
position: absolute;
}
thankyou
You can use a pseudo element and some border manipulation.
This would allow you to create it with only a single element, to create this:
.title {
height: 1px;
background-color: transparent;
border-bottom: 170px solid blue;
border-right: 170px solid transparent;
width: 190px;
position:relative;
}
.title:after{
content:"";
position:absolute;
height: 1px;
top:0px;
background-color: transparent;
border-bottom: 170px solid purple;
border-right: 170px solid transparent;
width: 210px;
z-index:-1;
}
<div class="title"></div>
If you do not want to use this approach, an alternative method (using background gradients) can be viewed here
Using SkewX:
div{
position:relative;
height:15vh;
width:60vw;
overflow:hidden;
}
div:before{
z-index:-1;
content:"";
position:absolute;
top:0;
height:100%;
right:50%;
width:150%;
border-right:10px solid green;
background:cornflowerblue;
-webkit-transform:skewX(45deg);
transform:skewX(45deg);
}
<div>123</div>
Here is a demo of what you want: http://jsfiddle.net/shivanraptor/c4vrLrq7/
Basically it's a Square (#blue), Triangle (#triangle), Parallelogram (#parallelogram)
#container {
width: 100%;
height: 100px;
background-color: white;
position: absolute;
}
#blue {
width: 200px;
height: 100px;
background-color: blue;
float: left;
}
#triangle {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid blue;
float: left;
margin-left: -50px;
}
#parallelogram {
width: 50px;
height: 100px;
-webkit-transform: skew(30deg);
-moz-transform: skew(30deg);
-o-transform: skew(30deg);
background: purple;
float: left;
margin-left: -50px;
}
<div id="container">
<div id="blue"></div>
<div id="triangle"></div>
<div id="parallelogram"></div>
</div>
If you want a background-image, you could make use of rgba() values and a :pseudo-element.
The idea is to apply the background-image to an :after :pseudo-element and the linear-gradient with rgba() values on the main div.
You could change the opacity of the linear-gradient by changing the alpha value in rgba(red, green, blue, alpha)
div {
position: relative;
height: 200px;
background: linear-gradient(55deg, rgba(122, 0, 201, 0.8) 75%, rgba(178, 0, 204, 0.8) 75%, rgba(178, 0, 204, 0.7) 80%, transparent 80%);
}
div:after {
position: absolute;
content: '';
width: 100%;
height: 100%;
background: url(http://lorempixel.com/700/200);
z-index: -1;
}
<div></div>
An other approach using one element, the skewX() property for the slope right side, the transparency is made with rgba() background-color and border on a pseudo element :
DEMO
div{
height:100%;
position:relative;
overflow:hidden;
}
div:before{
content:'';
position:absolute;
top:0; right:0;
width:100%; height:100%;
background-color: rgba(90, 74, 199, .8);
border-right:40px solid rgba(173, 96, 223, .8);
-webkit-transform-origin:100% 100%;
-ms-transform-origin:100% 100%;
transform-origin:100% 100%;
-webkit-transform:skewX(30deg);
-ms-transform:skewX(30deg);
transform:skewX(30deg);
}
/****** FOR THE DEMO *******/
html, body{
background: url(http://lorempixel.com/output/people-q-c-640-480-1.jpg);
background-size:cover;
margin:0;padding:0;
height:100%;
<div></div>
Related
Is it possible to create an a curved element like this with border radius ruler if so what is it?
.box {
width: 500px;
height: 100px;
border: solid 0 #000;
border-color: #000 transparent transparent transparent;
border-radius: 100%/0 100px 0 0px;
background-color: #FF7C07;
}
<div class="box"></div>
i tried doing it with this code but i cant seem to make it work.
You can use a radial-gradient as background for this:
.box {
width: 500px;
height: 200px;
background: radial-gradient(110% 50% at top right,#0000 99%,#FF7C07);
}
<div class="box"></div>
This was the closest I could get to your curved element. Sadly, there is no direct way of doing this using only border radius.
.box {
width: 500px;
height: 100px;
border: solid 0 #000;
border-color: #000 transparent transparent transparent;
background-color: #FF7C07;
}
.top-right {
margin-top: -125px;
margin-left: -35px;
width: 535px;
height: 80px;
border-bottom-left-radius: 100%;
background-color: #FFFFFF;
}
<div class="box"></div>
<div class="top-right"></div>
I would recommend the following method instead:
.box {
height: 200px;
overflow:hidden;
background-color: #FF7C07;
position:relative;
z-index:10;
}
.box:before {
content: "";
position: absolute;
left: -25%;
right: -125%;
top: -200%;
bottom: 30%;
background-color: #FFF;
border-radius: 100%;
z-index: -1;
}
<div class="box">123</div>
Can anyone please help with this? How to achieve the attached button with CSS only(no image)?
This is my code so far:
.triangle-up {
width: 0;
height: 0;
border-left: 25px solid transparent;
border-right: 25px solid transparent;
border-bottom: 50px solid #555;
}
<div class="triangle-up"></div>
Use pseudo element where you apply a radial-gradient:
.box {
margin:60px 10px 0;
display:inline-block;
color:#fff;
text-align:center;
padding:10px 30px;
background:green;
border-radius:50px;
position:relative;
}
.box:before {
content:"";
position:absolute;
bottom:100%;
left:50%;
width:60px;
height:25px;
transform:translateX(-50%);
background:
radial-gradient(farthest-side at top left , transparent 98%,green 100%) left,
radial-gradient(farthest-side at top right, transparent 98%,green 100%) right;
background-size:50.2% 100%;
background-repeat:no-repeat;
}
body {
background:pink;
}
<div class="box">text here</div>
<div class="box">more and more text here</div>
<div class="box">2 lines <br>of text</div>
Another idea in case you want any kind of coloration:
.box {
margin:60px 10px 0;
display:inline-block;
color:#fff;
text-align:center;
padding:10px 30px;
background-image:linear-gradient(60deg,yellow,purple,green,blue);
background-size:100% calc(100% + 25px);
background-position:bottom;
border-radius:50px;
position:relative;
z-index:0;
}
.box:before {
content:"";
position:absolute;
z-index:-1;
bottom:0;
left:0;
right:0;
height:calc(100% + 25px);
background-image:inherit;
-webkit-mask:
radial-gradient(farthest-side at top left , transparent 98%,#fff 100%) left,
radial-gradient(farthest-side at top right, transparent 98%,#fff 100%) right;
mask:
radial-gradient(farthest-side at top left , transparent 98%,#fff 100%) left,
radial-gradient(farthest-side at top right, transparent 98%,#fff 100%) right;
-webkit-mask-size:30px 25px;
mask-size:30px 25px;
-webkit-mask-position:calc(50% - 15px) 0,calc(50% + 15px) 0;
mask-position:calc(50% - 15px) 0,calc(50% + 15px) 0;
-webkit-mask-repeat:no-repeat;
mask-repeat:no-repeat;
}
body {
background:pink;
}
<div class="box">text here</div>
<div class="box" style="
background-image:linear-gradient(160deg,white,red,black,orange);">more and more text here</div>
<div class="box" style="
background-image:linear-gradient(180deg,blue 20%,violet 20%,black);">2 lines <br>of text</div>
you can use the shadow on both rounded pseudos
.bubble {
position: relative;
background: #00aabb;
border-radius: 0.4em;
width: 200px;
height: 100px;
}
.bubble:after,
.bubble:before {
content: "";
position: absolute;
height: 3em;
width: 3em;
border-radius: 50%;
top: 100%;
margin: -1px;
}
:after {
left: 50%;
box-shadow: -0.8em -1.4em 0 -0.5em #00aabb
}
:before {
right: 50%;
box-shadow: 0.8em -1.4em 0 -0.5em #00aabb;
}
<div class='bubble'></div>
to understand how it works, give a background to the pseudo and another color to the shadows. You'll be able to reproduce for the sides or the top. It's a matter of the circle size and shadow's size and direction.
One option is to create a normal rectangle and then position two circles over it, such that they create a curved point.
In the demo below, this rectangle is represented by the .point div, and the circles are represented by the pseudo-elements ::before and ::after.
.caption {
position: relative;
width: 350px;
margin-top: 40px;
}
.caption>.content {
width: 100%;
height: 100%;
padding: 10px;
box-sizing: border-box;
border-radius: 30px;
background-color: green;
color: white;
text-align: center;
}
.caption>.point {
position: absolute;
left: 50%;
top: -30px;
width: 30%;
height: 30px;
transform: translateX(-50%) translateZ(1px);
overflow: hidden;
background-color: green;
}
.caption>.point::before,
.caption>.point::after {
content: '';
display: block;
width: 100%;
height: 200%;
position: absolute;
top: 0;
left: 0;
border-radius: 100%;
background-color: white;
}
.caption>.point::before {
transform: translateX(-49%) translateY(-50%);
}
.caption>.point::after {
transform: translateX(49%) translateY(-50%);
}
<div class="caption">
<div class="point"></div>
<div class="content">This is some text!</div>
</div>
Here is a more visual demonstration of what the code is actually doing. The ::before and ::after elements are represented by the red circles. I've reduced the transparency of their fill to 50% so you can see which portion of the .point div they're cutting off.
.caption {
position: relative;
width: 350px;
margin-top: 40px;
}
.caption>.content {
width: 100%;
height: 100%;
padding: 10px;
box-sizing: border-box;
border-radius: 30px;
background-color: green;
color: white;
text-align: center;
}
.caption>.point {
position: absolute;
left: 50%;
top: -30px;
width: 30%;
height: 30px;
transform: translateX(-50%) translateZ(1px);
background-color: green;
}
.caption>.point::before,
.caption>.point::after {
content: '';
display: block;
width: 100%;
height: 200%;
position: absolute;
top: 0;
left: 0;
border-radius: 100%;
background-color: rgba(255,255,255,0.5);
border: 1px solid red;
}
.caption>.point::before {
transform: translateX(-49%) translateY(-50%);
}
.caption>.point::after {
transform: translateX(49%) translateY(-50%);
}
<div class="caption">
<div class="point"></div>
<div class="content">This is some text!</div>
</div>
I am having trouble centering the arrow inside the red circle.
How can I center one fixed element inside another fixed element?
JsFiddle: https://jsfiddle.net/sebastian3495/xtj9cga2/4/
Code
html, body {
height: 1000px;
width: 100%;
}
#a {
width: 100%;
height: 100%;
border: 1px solid black;
position:relative;
}
#wrapper {
position: absolute;
top: 50vh;
}
#b {
width: 100px;
height: 100px;
border-radius: 50%;
background: red;
position: fixed;
}
#c {
border: solid black;
border-width: 0 3px 3px 0;
position: fixed;
width: 50px;
height: 50px;
transform: rotate(-45deg);
}
<div id="a">
<div id="wrapper">
<i id="b"></i>
<i id="c"></i>
</div>
</div>
You can simply your code like below then you can easily center your arrow and also adjust the dimension:
.arrow {
background:red;
width:100px;
height:100px;
border-radius:50%;
position:fixed;
top:100px;
left:50px;
}
.arrow::before {
content:"";
position:absolute;
top:50%;
left:50%;
width:50%;
height:50%;
border-top:3px solid;
border-right:3px solid;
/*75% instead of 50% since we need to center half the shape so 50% then 25%*/
transform:translate(-75%,-50%) rotate(45deg);
}
<div class="arrow"></div>
You can still simplify more without pseudo element:
.arrow {
width:100px;
height:100px;
padding:35px 35px 0 0;
border-radius:50%;
position:fixed;
top:100px;
left:50px;
background:
linear-gradient(#000,#000) top right/77% 3px,
linear-gradient(#000,#000) top right/3px 77%,
red;
background-repeat:no-repeat;
background-origin:content-box;
transform:rotate(45deg);
box-sizing:border-box;
}
<div class="arrow"></div>
adjust top and left position for i tag with id="c"
#c {
border: solid black;
border-width: 0 3px 3px 0;
position: fixed;
width: 50px;
height: 50px;
left:3%;
top:60vh;
transform: rotate(-45deg);
}
need help creating the shapes above with the curved rectangular angles...to insert images inside i can do that ...can someone help me out ...please...
I have tried using border-radius to selectively chose the edge i want rectangular
.curv {
width: 800px;
margin: 0 auto;
position: relative;
padding-top: 100px;
overflow: hidden;
}
.curv:before {
background: #333;
height: 200px;
left: -20px;
right: 0px;
top: 0px;
content: '';
position: absolute;
border-radius: 0% 0 0 0;
clip-path: polygon(53% 0, 100% 49%, 57% 100%, 0% 100%, 0 47%, 0% 0%);
}
.holder {
height: 200px;
background: #333;
position: relative;
z-index: 9999;
}
<div class="curv">
<div class="holder"></div>
</div>
I would use some pseudo element and the same background-image twice.
Here is an example (missing only one curve):
body {
background:pink;
}
.box {
margin:100px;
width:200px;
height:100px;
border-right:3px solid green;
border-bottom:3px solid green;
border-radius:0 0 10px 10px;
background:
url(https://lorempixel.com/200/150/) bottom;
position:relative;
}
.box:before {
content:attr(data-text);
color:#000;
font-weight:bold;
text-shadow:0px 0px 5px #fff;
text-align:center;
position:absolute;
height:50px;
top:-53px;
right:-3px;
width:50%;
background:
url(https://lorempixel.com/200/150/) top right;
border:3px solid green;
border-bottom:none;
border-radius:10px 10px 0 0;
}
.box:after {
content:"";
position:absolute;
left:-3px;
width:50%;
bottom:-3px;
height:100px;
border:3px solid green;
border-right:none;
border-radius:10px 0 0 10px;
}
<div class="box" data-text="SOME TEXT">
</div>
I am able to make a normal square div and a triangle div in CSS. But I don't know how to make such a shape with a single div. Can anyone help me out ?
Also I want this to spread to the entire width of it's parent but border properties don't support percentages. ( eg border-left: 160px solid transparent; )
.container{
width: 100%;
position: relative;
}
.v-div {
width: 0;
height: 0;
border-left: 160px solid transparent;
border-right: 160px solid transparent;
border-top: 100px solid #f00;
}
.box{
height: 80px;
width: 320px;
background: red;
}
<div class="container">
<div class="box">
</div>
<div class="v-div">
</div>
</div>
you can use clip path css property
#clippedDiv{
width:200px;
height:200px;
background-color:red;
-webkit-clip-path: polygon(50% 0%, 100% 0, 100% 35%, 50% 70%, 0 35%, 0 0);
clip-path: polygon(50% 0%, 100% 0, 100% 35%, 50% 70%, 0 35%, 0
}
<div id="clippedDiv"></div>
for more shapes you can visit http://bennettfeely.com/clippy/
you can do it with :after pseudo classes. If you uncomment the :before in this example you get a hexagon
#hexagon{
position: relative;
height:100px;
width:50%;
color: white;
background: green;
padding-bottom: 15%;
overflow:hidden;
background-clip: content-box;
}
#hexagon:after {
content: "";
position: absolute;
top:100px;
left: 0;
background-color:green;
padding-bottom: 50%;
width: 57.7%;
transform-origin: 0 0;
transform: rotate(-30deg) skewX(30deg);
}
<div id="hexagon"></div>
use :after css selector.
.container{
width: 100%;
position: relative;
margin-top: 100px;
}
.box {
width: 100px;
height: 55px;
background: red;
position: relative;
}
.box:after {
content: "";
position: absolute;
bottom: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 25px solid red;
}
<div class="container">
<div class="box">
</div>
</div>
<svg width="12cm" height="4cm" viewBox="0 0 1200 400"
xmlns="http://www.w3.org/2000/svg" version="1.1"><polygon fill="lime" stroke="blue" stroke-width="10" points="850,75 958,137.5 958,262.5 850,325 742,262.6 742,137.5" /></svg>