I'm trying to make a line that almost looks like it has serifs at the ends. Essentially, I want to make it wider at the very ends and thin in the middle, just using css. This has actually proven to be quite a challenge.
Any help would be appreciated.
Thus far I've been able to get the bottom to look how I want using the :after pseudo selector, but no luck with the top, which I can only seem to get concave, rather than convex.
Here's the code of what I've done so far
.line {
background:none;
height: 8px;
position:relative;
overflow:hidden;
z-index:1;
top: 50px;
left: 50px;
width: 140px;
box-shadow: 11px 12px 16px -3px rgba(0,0,0,0.6);
-webkit-transform: rotate(38deg);
transform: rotate(38deg);
}
.line:after {
content: '';
position: absolute;
left: 0%;
width: 100%;
padding-bottom: 10%;
top: 50%;
border-radius: 35%;
box-shadow: 0px 0px 0px 150px rgba(0,0,0,0.6);
z-index: -1;
}
.line:before {
content: '';
position: absolute;
left: 0%;
width: 100%;
padding-bottom: 8%;
top: -30%;
border-radius: 35%;
box-shadow: 0px 0px 0px 150px rgba(255,255,255, 1);
z-index: 24 !important;
}
and the HTML
<section class="stage">
<figure class="line"></figure>
</section>
Here's the fiddle of what I have thus far (also, I'm gonna need to rotate it for certain areas)
http://jsfiddle.net/speo9bfv/1/
Thanks for the help!
If you have a plain background color, you can do this with pseudo elements :
DEMO
HTML :
<section class="stage">
<figure class="line"></figure>
</section>
CSS :
.line {
height: 8px;
position:relative;
overflow:hidden;
z-index:1;
top: 50px;
left: 50px;
width: 140px;
-webkit-transform: rotate(38deg);
transform: rotate(38deg);
background:rgba(0,0,0,0.6);
}
.line:after, .line:before {
content:'';
position: absolute;
left:0;
width:100%;
height:100%;
border-radius: 35%;
background:#fff;
}
.line:after{
top:5px;
}
.line:before{
bottom:5px;
}
I would try using gradients to create the illusion of a pinched line.
black -> white -> black
black line
black -> white -> black
I wanted this to just be a comment, but I couldn't make new lines like I wanted.
Here's a fiddle for you:
http://jsfiddle.net/qaqafc6f/
Here is a better one, with rotate applied.
http://jsfiddle.net/qaqafc6f/2/
Note this does not use :before or :after, and is probably more cross-browser compatible (as long as you add the vendor prefixes).
If you need a transparency around this shape you could use two pseudo elements with a curved border-radius and multiple box-shadows to colour in the space between them:
.line {
height: 8px;
position:relative;
overflow:hidden;
z-index:1;
top: 50px;
left: 50px;
width: 140px;
-webkit-transform: rotate(38deg);
transform: rotate(38deg);
}
.line:after, .line:before {
content:'';
position: absolute;
left:-10px;
right:-10px;
height:100%;
border-radius: 50%;
background:transparent;
box-shadow: 0 0 1px 1px rgba(0, 0, 0, .5), 5px 0 0px 2px rgba(0, 0, 0, .5), -5px 0 0px 2px rgba(0, 0, 0, .5), 10px 0 0px 2px rgba(0, 0, 0, .5), -10px 0 0px 2px rgba(0, 0, 0, .5), 15px 0 0px 2px rgba(0, 0, 0, .5), -15px 0 1px 2px rgba(0, 0, 0, .5), 20px 0 0px 2px rgba(0, 0, 0, .5), -20px 0 0px 2px rgba(0, 0, 0, .5), 25px 0 0px 2px rgba(0, 0, 0, .5), -25px 0 0px 2px rgba(0, 0, 0, .5), 30px 0 1px 1px rgba(0, 0, 0, .5), -30px 0 1px 1px rgba(0, 0, 0, .5);
}
Or - if an inline svg datauri is acceptable - you could do something like:
.svg-stick {
margin-top:200px;
display:block;
width:140px;
height:8px;
background: transparent url(data:image/svg+xml;
base64, PD94bWwgdmVyc2lvbj0iM...etc...) center center no-repeat;
background-size:100% 100%;
-webkit-transform: rotate(38deg);
transform: rotate(38deg);
}
Both demoed here: http://jsfiddle.net/eqaL4g5q/
Related
This question already has answers here:
Responsive CSS triangle with percents width
(7 answers)
Closed 6 months ago.
I need to create the following form in CSS I tried it with after but I can't get the same result, can someone help me please.
Shape
.login-card{
position: absolute;
width: 394px;
height: 682px;
left: calc(50% - 394px/2);
top: 64px;
/* surface */
background: #FFFFFF;
/* 04 dp */
box-shadow: 0px 4px 5px rgba(0, 0, 0, 0.14), 0px 1px 10px rgba(0, 0, 0, 0.12), 0px 2px 4px rgba(0, 0, 0, 0.2);
border-radius: 10px;
}
.login-card:after {
content: "";
position: absolute;
top: 100%;
width: 60px;
height: 0;
border-style: solid;
border-width: 86px 197px 0 197px;
border-color: red transparent transparent transparent;
box-shadow: 0px 4px 5px rgba(0, 0, 0, 0.14), 0px 1px 10px rgba(0, 0, 0, 0.12), 0px 2px 4px rgba(0, 0, 0, 0.2);
}
<div class="login-card">
</div>
You could use a combination of clip-path and calc() to create the shape in the main element and use some padding to prevent content from falling into the triangle shape.
The main issue with this approach is the loss of the box-shadow when using clip-path but this can be fixed using CSS filters, as per this article: https://css-tricks.com/using-box-shadows-and-clip-path-together/
Here's this approach in action on your example:
.login-card {
--triangle-size: 100px;
position: absolute;
width: 394px;
height: 682px;
left: calc(50% - 394px/2);
top: 64px;
background: #fff;
border-radius: 10px 10px 0 0;
padding-bottom: var(--triangle-size);
clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--triangle-size)), 50% 100%, 0 calc(100% - var(--triangle-size)), 0 0);
}
/** Restore the shadows */
.login-card-wrap {
filter: drop-shadow(0px 4px 5px rgba(0, 0, 0, 0.14)) drop-shadow(0px 1px 10px rgba(0, 0, 0, 0.12)) drop-shadow(0px 2px 4px rgba(0, 0, 0, 0.2));
}
<div class="login-card-wrap">
<div class="login-card"></div>
</div>
Use clip-path and filter instead of box-shadow on the parent and it will follow the shape.
.login-card {
position: relative;
width: 394px;
height: 682px;
left: calc(50% - 394px/2);
top: 64px;
/* surface */
background: #FFFFFF;
/* 04 dp */
filter: drop-shadow(0px 1px 5px rgba(50, 50, 0, 0.5));
border-radius: 10px 10px 3px 3px;
}
.login-card:after {
content: "";
position: absolute;
top: 100%;
background: #fff;
width: 100%;
height: 100px;
clip-path: polygon(0 0, 48% 100%, 99% 0);
}
<div class="login-card"></div>
In an attempt to create shadows around custom shapes, I discovered the drop-shadow filter CSS property. However after having implemented it, I realised that it slowed the website down significantly.
I am therefore searching for an alternative to gain the same effect without compromising the load speed of the page.
The main content of the site is surrounded by a shadow-box wrapper using a box shadow, but this could not be used for the end section due to the transparent part of the background.
I am trying to achieve a shadow which resembles the shadow of the shadow-box.
Here is a jsFiddle illustrating how it currently looks
and here it can bee seen on the real site
HTML
<div class="container shadow-box no-padding"></div>
<div class="container justify-content-center">
<section class="light-bg end-section" id="portfolio"></section>
</div>
CSS
.container{
width:70%;
margin:auto;
}
.shadow-box{
background:green;
height:200px;
-webkit-box-shadow: 0px 0px 21px 8px rgba(0, 0, 0, 0.6) !important;
-moz-box-shadow: 0px 0px 21px 8px rgba(0, 0, 0, 0.6) !important;
-ms-box-shadow: 0px 0px 21px 8px rgba(0, 0, 0, 0.6) !important;
-o-box-shadow: 0px 0px 21px 8px rgba(0, 0, 0, 0.6) !important;
box-shadow: 0px 0px 21px 8px rgba(0, 0, 0, 0.6) !important;
}
.end-section {
background: radial-gradient(circle at 50% 100%, transparent 50px, #c1c1c1 50px);
z-index: 5;
height:200px;
filter: drop-shadow(0 30px 15px rgba(0, 0, 0, 0.6))
drop-shadow(0 10px 5px rgba(0, 0, 0, 0.6));
}
.light-bg:before {
content: '';
position: absolute;
z-index: 3;
top: -50px;
left: 50%;
margin-left: -50px;
height: 50px;
width: 100px;
border-top-left-radius: 100px;
border-top-right-radius: 100px;
background: #c1c1c1;
}
So according to this question Div with cut out edges, border and transparent background and the answer demo on codepen: http://codepen.io/web-tiki/pen/Dvgqn, how do you modify the codepen in the least number of code changes to also have the upper left and bottom right corners become cut out as well?
Here's the code from the codepen:
div{
position:relative;
width:50%;
height:300px;
margin:10% auto;
background:rgba(0, 0, 0, 0.7);
border-top:6px solid rgba(0, 0, 0, 0.8);
border-bottom:6px solid rgba(0, 0, 0, 0.8);
}
div:before, div:after{
content:'';
position:absolute;
top:-6px;
width:20%; height:100%;
}
div:before{
right:100%;
background:inherit;
border-top:6px solid rgba(0, 0, 0, 0.8);
border-left:6px solid rgba(0, 0, 0, 0.8);
border-bottom:6px solid rgba(0, 0, 0, 0.8);
-webkit-transform-origin:100% 0;
transform-origin:100% 0;
-webkit-transform : perspective(1px) rotateY(-0.15deg);
transform : perspective(1px) rotateY(-0.15deg);
}
div:after{
left:100%;
border-top:6px solid rgba(0, 0, 0, 0.8);
border-right:6px solid rgba(0, 0, 0, 0.8);
border-bottom:6px solid rgba(0, 0, 0, 0.8);
border-left:none;
background:inherit;
-webkit-transform-origin:0 100%;
transform-origin:0 100%;
-webkit-transform : perspective(1px) rotateY(0.15deg);
transform : perspective(1px) rotateY(0.15deg);
}
/*following just for demo */
body, html{
height:100%;
margin:0;
}
body{
background: url(http://lorempixel.com/output/people-q-c-640-480-1.jpg) no-repeat;
background-size:cover;
color:#fff;
font-size:1.2em;
font-family:arial;
}
And the placeholder div:
<div>
<h1>Title here</h1>
<p>some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here...</p>
</div>
I am not sure how exactly the answer to the aforementioned question even works, I just copy pasted it. Any insight would be amazing! Thank you so much, I will try to figure this out myself and keep you posted as well.
I was able to modify the angle of the edge cut by changing the degrees and perspective px, but am not sure what I need to add to make the cuts also appear on the upper left and bottom right. Will keep you posted!
Seems that simplifying the transform code works. Just change those 4 lines, and voila.
Precisely, this:
div:before {
-webkit-transform-origin:100% 0;
transform-origin:100% 0;
}
div:after {
-webkit-transform-origin:0 100%;
transform-origin:0 100%;
}
becomes this:
div:before {
-webkit-transform-origin: 100%;
transform-origin: 100%;
}
div:after {
-webkit-transform-origin: 0;
transform-origin: 0;
}
See it here: http://jsfiddle.net/ryanpcmcquen/pxm3beyL/
Full code:
div {
position: relative;
width: 50%;
height: 300px;
margin: 10% auto;
background: rgba(0, 0, 0, 0.7);
border-top: 6px solid rgba(0, 0, 0, 0.8);
border-bottom: 6px solid rgba(0, 0, 0, 0.8);
}
div:before,
div:after {
content: '';
position: absolute;
top: -6px;
width: 20%;
height: 100%;
}
div:before {
right: 100%;
background: inherit;
border-top: 6px solid rgba(0, 0, 0, 0.8);
border-left: 6px solid rgba(0, 0, 0, 0.8);
border-bottom: 6px solid rgba(0, 0, 0, 0.8);
-webkit-transform-origin: 100%;
transform-origin: 100%;
-webkit-transform: perspective(1px) rotateY(-0.15deg);
transform: perspective(1px) rotateY(-0.15deg);
}
div:after {
left: 100%;
border-top: 6px solid rgba(0, 0, 0, 0.8);
border-right: 6px solid rgba(0, 0, 0, 0.8);
border-bottom: 6px solid rgba(0, 0, 0, 0.8);
border-left: none;
background: inherit;
-webkit-transform-origin: 0;
transform-origin: 0;
-webkit-transform: perspective(1px) rotateY(0.15deg);
transform: perspective(1px) rotateY(0.15deg);
}
/*following just for demo */
body,
html {
height: 100%;
margin: 0;
}
body {
background: url(http://lorempixel.com/output/people-q-c-640-480-1.jpg) no-repeat;
background-size: cover;
color: #fff;
font-size: 1.2em;
font-family: arial;
}
<div>
<h1>Title here</h1>
<p>some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here some text here...</p>
</div>
So I played around with just the -webkit-transform-origin and transform-origin properties,
The only difference was to change
-webkit-transform-origin:100% 0;
transform-origin:100% 0;
to
-webkit-transform-origin:55% 0%;
transform-origin:100% 33%;
in div:before, and to change
-webkit-transform-origin:0 100%;
transform-origin:0 100%;
to
-webkit-transform-origin:0% 55%;
transform-origin:10 100%;
in the div:after
Here's the new codepen:
http://codepen.io/anon/pen/YyyXzE
I have code below. It has several divs and css code. The image pic size is about 45kb,small size. So, I want to know, should I use img directly or use the code below. Which one has the faster speed when page loading. Appreciate.
div.smileyface {
width: 300px;
height: 300px;
position: relative;
border-radius: 150px;
-webkit-border-radius: 150px;
-moz-border-radius: 150px;
display: block;
background: #ffe632;
background: -webkit-gradient(linear, left top, left bottom, from(#fffe8d), to(#f6d23e));
background: -moz-linear-gradient(top, #fffe8d, #f6d23e);
box-shadow: inset 0px -14px 14px rgba(0, 0, 0, .3), 0px 2px 20px rgba(0, 0, 0, .6);
-webkit-box-shadow: inset 0px -14px 14px rgba(0, 0, 0, .3), 0px 2px 20px rgba(0, 0, 0, .6);
-moz-box-shadow: inset 0px -14px 14px rgba(0, 0, 0, .3), 0px 2px 20px rgba(0, 0, 0, .6);
}
p.eyes {
width: 50px;
height: 80px;
background: #222;
border-radius: 100px/160px;
-webkit-border-radius: 100px 160px;
-moz-border-radius: 100px/160px;
position: absolute;
top: 40px;
box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
-webkit-box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
-moz-box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
}
p.eyes.lefteye {
left: 75px;
}
p.eyes.righteye {
right: 75px;
}
div.smile {
width: 200px;
height: 70px;
border: 10px solid #222;
border-top: 0;
background: rgba(0,0,0,0);
-moz-border-radius: 0 0 120px 120px / 0 0 90px 90px;
-webkit-border-radius: 0 0 120px 120px 0 0 90px 90px;
border-radius: 0 0 120px 120px / 0 0 90px 90px;
position: absolute;
bottom: 50px;
left: 38px;
box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
-webkit-box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
-moz-box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
}
div.corner {
width: 10px;
height: 30px;
background: #222;
border-radius: 100px/160px;
-webkit-border-radius: 100px 160px;
-moz-border-radius: 100px/160px;
position: absolute;
top: -12px;
-webkit-transform: rotate(65deg);
-moz-transform: rotate(65deg);
left: -12px;
}
div.corner.right {
left: 202px;
-webkit-transform: rotate(-65deg);
-moz-transform: rotate(-65deg);
}
<div class="smileyface">
<p class="eyes lefteye"></p>
<p class="eyes righteye"></p>
<div class="smile">
<div class="corner"></div>
<div class="corner right"></div>
</div>
</div>
According to YSlow, it is a best practice to Minimize HTTP Requests: use CSS sprites, avoid CSS images, combine files etc.
The overall goal should in the end be to optimize page weight, though.
Since the image is 45KB in this case, I would recommend the CSS solution - it is 2148 chars, which is 2KB. If all CSS is in one file, the CSS solution will save you 43KB and 1 HTTP request.
The CSS Solution might get even smaller with a tool such as FormatCSS and by minification.
45KB sounds like a very big file, unnecessary big even. Optimize Images could also be considered.
Here is a detailed explanation of what to use when. Hope it helps:
When to use IMG vs. CSS background-image?
I need to make this using only css and css3 drop shadows
Please help to make like this using css...
Image : http://technocodes.us/Lab/Html/vidbees/img/frame.png
ADDED MORE TO THE ANSWER:
I looked into this. I believe this is the solution. Not using images at all, only CSS.
This is not the full solution, but I believe this is the solution. You should get the idea and solution to run from from here I think:
This is the result:
(Here is the fiddle: http://jsfiddle.net/uwfL5azw/3/ )
Here is the place that inspired me, and I lend code from: http://www.themeshock.com/css-drop-shadow/
The HTML:
<div class="main-box">
<div class="box_shadow">Here is my content
<div class="sh_bottom"></div>
</div>
</div>
The CSS:
.main-box {
padding: 0 0 0 30px; /*just for the box's content*/
}
.sh_bottom:before {
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 150px;
height: 100px;
z-index: -1;
background: rgba(0, 0, 0, 0.2);
box-shadow: -20px 30px 10px rgba(0, 0, 0, 0.3);
-moz-box-shadow: -20px 30px 10px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: -20px 30px 10px rgba(0, 0, 0, 0.3);
-webkit-transform: skew(-10deg,-10deg) translate(40px,-15px);
transform: skew(-10deg,-10deg) translate(40px,-15px);
-moz-transform: skew(-10deg,-10deg) translate(40px,-15px);
}
.sh_bottom:after {
content: "";
position: absolute;
right: 0;
bottom: 0;
width: 150px;
height: 100px;
z-index: -1;
background: rgba(0, 0, 0, 0.2);
-moz-box-shadow: 20px 30px 10px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 20px 30px 10px rgba(0, 0, 0, 0.3);
box-shadow: 20px 30px 10px rgba(0, 0, 0, 0.3);
-moz-transform: skew(10deg,10deg) translate(-40px,-15px);
-webkit-transform: skew(10deg,10deg) translate(-40px,-15px);
transform: skew(10deg,10deg) translate(-40px,-15px);
}
.box_shadow {
padding:20px;
width: 374px;
min-height: 200px;
margin: auto;
background: #ccc;
border: 5px solid white;
position: relative;
-webkit-box-shadow: rgba(0, 0, 0, 0.8) 0px 0px 1px; box-shadow: rgba(0, 0, 0, 0.8) 0px 0px 1px;
}
MORE:
See fiddle: http://jsfiddle.net/uwfL5azw/5/
This is only a little example of drop shadows.
For an example more helpful, I need of you code, or a web page with a result similar at your.
div {
width: 300px;
height: 100px;
background-color: yellow;
box-shadow: 10px 10px 5px #888888;
}
<div>Hello world!</div>
Thank you and bye,
Giacomo
How about this it is made of two divs
#box {
width:200px;
height:200px;
background:grey;
margin:20px;
border:2px solid white;
box-shadow:0px 16px 20px black;
}
#b {
position:absolute;
width: 0px;
height: 0px;
border-left: 250px solid transparent;
border-right: 250px solid transparent;
border-bottom: 100px solid white;
margin-left:-130px;
margin-top:-17px;
}
<div id="box"></div>
<div id="b"></div>
Without using two divs [Fiddle]http://jsfiddle.net/udq412fe/3/)
#box {
width:200px;
height:200px;
background:grey;
margin:20px;
border:2px solid white;
box-shadow:0px 16px 20px black;
}
#b {
position:absolute;
width: 0px;
height: 0px;
border-left: 250px solid transparent;
border-right: 250px solid transparent;
border-bottom: 100px solid white;
margin-left:-130px;
margin-top:-17px;
}
<div id="box"></div>