background color on polygon figure - css

I need to set the arrow white background on the same color of the background
,If I set the background on blue and the color on white ,the background non covered zone is white and It should be at the same color of the container background(some kind of grey)
Problem image
this is the arrow code
#arrow {
width: 120px;
height: 40px;
position: relative;
background: blue;
color: white;
padding-left: 25px;
padding-top: 5px;
}
#arrow:after {
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 0;
height: 0;
border-left: 20px solid white;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
}
#arrow:before {
content: "";
position: absolute;
right: -20px;
bottom: 0;
width: 0;
height: 0;
border-left: 20px solid blue;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
}
I'm not sure about how to fix it.

Here is an idea with multiple background:
.arrow {
padding:0 20px;
color:#fff;
font-size:25px;
width:120px;
text-align:center;
line-height:50px;
display:inline-block;
background:
/*right arrow*/
linear-gradient(to bottom left, transparent 49%,blue 50%) top right,
linear-gradient(to top left, transparent 49%,blue 50%) bottom right,
/*left arrow*/
linear-gradient(to bottom left, blue 49%,transparent 50%) top left,
linear-gradient(to top left, blue 49%,transparent 50%) bottom left,
blue content-box;
background-size:20px 50%;
background-repeat:no-repeat;
}
<div class="arrow">
some text
</div>

I made more simple with transform:skew() property. Solves the your problem exactly.
body {
background: #333;
padding:30px;
}
#arrow {
width: 120px;
height: 40px;
position: relative;
color:#fff;
font-size:22px;
display:flex;
align-items:center;
justify-content:center;
}
#arrow::before {
content:"";
width: 120px;
height: 20px;
position: absolute;
top:0;
left:0;
background:blue;
transform:skewX(40deg);
z-index:-1;
}
#arrow::after {
content:"";
width: 120px;
height: 20px;
position: absolute;
top:20px;
left:0;
background:blue;
transform:skewX(-40deg);
z-index:-1;
}
<div id="arrow">Section</div>

Related

How to do a rounded trapeze inside another trapeze with css

I need help with this problem
I want to do with css a figure like this:
I want to do a trapeze with a "rounded" protuberance in the middle.
I tried to put a trapeze back with z-index 0 an the other rounded with z-index 1, but i couldn't. Another solution for me was using svg but neither, it complicated me more.
Thanks for your help.
I tried to do this:
<style>
.left {
height: 66px;
background: blue;
float: left;
position: relative;
border-top-right-radius: 19px;
width: 370px;
}
.left:after {
content: '';
position: absolute;
right: -23.5px;
bottom: 0px;
border-top: rgba(255,255,255,0.1) 56px solid;
border-left: 26px solid #0000ff;
width: 0;
z-index: 1;
}
#trapezoid {
border-bottom: 100px solid #0000ff;
border-right: 50px solid transparent;
height: 0;
width: 330px;
}
`
You can use skew transformation like follow:
.box {
height:100px;
margin-right:50px;
position:relative;
z-index:0;
transform:skew(25deg);
transform-origin:bottom left;
}
.box:before {
content:"";
position:absolute;
top:0;
left:0;
right:20px;
bottom:50%;
background:green;
}
.box:after {
content:"";
position:absolute;
top:50%;
left:0;right:0;bottom:0;
background:green;
border-top-right-radius:20px;
}
body {
margin:0;
}
<div class="box"></div>
Reduce the width of trapezoid
.left {
height: 66px;
background: blue;
float: left;
position: relative;
border-top-right-radius: 19px;
width: 370px;
}
.left:after {
content: '';
position: absolute;
right: -23.5px;
bottom: 0px;
border-top: rgba(255,255,255,0.1) 56px solid;
border-left: 26px solid #0000ff;
width: 0;
z-index: 1;
}
#trapezoid {
border-bottom: 80px solid #0000ff;
border-right: 50px solid transparent;
height: 0;
width: 300px;
}
<div id="trapezoid"></div>
<div class="left"></div>

CSS - Creating a custom arrow

Hi I am trying to create a custom arrow in CSS that looks like the image below.
Ideally I want to create this by overlaying two shapes a triangle and a rectangle (maybe using CSS :after and :before) but I'm not too savvy when it comes to CSS so I have been struggling.I started by just using borders but doesn't look like it is going to work
So far I just have:
.arrow {
width: 0;
height: 0;
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
border-left: 60px solid #ccc;
}
<div class="arrow"></div>
Not too hard to make using the :before pseudo element and some transforms:
.container {
padding: 100px;
}
.arrow {
display: inline-block;
height: 150px;
background: #000;
width: 75px;
}
.arrow:before {
content: "";
border-top: 100px solid #000;
border-left: 100px solid transparent;
border-right: 100px solid transparent;
border-bottom: 100px solid transparent;
transform: rotateZ(180deg) translateY(100%) translateX(31%);
position: relative;
display: inline-block;
}
<div class="container">
<div class="arrow"></div>
</div>
Here's another option.
.arrow{
width: 0;
height: 0;
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
border-left: 60px solid #ccc;
position: relative;
margin: 0 0 0 100px;
}
.arrow::before{
content: "";
height:50px;
width:80px;
background: #ccc;
position: absolute;
top: 0;
margin: -100%;
display: block;
transform: translateX(-160%) translateY(-50%);
}
<div class="arrow"></div>
Create one rectangle and then add triangle on top with :before pseudo-element and that is it.
.arrow {
width: 36px;
height: 50px;
background: #3F3F3F;
position: relative;
margin: 60px;
}
.arrow:before {
content: '';
border-style: solid;
border-width: 0 40px 40px 40px;
border-color: transparent transparent #3F3F3F transparent;
position: absolute;
top: 0;
left: 50%;
transform: translate(-50%, -100%);
}
<div class="arrow"></div>
To explain and demonstrate:
A CSS arrow is created by coloring 1 border side, and then moving the other 3 sides in towards the middle of the shape as transparent so they don't show but cut the remaining colored side into a triangle. The shorthand for this is TOP RIGHT BOTTOM LEFT. So to make a triangle pointing upwards you use the third property or bottom.
Using pseudo elements (incase you want the arrow added to another element) you need content:'' to "create" the pseudo element. I've set them as display: block so that they are in the flow and interact with eachother (rather than being laid on top of one another).
By giving the rectangle position: relative you can then use left: 30px (half of the triangle width) to position it in the middle of the triangle.
.arrowWrapper:before {
content: '';
display: block;
width: 0;
height: 0;
border-style: solid;
border-width: 0 60px 60px 60px;
border-color: transparent transparent black transparent;
/* border-color: TOP RIGHT BOTTOM LEFT; */
}
.arrowWrapper:after {
content: '';
position: relative;
display: block;
width: 60px;
height: 60px;
background: black;
left: 30px;
}
<div class="arrowWrapper"></div>
Lifted and modified from http://www.cssportal.com/css3-shapes/:
#eq-triangle {
width: 0;
height: 0;
border-bottom: 104px solid blue;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
}
#rectangle {
width: 40px;
height: 80px;
background: blue;
margin-left: 40px;
}
<div id="eq-triangle"></div>
<div id="rectangle"></div>

How to create custom shapes with pseudo classes in CSS3

I am trying to create an element using Bootstrap that looks like this image
This is the screen shot of how far I have gone
I have never worked on pseudo classes and am finding it very difficult to get the exact shape. Please take a look at my code and help me figure it out. I have included only the second (thee one on the right side in the screenshot) clipboard's code here.
HTML
<div class="col-xs-12 col-sm-6">
<div class="clip">
<div class="circle"></div>
</div>
<div class="pad">
<div class="paper"></div>
</div>
</div>
CSS
.clip, .circle{
position: relative;
}
.clip::after, .clip::before, circle:after, .circle:before{
display: block;
position: absolute;
content: "";
z-index: 50;
}
.clip:before{
top: 12.5px;
left: 15%;
width: 70%;
border-bottom: solid 50px grey;
border-left: solid 150px transparent;
border-right: solid 150px transparent;
}
.clip:after{
top: 60px;
left: 15%;
width: 70%;
border-bottom: solid 55px grey;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
.circle:before{
top: 10px;
left: 70%;
width: 20%;
height: 50px;
border-radius: 50%;
border-right: solid 150px yellow;
}
because there is no SVG tag, i'll go with pseudo & gradient :
div {
position:relative;
float:left;
margin:60px 60px 80px;
width:180px;
height:200px;
border-radius:15px;
background:white;
box-shadow:/* draw inside part of border */0 0 0 20px #159E91, inset -1px -1px 1px;
}
div:before {/*to draw outside part of border with same radius inside/out */
z-index:-1;
border-radius:20px;
content:'';
border: 20px solid #159E91;
position:absolute;
top:-30px;
left:-30px;
right:-30px;
bottom:-30px;
box-shadow:0 -2px 2px rgba(30, 162, 149, 0.2), 0 0 2px white, 0 5px 5px -3px rgba(0,0,0,0.5)
}
div:after {/* draw gradient underneath clipper */
content:'';
position:absolute;
top:0;
border-radius: 0 15px 0 0;
left:26px;
width:152px;
height:150px;
background:
linear-gradient(45deg, white 40%, rgba(255,255,255,0) 40% ),/* mask*/
linear-gradient(-45deg, white , transparent 70%),/* mask*/
linear-gradient(to right , rgba(0,0,0,0.25) , rgba(0,0,0,0.15)),transparent ;
}
.clipper {/* hold clipper shape actually */
display:block;
width:128px;
height:80px;
margin: -52px auto 30px;
position:relative;
z-index:1;
overflow:hidden;
}
.clipper b {/* show the clipper shape */
border-radius:35px;
position:absolute;
height:150%;
width:100%;
box-shadow: 0 0 1px 1px gray;
left:50%;
top:-12px;
transform-origin:0 0;
transform:rotate(45deg);
overflow:hidden;
}
.clipper b:before {/* draw the hoe and paint around it */
content:'';
display:block;
border-radius:100%;
height:29px;
width:29px;
margin:20px;
box-shadow:inset -1px -1px 1px gray, 0 0 0 100px #3B3B3B, inset 1px 1px 2px rgba(0,0,0,0.5);
}
/* to match fake picture's text */
.clipper ~ span {
display:block;
background:#353535;
margin:10px 58px;
padding:5px;
position:relative;
z-index:1;
}
.clipper ~ span:last-of-type {
display:block;
background:#353535;
margin:10px 85px 10px 58px;
}
<div>
<span class="clipper"><b></b></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
but that's really much CSS for just a shape, where an image or an SVG would do fine for the design.
You can play with it here : http://codepen.io/gc-nomade/pen/rLYYZx
https://jsfiddle.net/ahe128/esmrLzuv/5/
i did something but this is realy hard work i will try complete this :)
.clip,
.circle {
position: relative;
}
.clip::after,
.clip::before,
circle:after,
.circle:before {
display: block;
position: absolute;
content: "";
z-index: 50;
}
.clip:before {
top: 1rem;
left: 10%;
width: 20%;
border-bottom: solid 50px grey;
border-left: solid 150px transparent;
border-right: solid 150px transparent;
}
.clip:after {
top: 4.65rem;
left: 10%;
right:10%;
width: 82%;
border-bottom: solid 4.3rem grey;
border-top-left-radius: 0.8rem;
border-top-right-radius: 0.8rem;
border-bottom-left-radius: 0.4rem;
border-bottom-right-radius: 0.4rem;
}
.circle:before {
top: 0.78rem;
height: 1px;
width:1px;
border-radius: 50%;
border: solid 25px white;
z-index:100;
left:47%
}
Finally.......I got it working (except the diagonal gradient). But it's not responsive yet. My aim is to keep each Clipboard's design intact and stack them one below the other in small screens. Can someone please point out where I'm missing it !!
Also, if there's a better way of doing it in Pure CSS then I'd love to see it.
Fiddle: https://jsfiddle.net/chandannadig/esmrLzuv/7/
/*Clip*/
.clip, .circle{
position: relative;
}
.clip::after, .clip::before, circle:after, .circle:before{
display: block;
position: absolute;
content: "";
}
.clip:before{
z-index: 50;
top: 1rem;
left: 6.958rem;
width: 29rem;
border-bottom: solid 4rem grey;
border-left: solid 11.5rem transparent;
border-right: solid 11.5rem transparent;
}
.clip:after{
top: 4.7rem;
left: 6.958rem;
width: 29rem;
z-index: 50;
border-bottom: solid 4rem grey;
border-top-left-radius: 0.8rem;
border-top-right-radius: 0.8rem;
border-bottom-left-radius: 0.5rem;
border-bottom-right-radius: 0.5rem;
}
.circle{
position: absolute;
z-index: 60;
top: 0.4rem;
left: 15.6rem;
width: 12rem;
height: 8rem;
background: grey;
border-radius: 50%;
}
.circle::before{
z-index: 60;
top: 1rem;
left: 4.2rem;
width: 3.5rem;
height: 3.5rem;
background: white;
border-radius: 50%;
}
/*End of Clip*/

How to create a border that fully covers the adjacent corners in CSS?

I have a div with a 1px border and I'm trying to create a 3px border in another color to that div. I'm using this code:
box {
border: 1px solid #ddd;
border-top: 3px solid #3F9BD0;
}
but at the corners the border is not good, see image:
How can I make this border look good, like this:
fiddle: https://jsfiddle.net/15tory3z/
Instead of border-top, try using the :after pseudo-element to recreate the effect you want.
.box {
width: 200px;
height: 100px;
border: 1px solid #ddd;
position: relative;
}
.box:after {
position: absolute;
content: "";
width: 100%;
height: 5px;
top: -5px;
background: dodgerblue;
padding: 1px;
left: -1px;
}
<div class="box"></div>
Choice 2:
Use linear-gradient().
.box {
width: 200px;
height: 100px;
border: 1px solid #ddd;
background: -webkit-linear-gradient(top, dodgerblue 5%, #fff 5%);
background: -moz-linear-gradient(top, dodgerblue 5%, #fff 5%);
background: -o-linear-gradient(top, dodgerblue 5%, #fff 5%);
background: -ms-linear-gradient(top, dodgerblue 5%, #fff 5%);
background: linear-gradient(top, dodgerblue 5%, #fff 5%);
}
<div class="box"></div>
You could draw these with inset shadows and padding :
div {
padding:12px 5px 5px;
width: 40%;
height: 200px;
box-shadow: inset 0 10px #3F9BD0, inset 4px 0 gray, inset -4px 0 gray, inset 0 -4px gray
}
<div></div>
or just an outset top shadow
div {
width: 40%;
height: 200px;
border:2px solid gray;
border-top:none;
box-shadow: 0 -10px #3F9BD0;
margin-top:12px;
}
<div></div>
else, background gradient could be used and even animated 2 examples : http://codepen.io/gc-nomade/pen/IGliC or http://codepen.io/gc-nomade/pen/pKwby
This also puts a line on top:
.box1 {
border: 10px solid #ddd;
border-top: 0;
box-shadow: 0 -30px 0 #3F9BD0;
float: left;
width: 300px;
height: 300px;
}
<div class="box1"></div>
Use css :after pseudo-class, docs
.box_big {
border: 10px solid #ddd;
position:relative;
z-index: 1;
}
.box_big:after{
height: 10px;
position: absolute;
top:-10px; left:-10px; right:-10px;
content: " ";
z-index: 2;
background: red;
}
.box {
border: 1px solid #ddd;
position:relative;
z-index: 1;
}
.box:after{
height: 3px;
position: absolute;
top:-3px; left:-1px; right:-1px;
content: " ";
z-index: 2;
background: red;
}
<div class="box_big">
big box
</div>
<hr />
<div class="box">
your box
</div>
Welcome to the css borders. The only way to properly do that is using :after or :before pseudoelements.
Fiddle
.box {
border: 1px solid #ddd;
position: relative;
}
.box:after {
position: absolute;
display: block;
content:'';
/* Positioning */
top: 0;
width: 100%;
height: 3px;
left: 0;
right: 0;
/* Color */
background-color: #3F9BD0;
}
Try this:
.box {
outline: 2px solid #ddd;
margin-top: -2px;
border-top: 10px solid #3F9BD0;
min-width:100px;
min-height:100px;
float:left;
}
<div class="box"></div>
The question is a bit old but I thought I'd make a suggestion that worked for me in a similar situation.
I just set border-width: 0; and that took away the mitered ends and made them nice and square for a button that I had a bottom-border applied.

Reproduce image shape using CSS

I'm trying to reproduce this image using only css
I've played with the radius property but as you will see I don't get the same angle effect.
.shape{
background-color: black;
opacity:0.9;
filter:alpha(opacity=90); /* For IE8 and earlier */
color:white;
font-weight:bold;
padding: 30px 30px 30px 50px;
text-align:center;
position:absolute;
right:0;
bottom:0;
z-index:1003;
font-size: 20px;
border-top-left-radius: 125px;
-moz-border-radius-topright: 125px;
}
​
You can see what I've tried at http://jsfiddle.net/ymorin007/7qX4U/
Thanks.
Might not be cross-browser compatible, but this'll get you close :)
.shape{
background-color: black;
opacity:0.9;
filter:alpha(opacity=90); /* For IE8 and earlier */
color:white;
font-weight:bold;
padding: 30px 30px 30px 50px;
text-align:center;
position:absolute;
right:0;
bottom:0;
z-index:1003;
font-size: 20px;
border-top-left-radius: 125px;
-moz-border-radius-topright: 125px;
}
.shape::before{
content:"";
width:0;
height:0;
position:absolute;
left:-34px;
border-left: 53px solid transparent;
border-right: 53px solid transparent;
border-bottom: 53px solid black;
}
​
fiddle: http://jsfiddle.net/pggRb/
If you needed to hit test, you may want to consider using a skewed pseudo element:
div {
position: fixed;
bottom: 0;
right: 0;
height: 50px;
width: 200px;
background: gray;
cursor: pointer;
transition: all 0.6s;
}
div:before {
content: "";
position: absolute;
top: 0;
left: -50%;
width: 100%;
height: 100%;
background: inherit;
transform: skewX(-45deg);
border-radius: 20px 0 0 0;
z-index: -1;
}
div:hover {
background: tomato;
]
<div>SOME TEXT</div>

Resources