We're trying to create an HTML page that consists of masonry-style floated elements that contain a picture and title. The elements have a shadow and the page has a slight gradient background. Targets that have already been visited have a folded corner.
The folded corner causes a couple of problems:
1) How can we make the element's box-shadow end before the folded corner on the right and bottom sides? Will we have to do the shadows the pre-CSS3 way with divs containing semi-transparent gradients?
2) How to do the folded corner itself? We can't just impose an image on the right bottom corner on top of the white background, because the page's background gradient must show through.
So far, I've thought of four ways of doing this:
Method 1: The idea behind this one is to use two pseudo-elements on the .box to get the corner and then two pseudo-elements on the .box-text to get the shadows in the corners right - demo. The biggest problem with this one is that it is... well, ugly.
HTML structure:
<div class="box">
<header></header>
<div class="box-text">
<p>Text</p>
</div>
</div>
Relevant CSS:
body {
background: #ccc;
}
.box {
box-shadow: 2px 2px 13px #000;
position: relative;
background: white;
}
.box:before, .box:after, .box-text:before, .box-text:after {
position: absolute;
content: '';
}
.box:before {
bottom: -25px;
right: -25px;
width: 75px;
height: 75px;
background: #ccc;
}
.box:after {
bottom: 0;
right: 0;
width: 50px;
height: 50px;
box-shadow: -2px -2px 2px #777;
background: linear-gradient(-45deg, transparent 38%, #333 50%, #faf0f0 50%);
}
.box-text:before {
bottom: 32px;
right: -15px;
width: 15px;
height: 18px;
background: radial-gradient(top left, #333 0%, transparent 40%);
}
.box-text:after {
bottom: -15px;
right: 32px;
width: 18px;
height: 15px;
background: radial-gradient(top left, #333 0%, transparent 40%);
}
Method 2: combine shadows in a nicer manner using a skewed pseudo-element for that particular corner (I would have shadows on the pseudo-element) - demo
I think this one looks nicer and also has the advantage of working in IE9 as well (the previous one didn't, since it made use of CSS gradients).
The HTML would be exactly the same and the CSS would become:
.box {
box-shadow: 0 0 5px 1px #777;
position: relative;
background: white;
}
.box:before, .box:after, .box-text:before {
position: absolute;
z-index: 2;
content: '';
}
.box:before {
bottom: -38px;
right: -38px;
width: 71px;
height: 71px;
transform: rotate(45deg);
z-index: 1;
background: #ccc;
}
.box:after {
bottom: 0;
right: 0;
border: solid 23px #f9f0f0;
border-bottom-color: transparent;
border-right-color: transparent;
box-shadow: -1px -1px 2px #777;
z-index: 4;
}
.box-text:before {
right: 0;
bottom: 22px;
width: 47px;
box-shadow: 2px 2px 3px 1px #777;
transform: skewY(-45deg);
}
Method 3: I got an idea from the previous method - demo. I think the previous one looks slightly nicer though...
CSS that has changed:
.box:before {
bottom: -24px;
right: -7px;
width: 35px;
height: 70px;
box-shadow: inset 2px 0 3px 1px #999;
transform: rotate(45deg);
z-index: 1;
background: #ccc;
}
.box:after {
bottom: 0;
right: 0;
border: solid 23px #f9f0f0;
border-bottom-color: transparent;
border-right-color: transparent;
box-shadow: -1px -1px 2px #777;
z-index: 4;
}
.box-text:before {
bottom: -27px;
right: -10px;
width: 35px;
height: 70px;
transform: rotate(45deg);
background: #ccc;
}
Method 4: Uses just 2 pseudo-elements, both on the box - demo
.box:before, .box:after {
position: absolute;
z-index: 2;
content: '';
}
.box:before {
right: -8px;
bottom: 22px;
width: 65px;
box-shadow: 2px 2px 5px 1px #777, 0 25px 0 25px #ccc;
transform: rotate(-45deg);
}
.box:after {
bottom: 0;
right: 0;
border: solid 23px #f9f0f0;
border-bottom-color: transparent;
border-right-color: transparent;
box-shadow: -1px -1px 2px #777;
z-index: 4;
}
Related
I am trying to create a box-shadow with two different colours horizontally of a line. Is there any way to do it instead of box-shadow? I am trying to build the inner design of the screen.
.neon-rod
{
position: relative;
height: 0.2vmin;
width: 25vmin;
background: red;
left: 50vmin;
box-shadow:
0.2vmin 0 0 0.1vmin #69e;
}
<div class="neon-rod"></div>
Reference Image
Above is the reference image of the design.
Codepen:- https://codepen.io/himanshu-pal/pen/vYejNZW
I have increased the blur and spread of box-shadow property
.neon-rod
{
position: relative;
height: 5px;
width: 100px;
background: red;
left: 50vmin;
box-shadow:
0 0 8px 4px #69e;
}
<div class="neon-rod"></div>
With :before
.neon-rod {
position: relative;
height: 5px;
width: 100px;
background: #69e;
left: 50vmin;
box-shadow: 0 0 8px 4px #69e;
}
.neon-rod:before {
content: "";
position: absolute;
width: 90%;
background: #0f0;
left: 5px;
right: 5px;
top: 3px;
bottom:3px;
box-shadow: 0 0 3px 2px #0f0;
}
<div class="neon-rod"></div>
More details:
https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow
You can add more than one box-shadow and use different colors for each. Just separate the shadows with a comma.
.neon-rod
{
position: relative;
height: 1vmin;
width: 25vmin;
background: red;
left: 50vmin;
top: 10vmin;
box-shadow:
0.2vmin 0.3vmin 1.6vmin #69e8,
0.3vmin 0.4vmin 3.2vmin #69ea,
0.3vmin 0.4vmin 4.8vmin #69ec,
0.3vmin 0.4vmin 6.4vmin #69ef,
-0.2vmin -0.3vmin 0.8vmin green;
}
<div class="neon-rod"></div>
This question already has answers here:
Cut Corners using CSS
(16 answers)
Closed 2 years ago.
I'm struggling to replicate the button style as in the image below. I've tried using clip path but I'm not getting the desired effect where there is a visible border and a semitransparent background.
Is there a simple workaround for this?
https://i.stack.imgur.com/kI5eX.png
Your idea to use clip-path should work out. Here's an approach
a {
position: relative;
display: inline-block;
padding: 10px 20px;
background-color: rgba(255, 0, 0, .3);
box-shadow: inset 0 0 0 3px red;
clip-path: polygon(0 0, calc(100% - 20px) 0, 100% 20px, 100% 100%, 20px 100%, 0 calc(100% - 20px));
}
a:before,
a:after {
content: '';
position: absolute;
width: 3px;
height: 30px;
background-color: red;
}
a:before {
left: 0;
top: 100%;
transform-origin: 50% 0%;
transform: translateY(-20px) rotate(-45deg);
}
a:after {
right: 0;
bottom: 100%;
transform-origin: 50% 100%;
transform: translateY(20px) rotate(-45deg);
}
Start my free session
The only issue with this solution is the support for clip-path https://caniuse.com/?search=clip-path
Here's a codepen https://codepen.io/Hornebom/pen/912d2557034ba9c3936a06ced8584de4
To achieve an exact copy of this image the background needs to be an svg image.
however if your background is solid you can do the trick with just css like this
button {
background-color: #bb000077;
border: 2px solid #ff6666;
font-weight: bold;
color: #fff;
font-size: 20px;
padding: 15px 25px;
position: relative;
outline: none;
}
button::before,
button::after {
content: '';
pointer-events: none;
position: absolute;
width: 29px;
height: 29px;
background-color: #fff;
transform: rotate(45deg);
}
button::after {
top: -16px;
right: -16px;
border-bottom: 2px solid #ff6666;
}
button::before {
bottom: -16px;
left: -16px;
border-top: 2px solid #ff6666;
}
<button>Start my free session</button
I am trying to create a css design like the image attached below. Actually I need to create this style only using CSS without using any images.
I tried get it to work but not sure How to create inner triangle.
This is my HTML -
body {
background: #cdc6e1;
}
.content-box {
background: #28166f;
width: 250px;
height: 100px;
}
.tag {
background: #f8c300;
width: 100px;
height: 0;
padding-left: 10%;
padding-bottom: 10%;
overflow: hidden;
}
.tag:after {
content: "";
display: block;
width: 0;
height: 0;
margin-left: -500px;
border-left: 500px solid transparent;
border-right: 500px solid transparent;
border-bottom: 500px solid #f8c300;
}
<div class="content-box">
<div class="tag">
<h1>1<span>st</span></h1>
</div>
<div class="name">
<h1>First<br>
Place</h1>
</div>
</div>
Hope somebody may help me out to achieve to this custom style.
Thank you.
A basic mockup would be to use some pseudo elements in order to generate this:
.outer {
height: 200px;
width: 400px;
background: purple;
border: 10px solid pink;
position: relative;
text-Align: right;
font-size: 50px;
line-height: 200px;
}
.outer:before,
.outer:after {
height: 0;
width: 0;
position: absolute;
content: "";
border-bottom: 100px solid yellow;
border-right: 70px solid transparent;
border-left: 70px solid transparent;
bottom: 0;
left: 20px;
z-index: 8;
}
.outer:after {
border-bottom: 130px solid blue;
border-right: 90px solid transparent;
border-left: 90px solid transparent;
z-index: 0;
}
.place {
position: absolute;
left: 50px;
color: red;
bottom: -20px;
font-size: 100px;
line-height: initial;
z-index: 10;
text-shadow:
3px 3px 0 white,
/* Simulated effect for Firefox and Opera
and nice enhancement for WebKit */
-1px -1px 0 white,
1px -1px 0 white,
-1px 1px 0 white,
1px 1px 0 white;
}
<div class="outer">First Place
<div class="place">1st</div>
</div>
Note. The text outline property is yet to be implemented in any of the major browsers yet, so it may require a 'larger white text' to be positioned behind to create this text outline in your mockup.
A workaround (as stateed in the comments) would be to 'hack' the text shadow:
text-shadow:
3px 3px 0 white, /* Simulated effect for Firefox and Opera
and nice enhancement for WebKit */
-1px -1px 0 white,
1px -1px 0 white,
-1px 1px 0 white,
1px 1px 0 white;
Text Stroke
Although only available in webkit broswers, you may possibly want to use text-stroke for your 'white border' to the text (unavailable in IE or Firefox)
div {
font-size: 50px;
position: relative;
height: 50px;
width: 50px;
color: black;
}
div:before {
content: "1st";
z-index: -1;
left: 0;
top: 0;
position: absolute;
-webkit-text-fill-color: black;
-webkit-text-stroke: 8px red;
}
html {
background: gray;
}
<div>
1st
</div>
<br/>
<strong>Note</strong> only available in webkit browsers
Create a duplicate triangle and place it behind. Code given below. JSBin: http://jsbin.com/totewinizu/2/
HTML:
.tag {
width: 100px;
display: block;
position: relative;
top: 20px;
border-color: transparent transparent red transparent;
border-style: solid;
border-width: 0px 60px 80px 60px;
height: 0px;
width: 0px;
z-index: 99;
}
.dupe {
position: absolute;
border-color: transparent transparent white transparent;
border-style: solid;
border-width: 0px 60px 80px 60px;
top: 40px;
left: 20px;
z-index: 9;
}
<div class="content-box">
<div class="tag">
<h1>1</h1><span>st</span>
</div>
<div class='tag dupe'>
</div>
<div class="name">
<h1>First<br>
Place</h1>
</div>
</div>
This question already has answers here:
Div with cut out edges, border and transparent background
(6 answers)
Closed 7 years ago.
What I want to achieve :
What I did so far is to make the corners as if it had the same color with the container and then cover the unneeded area with the "fake" square rotated by 45 deg.
I don't like that much the result, especially the bottom right corner and I can't thing another way to do it. What is the best way to achieve it ? Is it possible to be done with gradients ?
First Step : http://jsfiddle.net/laxmana/wjaAs/
Final : http://jsfiddle.net/laxmana/j9NWC/
CSS :
.chamfered-box{
width: 100%;
position: relative;
background: white;
border: 1px solid #149E4B;
}
.chamfered-box::before, .chamfered-box::after{
width: 0px;
height: 0px;
background: #fff;
content: '';
position: absolute;
bottom: 0;
}
.chamfered-box::after{
right: -1px;
bottom: -1px;
border-top: 10px solid #149E4B;
border-right: 10px solid white;
border-left: 10px solid #149E4B;
border-bottom: 10px solid white;
}
.chamfered-box::before{
left: -1px;
top: -1px;
border-top: 10px solid #149E4B;
border-right: 10px solid white;
border-left: 10px solid #149E4B;
border-bottom: 10px solid white;
}
.ch-top, .ch-bottom{position: absolute;z-index: 5;}
.ch-top{
top: -16px;
left: -18px;
width: 30px;
height: 30px;
background: white;
-webkit-transform: rotate(45deg);
}
.ch-bottom{
bottom: 5px;
right: 6px;
width: 28px;
height: 28px;
background: white;
-webkit-transform: rotate(45deg);
}
.ch-content{
padding: 20px;
}
HTML :
<div class="chamfered-box">
<div class="ch-top"></div>
<div class="ch-bottom"></div>
<div class="ch-content">The text</div>
</div>
You may use the pseudo element and rotate them on top(over) of the container with a little difference from your method.
Draw an inset shadow instead a border to your container.
Draw squares with a white background (as container) with borders.
Rotate the square and hide part of them overflowing from container.
DEMO
.chamfered-box{
margin:1em auto;
width: 440px;
padding:5px;
position: relative;
overflow:hidden;
background: white;
box-shadow: inset 0 0 0 1px #149E4B;
}
.chamfered-box::before, .chamfered-box::after{
width: 20px;
height: 20px;
background: #fff;
content: '';
position: absolute;
bottom: 0;
border: 1px solid #149E4B;
transform:rotate(45deg);
}
.chamfered-box::after{
right: -11px;
bottom: -11px;
}
.chamfered-box::before{
left: -11px;
top: -11px;
}
Does anyone know how to make edgy corners like in the following below? See how the edge wraps around the corner. I would like to know the term as well (if any). cross browser support (IE8 and up, bonus IE7) is a must. Thanks for any help.
Check out this tutorial. I don't know how crossbrowser compatible it is (as it is CSS3), but it achieves the effect you want.
HTML:
<div>
<h2></h2>
</div>
CSS:
div {
width: 200px;
padding: 50px;
margin: 0 auto;
border: 1px solid #333;
}
h2 {
position: relative;
width: 50%;
height: 50px;
margin: 30px 10px 10px -70px;
background-color: orange;
}
h2:after {
content: ' ';
position: absolute;
width: 0;
height: 0;
left: 0px;
top: 100%;
border-width: 5px 10px;
border-style: solid;
border-color: #666 #666 transparent transparent;
}
JS Fiddle Example
.box{
background: #666;
border: 4px solid #fff;
box-shadow: 0px 0px 20px #000;
width: 200px;
height: 200px;
margin: 40px auto;
position: relative;
}
.ribbon{
background: #FFA500;
position: absolute;
width: 100%;
top: 20px;
left: -20px;
height: 20px;
padding-right: 20px;
}
.ribbon::before{
content: '';
position: absolute;
left: 0px;
top: 20px;
width: 0px;
height: 0px;
border-style: solid;
border-width: 0 16px 10px 0;
border-color: transparent #FFA500 transparent transparent;
z-index: -5;
}
HTML:
<div class="box">
<div class="ribbon"></div>
</div>
(DEMO)
I don't think IE 7/8 support the ::before pseudo-element, so if you want IE compatibility add another element and put ::before styles on it :)
That edgy corner is only a div with a triangle actually, you only need ONE element to do it.
<div id="myCorner"></div>
myCorner will be the div, and myCorner:after will be the triangle.
Check it out : http://jsfiddle.net/Starx/Xp6E7/2/
#myCorner
{
width:100px;
height:70px;
background-color:orange;
-webkit-box-shadow: 0 4px 5px -3px black;
-moz-box-shadow: 0 4px 5px -3px black;
box-shadow: 0 4px 5px -3px black;
position:relative;
}
#myCorner:after
{
content:"";
position:absolute;
left: 0;
top:100%;
width: 0px;
height: 0px;
border-style:solid;
border-width: 5px 10px;
border-color: orange orange transparent transparent;
z-index: -1;
}