CSS3 horizontal fading drop shadow with specific stops? - html

So, I am trying to use pure CSS to have a slight dropshadow that lays over a tab. I want it to fade out on the ends at 20% and 80%. I've been trying to acheive this for some time now, but finding myself not happy with the results so far.
Here's an image of what I want to have:
HTML:
<button type="button" class="btn">
<span>Button Text</span>
<span class="buttonshadow"></span>
</button>
CSS:
.btn {
-webkit-border-radius: 0px;
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-moz-border-radius: 0px;
-moz-border-radius-bottomright: 5px;
-moz-border-radius-bottomleft: 5px;
border-radius: 0px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
font-size: 24px;
padding: 6px 16px 7px;
line-height: 1;
position: relative;
color: #ffffff;
background-color: #5CBCEC;
border-color: #5CBCEC;
display: inline-block;
margin-bottom: 0;
background-image: none;
border: 1px solid transparent;
white-space: nowrap;
overflow: visible;
}
.buttonshadow {
width: 120%;
height: 100%;
position: absolute;
top: 0;
left: -10%;
}
.buttonshadow:before {
content: "";
position: absolute;
z-index: 1;
top: -1px;
left: 0;
width: 100%;
height: 5px;
background: -webkit-radial-gradient(50% -3%, ellipse cover, rgba(00, 00, 00, 0.2), rgba(97, 97, 97, 0.0) 40%);
background: radial-gradient(ellipse at 50% 0%, rgba(0, 0, 0, 0.4), rgba(97, 97, 97, 0) 70%);
}
Here's my current fiddle so far: JSFiddle
Clearly this does not look the same. Any help is much appreciated!!!

If i understand the problem correctly you want the gradient outside the button on the edges.
problem lies in the .buttonshadow and .buttonshadow:before
I changed it to this
.buttonshadow {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: -25px;
}
.buttonshadow:before {
content: "";
position: absolute;
z-index: 1;
top: -1px;
left: 0;
width: 130%;
height: 5px;
background: -webkit-radial-gradient(50% -3%, ellipse cover, rgba(00, 00, 00, 0.2), rgba(97, 97, 97, 0.0) 40%);
background: radial-gradient(ellipse at 50% 0%, rgba(55, 55, 55, 1), rgba(97, 97, 97, 0) 80%);
}
Check fiddle
http://jsfiddle.net/rLsbC/1/
you can then fiddle around with the gradient to get more what you want.
Hope this helps!
Note: If you want to change the width of the gradient change the width in .buttonshadow:before and the left attribute in .buttonshadow

This is one solution that may work for you.
Demo Fiddle
In order to get the fading at the ends I had to squish the radial gradient down a bit, and then position it to look right. I added it to the .btn class instead of a separate element.
CSS:
.btn:after {
content: '';
display: block;
position: absolute;
width: 120%;
height: 5px;
top: -2px;
left: -10%;
background: -webkit-radial-gradient(center, ellipse cover, rgba(0,0,0,0.45) 0%,rgba(0,0,0,0) 85%);
}

[me, earlier via comments] I’d try with just a linear gradient for the span over the whole width of the button, and then add a faded shadow via an elliptical gradient on both sides using :before/ :after elements on the span …
OK, I gave it a go now – http://jsfiddle.net/rLsbC/3/
Sorry, it’s Firefox only for now as I didn’t bother with vendor prefixes for other browsers – but to add those should be not a big deal. (For those that actually support radial gradients anyway.)
I replaced the shadow in the span element itself with a linear gradient,
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.4) 0%,
rgba(97, 97, 97, 0) 100%);
and then added positioned :before/:after with an elliptical radial gradient positioned at the top right resp. top left corner of those generated elements, like this
background: -moz-radial-gradient(top right, ellipse cover, rgba(0, 0, 0, 0.4),
rgba(97, 97, 97, 0) 50%);
Had to make the span element itself a little higher to get the linear gradient and the elliptical ones stuck to the sides of it to match up.
If you take that as a basis and play around with the specific values of the gradients (and maybe the width/position of the generated elements), you should be able to get very close to what you want.

Related

Divide a rectangle into 2 triangles along diagonal using css

I want to make a div into 2 triangles (as shown in below, no problem if 1 is background of parent) upper one with one color and lower one with another. I dont mind how it is implemented but i want to do it in css (not javascript). I tried with css rotation, (code below), but its not responsive. In smaller or wider screen it is distorted . Any way to implement this in css?
body {
background: #eee;
}
.darker {
position: fixed;
top: -94%;
left: -10%;
width: 150%;
height: 150%;
background: #dd4f39;
-webkit-transform: rotate(30deg);
transform: rotate(30deg);
}
<div class="darker"> </div>
I found an interesting way to do this from here, which uses clip-path
.Answering my own question so that everyone can use it.
html,
body {
margin: 0;
}
body {
background: #eee;
}
.box {
width: 100vw;
height: 100vh;
background-color: #dd4f39;
clip-path: polygon(0 0, 100% 0, 100% 100%);
}
<div class="box"></div>
This is one way of doing it. But this use case is strictly with respect to vw. Just make sure to give the same value to these elements
div and it's pseudo element should have same width and border-left respectively.
div and it's pseudo element should have same height and border-top respectively.
html, body {
margin: 0;
}
.box {
width: 100vw;
height: 100vh;
background-color: white;
}
.box::after {
content: ' ';
border-top: 100vh solid #dd4f39;
border-left: 100vw solid transparent;
width: 0;
position: absolute;
}
<div class="box"></div>
JS fiddle
https://jsfiddle.net/kqsrmrss/2/
You can do that with a skewed pseudo element. The main trick is to keep the aspect ratio the same or else the sloped angle will fail
Fiddle demo
Stack snippet Note 1
body {
background: #eee;
}
.darker {
position: absolute;
top: 0;
left: 0;
width: 100%;
padding-top: 50%;
background: #dd4f39;
overflow: hidden;
}
.darker::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: gray;
transform: skewY(26.5deg);
transform-origin: left top;
}
<div class="darker"></div>
Optionally, you can add media query to control the angle at different screen sizes
Fiddle demo 2
With a tiny script running when window resize's, you can control the angle and make it fully responsive both horizontally and vertically.
Note 1 Based on a comment, the Stack snippet might not work properly, and if, try the fiddle demos.
Please Use this code snippet.
div {
width: 100%;
height: 100px;
}
.diagonalRising {
border: 1pt solid black;
background: linear-gradient(to right bottom, #eeeeee 0%, #eeeeee 49.9%, #eeeeee 50%, #000000 51%, #dd4f39 51.1%, #dd4f39 100%);
}
.diagonalFalling {
background: linear-gradient(to right top, #eeeeee 0%, #eeeeee 49.9%, #000000 50%, #000000 51%, #dd4f39 51.1%, #dd4f39 100%);
}
.diagonalCross {
position: relative;
background: linear-gradient(to right bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 49.9%, rgba(0, 0, 0, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(0, 0, 0, 0) 51.1%, rgba(0, 0, 0, 0) 100%);
}
.diagonalCross:after {
content: "";
display: block;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
background: linear-gradient(to right top, #ffffff 0%, #ffffff 49.9%, #000000 50%, #000000 51%, #ffffff 51.1%, #ffffff 100%);
}
<div class="diagonalRising"></div>
<div class="diagonalFalling"></div>
<div class="diagonalCross"></div>
Try this,
.box::after {
background: #E52A35
content: '';
position: absolute;
width: 100%;
height: 100vh;
background-color: #dd4f39;
clip-path: polygon(52% 13%, 104% -1%, -1% 0%);
}

CSS border image is wider than the div

I am adding an image border in bottom of my div like this :
HTML:
<div class="view">
<div class="shadow_overlay"></div>
</div>
CSS:
.view {
text-align: center;
overflow: hidden;
position: relative;
text-align: center;
cursor: default;
width: 160px;
height: 190px;
border-image: linear-gradient(to right, rgb(139, 191, 64) 25%, rgb(230, 27, 33) 25%, rgb(230, 27, 33) 50%, rgb(124, 196, 236) 50%, rgb(124, 196, 236) 75%, rgb(254, 181, 17) 75%);
border-image-slice: 1;
border-image-width: 4px 0px 0px 0px;
}
.shadow_overlay {
background: url('http://i.imgur.com/MrVzqyp.png') 0 0 no-repeat;
background-size: cover;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin-left:auto;
margin-right:auto;
width:160px;
height:190px;
}
This worked but in action border-image is wider than my div.
Problem pic:
How do I fix this problem?
DEMO here
It seems like browsers assign a default width to borders when border-image is used (but the borders on the other sides are invisible because the border-image-width is 0px). To avoid the borders from looking like they are overflowing the div, manually set the border widths on all other sides to 0px.
border-width: 4px 0px 0px 0px;
The behavior is seen in Chrome (upto v48.0.2535.0 dev-m), IE (Edge), Opera and Safari. The border image doesn't extend beyond the div in latest Firefox (v41.0.1) IE (v11),
.view {
text-align: center;
overflow: hidden;
position: relative;
text-align: center;
cursor: default;
width: 160px;
height: 190px;
border-image: linear-gradient(to right, rgb(139, 191, 64) 25%, rgb(230, 27, 33) 25%, rgb(230, 27, 33) 50%, rgb(124, 196, 236) 50%, rgb(124, 196, 236) 75%, rgb(254, 181, 17) 75%);
border-image-slice: 1;
border-image-width: 4px 0px 0px 0px;
border-width: 4px 0px 0px 0px;
}
.shadow_overlay {
background: url('http://i.imgur.com/MrVzqyp.png') 0 0 no-repeat;
background-size: cover;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin-left: auto;
margin-right: auto;
width: 160px;
height: 190px;
}
<div class="view">
<div class="shadow_overlay"></div>
</div>
In the below snippet you can see how it looks as though all other sides have a 3px border. There is no clear explanation either in the Web or in the specs about whose behavior is correct (Chrome, Edge or FF, IE11).
.view {
text-align: center;
overflow: hidden;
position: relative;
text-align: center;
cursor: default;
width: 160px;
height: 190px;
border-image: linear-gradient(to right, rgb(139, 191, 64) 25%, rgb(230, 27, 33) 25%, rgb(230, 27, 33) 50%, rgb(124, 196, 236) 50%, rgb(124, 196, 236) 75%, rgb(254, 181, 17) 75%);
border-image-slice: 1;
border-image-width: 4px 0px 0px 0px;
}
.view#two{
border-width: 4px 3px 3px 3px;
}
.shadow_overlay {
background: url('http://i.imgur.com/MrVzqyp.png') 0 0 no-repeat;
background-size: cover;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin-left: auto;
margin-right: auto;
width: 160px;
height: 190px;
}
<div class="view">
<div class="shadow_overlay"></div>
</div>
<div class="view" id="two">
<div class="shadow_overlay"></div>
</div>
The W3C Specs also say the following about border-image properties but in FF and IE11 the border-image is not shown when only border-width is provided and border-image-width is avoided.
The border-image properties do not affect layout: layout of the box, its content, and surrounding content is based on the ‘border-width’ and ‘border-style’ properties only.
So, it seems like the behavior of border-image is still not standardized. I am leaning towards what is observed in Chrome, Edge because Microsoft, for some reason, seems to have changed the behavior from IE11 and so there must be a good reason for it.

css menu disappears on mobile device

Here's my CSS menu I've created.
When I see this in my mobile (iPhone 6), the last menu (Menu4) does not show At All. The first 3 menus stretch from left to the right of the phone screen. I can't figure out why.
Could someone help out please?
Here's the HTML part
<hr class="navHr">
<nav id="m">
Menu1
Menu2
Menu3
Menu4
</nav>
<hr class="navHr">
And the CSS part
.navHr {
border: 0;
height: 0.1em;
margin: 0;
background-image: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0));
background-image: -moz-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0));
background-image: -ms-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0));
background-image: -o-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0));
}
nav {
height: 2em;
background: #000;
background: linear-gradient(to bottom, rgba(76, 76, 76, 1) 0%, rgba(44, 44, 44, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(19, 19, 19, 1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#131313',GradientType=0 );
line-height: 2em;
text-transform: uppercase;
text-align: center;
min-width: 2em;
position: relative;
}
nav::before {
background: linear-gradient(to top, rgba(76, 76, 76, 0) 0%, rgba(44, 44, 44, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(19, 19, 19, 1) 100%);
content: '';
display: block;
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 100%;
opacity: 0.09;
}
nav a {
color: #FFF;
text-decoration: none;
font-weight: bold;
font-size: 1.2em;
border-right: solid 0.1em #FFF;
height: 100%;
padding: 0.25em 3em;
position: relative;
}
nav a:first-child {
border-left: solid 0.1em #FFF;
}
nav a::before {
content: attr(data-mirror);
position: absolute;
top: 100%;
left: 3em;
color: #000;
transform: scaleY(-1);
color: #FFF;
opacity: 0.5;
}
#m {
background-color: #000000;
}
I've checked on your code, try adding "display:inline-block" on your anchor tag, and you will see your column 4 appearing, the fourth one goes beneath the second one in small screens, since the position is relative, try it here :
Columns
Basically, what you are looking for, is displaying an element as an inline-level block container to avoid dislocation. The inside of this block is formatted as block-level box, and the element itself is formatted as an inline-level box, which shapes the navigation of these 4 columns sitting next to each other.
Why do we use inline-block ?
Inline-block makes the element generate a block box that’s laid out as if it were an inline box.
An inline block is placed inline (ie. on the same line as adjacent content), but it behaves as a block.
Basically, it’s a way to make elements inline, but preserving their block capabilities such as setting width and height, top and bottom margins and paddings etc.

Create a gradient border in CSS3 as referenced

I am doing a gradient border of a div in css3. So far now I have done my coding like this
in css
.bot-left {
position: relative;
}
.bot-left:before, .bot-left:after {
content: "";
position: absolute;
bottom: -3px;
left: -3px;
}
.bot-left:before {
top: -3px;
width: 3px;
background-image: -webkit-gradient(linear, 0 100%, 0 0, from(#000), to(transparent));
background-image: -webkit-linear-gradient(transparent, #000);
background-image: -moz-linear-gradient(transparent, #000);
background-image: -o-linear-gradient(transparent, #000);
}
.bot-left:after {
right: -3px;
height: 3px;
background-image: -webkit-gradient(linear, 0 0, 100% 0, from(#000), to(transparent));
background-image: -webkit-linear-gradient(left, #000, transparent);
background-image: -moz-linear-gradient(left, #000, transparent);
background-image: -o-linear-gradient(left, #000, transparent);
}
in html
<div class="bot-left" style="width: 200px; height: 200px"></div>
But still I am not getting the exact match as reference. The reference image for the gradient border is attached with this
UPDATE
I want the background-color should be transparent.
I would recommend you to use the gradients as background instead of border images. The reason I am suggesting you to use this method is because border-image isn't supported by IE10. Where as you can implement this method to support IE9 as well, by using base64 encoded gradients.
Now, here am using two absolute positioned elements along with :before and :after pseudo elements which are positioned absolute.
Demo
Here, you can refactor this to a great extent, I've not done that so that you can figure out how this works.
Also, if you want, you can wrap this inside a position: relative; container with a negative z-index set on the elements having class of .frame1 and 2 respectively.
Demo 2
body {
background: #000;
}
.frame1,
.frame2 {
position: absolute;
top: 25px;
left: 25px;
bottom: 25px;
right: 25px;
}
.frame1:before {
content: "";
position: absolute;
left: 0;
top: 0;
height: 100%;
background: linear-gradient(to bottom, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
width: 1px;
}
.frame1:after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
background: linear-gradient(to right, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
height: 1px;
}
.frame2:before {
content: "";
position: absolute;
right: 0;
bottom: 0;
height: 100%;
background: linear-gradient(to top, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
width: 1px;
}
.frame2:after {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background: linear-gradient(to left, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
height: 1px;
}
For younger browser , you may use one single gradient, box-shadow and transparent border : DEMO
CSS used for demo:
.bot-left {
background:
linear-gradient(
to bottom right,
#777,
#555,
#333,
#111,
#333,
#555,
#777) center;
background-size:105% 105%;/* needs to lay under borders */
box-sizing:border-box;/* keep borders inside width and height setted */
border:1px transparent solid;/* background will show through */
box-shadow:inset 0 0 0 500px black, 0 0 0 5px black;/* inset shadow will hide background gradient */
margin:5px;/* optionnal: includes ouside box-shadow in space needed by element */
}

Creating a rectangle with css and a 'triangle edge'

Im trying to create a container with css that has a rectangle header with a 'triangle edge'.
Example:
chrome example
Or code here (css):
.bubble {
clear: both;
margin: 0px auto;
width: 350px;
background: #fff;
-moz-border-radius: 10px;
-khtml-border-radius: 10px;
-webkit-border-radius: 10px;
-moz-box-shadow: 0px 0px 8px rgba(0,0,0,0.3);
-khtml-box-shadow: 0px 0px 8px rgba(0,0,0,0.3);
-webkit-box-shadow: 0px 0px 8px rgba(0,0,0,0.3);
position: relative;
z-index: 90; /* the stack order: displayed under ribbon rectangle (100) */
}
div#container {
margin: 50px auto 0px auto; /* centered */
padding-top:100px;
width: 400px;
}
.triangle {
height: 35px;
top: -20px;
width: 315px;
position: relative;
background: #D12738;
background: -moz-linear-gradient(top, rgba(209, 39, 56, 1) 0%, rgba(122, 23, 38, 1) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(209, 39, 56, 1)), color-stop(100%,rgba(122, 23, 38, 1)));
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#d12738', endColorstr='#7a1726',GradientType=0 ), filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
}
.triangle::after {
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-webkit-transform: rotate(35deg);
-o-transform: rotate(45deg);
background: none repeat scroll 0 0 white;
content: "";
height: 44px;
left: 302px;
position: absolute;
top: 2px;
width: 24px;
}
html:
<div id="container">
<div class="bubble">
<div class="triangle">test baa</div>
<p>sadsadsadsad dsdsa dsdsa ds dsadsd</p>
<p>sadsadsadsad dsdsa dsdsa ds dsadsd</p>
<p>sadsadsadsad dsdsa dsdsa ds dsadsd</p>
<p>sadsadsadsad dsdsa dsdsa ds dsadsd</p>
</div>
</div>
But the border on the right edge dissapears because of the white background. Is there any way to prevent this?
Any help appreciated!
You can't accomplish what you're trying to do by creating a triangle with that method, because by definition you're blocking out a piece of the rectangle with something that's also going to block out whatever else is behind it.
The way to accomplish what you want to accomplish is to create a triangle using a border. Here's a link and a fiddle to how you might accomplish this:
http://css-tricks.com/snippets/css/css-triangle/
http://jsfiddle.net/BNVHU/7/
Unfortunately, border gradients only work with webkit at this time, and don't seem to jibe with the border method of making triangles. I doubt that there's a way to do this with a gradient intact in all browsers. Might need an image.