Is there a way in CSS3 to create a cross-browser (i.e.: Mozilla, Webkit, and Opera) inset box shadow that will transition from black on top to white on the bottom? The closest way that I have found to do this only allows the outside of the shadow to be one color, then transition to another color on the inside, on this page: http://www.css3.info/preview/box-shadow/
Late to the party, but maybe someone will find it useful!
You can actually do it with multiple shadows on the box-shadow:
box-shadow: inset 0px 33px 25px 0 #000,
inset 0 66px 15px 0px #ccc,
inset 0 99px 5px 0px #fff;
codepen example : https://codepen.io/InFecT3D/pen/JQdmeL
Side note: it might be a little "hacky" approach, but in some cases it helps.
Take a look at this video by Lea Verou. The section I linked to talks about something very similar, where you use background-image gradients to make something like a box-shadow. If I can figure out a good working example I'll post an answer, but this should give you a good place to start. You can also do some really cool stuff, like a box shadow curl with the :after pseudo-class to make a shadow appear.
Here are a few simple examples at the top and bottom of a box, and underlining some text. You'll have to play around with it (a lot, probably) to get it to look how you want, but css has some really awesome features (and there will be more and more).
body {
display: flex;
height: 100vh;
width: 100vw;
padding: 0;
margin: 0;
}
.container {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
background:
radial-gradient(at 50% 0, black, transparent 70%),
linear-gradient(0deg, black, transparent 50%) bottom;
background-size: 100% 15px;
background-repeat: no-repeat;
}
.underline {
width: 6em;
text-align:center;
font-size:30px;
}
.underline:after {
content: '\00a0';
background-image:
radial-gradient(at 50% 0, blue 0%, red 50%, transparent 75%);
background-size: 100% 2px;
background-repeat: no-repeat;
float:left;
width:100%;
}
<div class="container">
<div class="underline">Hello, world!</div>
</div>
To create a rainbow gradient box shadow:
.innerSquare {
background-color: white;
border-radius: 5px;
height: 100%;
width: 100%;
}
.rainbowGradient {
display: flex;
align-items: center;
justify-content: center;
padding: 18px;
border-radius: 5px;
box-shadow: inset 0 0 12px 12px white, inset 0 0 3px 2px white;
background: linear-gradient(to right, orange , yellow, green, cyan, blue, violet);
}
<div class="rainbowGradient">
<div class="innerSquare">
<h1>Hello World!</h1>
</div>
</div>
Try using a :before element to set a 'shadow' up.
.classname {
&:before {
content: '';
position: absolute;
display: none;
top: -20px;
left: -20px;
right: -20px;
bottom: -20px;
z-index: -1;
background: linear-gradient(to bottom, red, blue);
}
&:hover {
&:before {
display: inline-block;
}
}
}
This above code is an example on how to set up such an hover effect.
If the intention is to create a semi-transparent overlay over a background image, then it can be achieved with the following style rule without box-shadow.
background-image: linear-gradient(rgba(0, 0, 0, 0.5),
rgba(255, 255, 255, 0.5)),
url("background.png");
See background-image on MDN.
Two divs are necessary:
1: with the linear gradient + blur:
.gr{/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#f2305a+0,fca832+100 */
background: #f2305a; /* Old browsers */
background: -moz-linear-gradient(left, #f2305a 0%, #fca832 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(left, #f2305a 0%,#fca832 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, #f2305a 0%,#fca832 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f2305a', endColorstr='#fca832',GradientType=1 );
filter:blur(10px);
height:200px;
}
2: over the other, the content.
.zz {background:#fff; position: relative; top:-200px;
height:200px;
}
Then:
<div class='gr'></div>
<div class='zz'>BOX</div>
DEMO
Unfortunately, this is not possible. I suggest just using a div with a background-image that you create on Photoshop or likewise.
Another way would be to set a White background, and make a shadow (from black to transparent)
Example:
box-shadow: 0 1px 100px 0 rgb(0 0 0 /30%);
You can use <iframe> to achieve gradient effect on elements like videos or images.
HTML:
<iframe width="720" height="515"
<img src="image.png">
</iframe>
CSS:
iframe{
border:none;
background: -webkit-linear-gradient(90deg, rgb(0, 184, 255), rgb(255, 0, 249));
background: linear-gradient(90deg, rgb(0, 184, 255), rgb(255, 0, 249));
z-index:0;
padding:5px;
}
codepen example
Related
This question already has answers here:
Is it possible to have two background colors for a single html element? [duplicate]
(3 answers)
Closed 2 years ago.
So I have this button i am styling and I want it like this - If you can see it is red in color but has different shade of red starting from the bottom half of this element.
I wanted to enquire what exactly do I do to achieve this effect.
I currently have this after a few attempts:
That can be done using linear-gradient for more info about Linear gradient
Example:
button {
background: linear-gradient(to bottom, #e66465 50%, #9198e5 50%);
}
<button>
click me
</button>
Sometimes a gradient is all you need.
.button {
display: inline-block;
border-radius: 10px;
color: white;
padding: 5px 10px;
box-shadow: 1px 1px 3px rgba(0,0,0,0.4);
background: rgb(255,0,0);
background: linear-gradient(180deg, rgba(255,0,0,1) 0%, rgba(255,0,0,1) 50%, rgba(200,0,0,1) 50.1%, rgba(200,0,0,1) 100%);
cursor:pointer;
}
/* Hover state */
.button:hover {
background: linear-gradient(180deg, rgba(255,50,50,1) 0%, rgba(255,50,50,1) 50%, rgba(200,50,50,1) 50.1%, rgba(200,50,50,1) 100%);
box-shadow: 0px 0px 1px rgba(0,0,0,0.4);
}
<div class="button">SUBMIT▶</div>
To do this, just use background: linear-gradient()
.button {
display: flex;
align-items: center;
justify-content: center;
width: 100px;
height: 50px;
color: white;
background: linear-gradient(to top, green 50%, red 50%);
}
<div class="button">
submit
</div>
So I know how to do a basic box shadow with CSS3. You can see that in the top of the graphic below.
The effect I'm trying to achieve is a 3D box shadow, as shown in the bottom of the graphic below.
Any ideas on how to do this with CSS3 box shadows?
Unfortunately box shadows are effectively just flat layers. However you can apply multiple box shadows to create this effect.
.box-shadow-3d{
box-shadow: 1px 1px 0px #999,
2px 2px 0px #999,
3px 3px 0px #999,
4px 4px 0px #999,
5px 5px 0px #999,
6px 6px 0px #999;
}
you can use pseudo element for as shadow
div {
background: black;
height: 100px;
width: 100px;
position: relative;
}
div:after,
div:before {
content: '';
background: grey;
position: absolute;
}
div:after {
width: 100%;
height: 20px;
left: 10px;
bottom: 0;
transform: translatey(100%) skewx(45deg);
}
div:before {
width: 20px;
height: 100%;
right: 0;
transform: translatex(100%) skewy(45deg);
top: 10px;
}
<div></div>
Here is a real 3D shadow using perspective and pseudo-element :before.
body {
background: lightblue;
}
.foo {
position: relative;
display: inline-block;
-webkit-perspective: 1000px;
-moz-perspective: 1000px;
persepctive: 1000px;
margin: 20px;
margin-top: 50px;
}
.foo .box {
transform: rotateY(-40deg);
height: 350px;
width: 250px;
background-color: black;
}
.foo:before {
content: "";
top: -15px;
position: absolute;
width: 50px;
height: 375px;
background-color: grey;
transform: translateX(215px) translateY(2.7px) rotateY(55deg)
}
<div class="foo">
<div class="box"></div>
</div>
You can stack the horizontal/vertical offsets of several box-shadows, each slightly bigger than the previous one. The more shadows you add, the more pronounced the effect. Here is a fiddle example.
div {
background: black;
height: 100px;
width: 100px;
box-shadow: 0 01px gray,
01px 0 gray,
01px 02px gray,
02px 01px gray,
02px 03px gray,
03px 02px gray,
03px 04px gray,
04px 03px gray,
04px 05px gray,
05px 04px gray,
05px 06px gray,
06px 05px gray;
}
I had some problems with these two options, so I adapted some diagonal gradients from Lea Verou's excellent book CSS Secrets. I thought about creating a gradient inside a right and bottom border via border-image, but that property does not allow edge targeting, à la border-right-image, etc.
So, I settled on using a pseudo element with two truncated corners, which seems to work pretty well. You have to be careful to adjust the width of the gradient to be 1.414 the size of half the padding, since this would be the diagonal of a square (square root of two). Also, since that's a pseudo element, be careful of the right placement. Interested to hear what you folks think.
div {
background: #bbb;
padding: 1em 1.2em;
width: 50%;
margin: 0 auto;
color: #111;
font: 150%/1.2 Georgia, Palatino, Times, serif;
position: relative;
}
div:after {
content:" ";
position:absolute;
top:0;
left: 0;
width:100%;
height:100%;
padding: 1.42em; /* (square root of gradient position) */
background: #000; /* Fallback if not supported */
background: linear-gradient(-135deg, transparent 2em, #000 0) top right,
linear-gradient(#000, #000) padding-box bottom right,
linear-gradient(45deg, transparent 2em, #000 0) bottom left;
/*I have avoided adding -webkit-, -moz and -0 prefixs for linear-gradient. You may put them in later to be extra safe*/
background-size: 50% 50%; /* There is no reason to paint the upper left quadrant, so I didn't. */
background-repeat: no-repeat;
-webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box;
/* Many people use border-box as default these days. Unfortunately, the box cannot be sized using border-box settings with the combination of padding in ems and percentages. So this is reset to content-box, just in case. */
z-index: -1; /* To keep the shadow behind the div*/
<div>This is a short sentence to demonstrate that our little div is responsive.</div>
Here's a little implementation, inspired by #Vitorino fernandes, in stylus...
offset = 10
border = 3
.offsetbox
margin offset
padding offset
text-align center
box-shadow inset 0 0 0 unit(border,px) black
background white
display inline-block
position relative
&:after,
&:before
content ''
background black
position absolute
&:after
width 100%
height offset
transform translatey(100%) skewx(-45deg)
right (offset/2)
bottom 0
&:before
height 100%
width offset
transform: translatex(-100%) skewy(-45deg)
left 0
top (offset/2)
I added some clip paths to #Vittorino fernandes code, to avoid white space between pseudos and make it sharper.
I added some 1px adjustments to avoid bad svg rendering problems.
You can use the variable called shadow-dimension to set the shadow width and height.
I Put it on a codePen:
https://codepen.io/silviamalavasi/pen/XWqeWEq
:root {
--shadow-dimension: 20px;
--blue: #0039a6;
}
.box-container {
position: relative;
}
.box-container>div {
border: 2px solid var(--blue);
}
.box-container>div:after, .box-container>div:before {
content: '';
background-color: var(--blue);
position: absolute;
}
.box-container>div:before {
width: calc(var(--shadow-dimension) + 1px);
height: calc(100% + 100px + 1px);
left: calc(var(--shadow-dimension) * -1);
transform: skewy(-45deg);
top: calc(0.5*var(--shadow-dimension));
clip-path: polygon(0% 0%, 100% 0%, 100% calc(100% - 100px - 2px + var(--shadow-dimension)), 0% calc(100% - 100px - 2px));
}
.box-container>div:after {
width: calc(100% + 100px);
height: calc(var(--shadow-dimension) + 1px);
left: calc(-0.5*var(--shadow-dimension) - 100px);
bottom: 1px;
transform: translateY(100%) skewx(-45deg);
clip-path: polygon(100px 0%, 100% 0%, 100% 100%, calc(100px + 2px) 100%);
}
This question already has answers here:
How to center the <legend> element - what to use instead of align:center attribute?
(10 answers)
Closed 7 years ago.
How to put some text on a border div so that text has a transparent background that it matches the image behind?
The problem is that the background-image has some shapes and multiple colors, so I can't put just some background color the the text because it won't fit.
Example:
html,
body {
width: 100%;
height: 100%;
}
body {
margin: 0;
background: url(http://wallpoper.com/images/00/45/05/47/green-background-2_00450547.jpg);
}
#main {
margin-top: 100px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
border: 1px solid #000000;
}
#main h2 {
font-size: 60px;
font-weight: 700;
text-align: center;
margin: -40px 0 0;
background: transparent; /* somehow remove the border behind the text */
padding: 0 20px;
}
<div id="main">
<h2>Star players</h2>
<ul>
<li>foo</li>
<li>bar</li>
</ul>
</div>
JSFiddle
You can use a fieldset instead of a div:
HTML:
<fieldset>
<legend>Test</legend>
</fieldset>
CSS:
legend {
text-align: center;
width: 100%;
}
So you want to see one thing 2 layers behind the text but not the other thing that is between the two...that in itself is rather counter-intuitive. Not sure you will be able to do it unless you use a border image and css gradient which is always a little complicated and this won't be dependant on the size/width of the text.
e.g.
HTML
<div class="gradborder-box"><div class="inner"><h2>Hello WORLD</h2></div></div>
CSS
.gradborder-box{
margin: auto;
width: 350px;
background: transparent;
border: 2px solid transparent;
-webkit-border-image: -webkit-linear-gradient(left, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 26%, rgba(0,0,0,0) 68%, rgba(0,0,0,1) 100%);
border-image: linear-gradient(to left, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 26%, rgba(0,0,0,0) 68%, rgba(0,0,0,1) 100%);
border-image-slice: 1;
}
h2{font-size: 1.2em; text-align: center; margin-top: -10px;}
.inner{height: 150px; width: 100%; border-bottom: 2px solid #000; margin-bottom: -2px;}
CodePen
This has been done for CHROME - you will need to add in the correct border image tags for the other browsers (-moz-border-image, etc). This is CSS3 only.
Using HTML with CSS.
On a single div, I have three buttons each with different class (border style) coded in CSS. I made the buttons behave where their widths are fixed while the height changes size depending on the text length.
The problem I have is, when one button change size (height), the other buttons does not follow or does not inherit the same height the div is adjusted too.
Here is my code in HTML:
<div class="container-1020-Apx">
<button type="button" class="btn-styleLT">The quick brown fox jumped over the lazy rabbit because it is not paying attention to it's mother who cried wolf. </button>
<button type="button" class="btn-styleCT"> middle </button>
<button type="button" class="btn-styleRT"> right </button>
</div>
Here is my code in CSS:
.container-1020-Apx {
margin:auto;
text-align: left;
width:1020px;
min-height: 30px;
background-color: White;
display:block;
}
.btn-styleLT{
border : solid 2px #170417;
border-radius : 20px 0px 0px 0px ;
moz-border-radius : 0px 20px 0px 0px ;
font-size : 16px;
color : #f4f6f7;
padding : 4px 18px;
width: 422px;
background : #000000;
background : -webkit-gradient(linear, left top, left bottom, color-stop(0%,#000000), color-stop(100%,#353535));
background : -moz-linear-gradient(top, #000000 0%, #1f3b08 100%);
background : -webkit-linear-gradient(top, #000000 0%, #1f3b08 100%);
background : -o-linear-gradient(top, #000000 0%, #1f3b08 100%);
background : -ms-linear-gradient(top, #000000 0%, #1f3b08 100%);
background : linear-gradient(top, #000000 0%, #1f3b08 100%);
filter : progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000', endColorstr='#1a0d1a',GradientType=0 );
min-height: 20px;
max-height: inherit;
}
.btn-styleRT{
border : solid 2px #170417;
border-radius : 0px 20px 0px 0px ;
... <almost same content>
min-height: 20px;
max-height: inherit;
}
.btn-styleCT{
border : solid 2px #170417;
font-size : 16px;
color : #f4f6f7;
padding : 4px 18px;
width:167px;
background : #000000;
... <almost same content>
min-height: 20px;
max-height: inherit;
}
.btn-styleLT:hover,
.btn-styleLT:focus,
.btn-styleLT:active,
.btn-styleLT.active {
color: #ffffff;
background-color: #3276b1;
border-color: #285e8e;
}
.btn-styleRT:hover,
... <same>
border-color: #285e8e;
}
.btn-styleCT:hover,
... <same>
border-color: #285e8e;
}
Any ideas? I was thinking to provide individual div for each button, but if there is a work-around without doing so, that would be great.
you need to use display:table and display:table-cell to achieve what you want.
here's a jsfiddle: http://jsfiddle.net/vtajZ/293/
html:
<div class="parent">
<div class="child"><button type="button" class="btn-styleLT">The quick brown fox jumped over the lazy rabbit because it is not paying attention to it's mother who cried wolf. </button></div>
<div class="child"><button type="button" class="btn-styleCT"> middle </button></div>
<div class="child"><button type="button" class="btn-styleRT"> right </button></div>
</div>
css:
*{
box-sizing:content-box;
}
.parent {
display: table;
position:relative;
}
.child {
display: table-cell;
}
.btn-styleLT{
border : solid 2px #170417;
border-radius : 20px 0px 0px 0px ;
moz-border-radius : 0px 20px 0px 0px ;
font-size : 16px;
color : #f4f6f7;
padding : 4px 18px;
width: 422px;
background : #000000;
background : -webkit-gradient(linear, left top, left bottom, color-stop(0%,#000000), color-stop(100%,#353535));
background : -moz-linear-gradient(top, #000000 0%, #1f3b08 100%);
background : -webkit-linear-gradient(top, #000000 0%, #1f3b08 100%);
background : -o-linear-gradient(top, #000000 0%, #1f3b08 100%);
background : -ms-linear-gradient(top, #000000 0%, #1f3b08 100%);
background : linear-gradient(top, #000000 0%, #1f3b08 100%);
filter : progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000', endColorstr='#1a0d1a',GradientType=0 );
min-height: 20px;
max-height: inherit;
}
.btn-styleRT{
border : solid 2px #170417;
border-radius : 0px 20px 0px 0px ;
... <almost same content>
min-height: 20px;
max-height: inherit;
}
.btn-styleCT{
border : solid 2px #170417;
font-size : 16px;
color : #f4f6f7;
padding : 4px 18px;
width:167px;
background : #000000;
... <almost same content>
min-height: 20px;
max-height: inherit;
}
.btn-styleCT,.btn-styleRT{
height: 100%;
}
.btn-styleCT{
position:relative;
height:100%;
}
.parent button{
margin:0px;
}
I've been trying to use a linear gradient on top of my background image in order to get a fading effect on the bottom of my background from black to transparent but can't seem to be able to make it show.
I've read other cases here and examples but none of them are working for me. I can only see the gradient or the image but not both of them.
Here's the link
Just click on the first logo, ignore that effect, what I'm trying is in the body in the whole site after that.
This is my css code:
body {
background: url('http://www.skrenta.com/images/stackoverflow.jpg') no-repeat, -webkit-gradient(linear, left top, left bottom, from(rgba(0, 0, 0, 0.1)), to(rgba(0, 0, 0, 1)));
}
Ok, I solved it by adding the url for the background image at the end of the line.
Here's my working code:
.css {
background:
linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 59%, rgba(0, 0, 0, 0.65) 100%),
url('https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a') no-repeat;
height: 200px;
}
<div class="css"></div>
body {
margin: 0;
padding: 0;
background: url('img/background.jpg') repeat;
}
body:before {
content: " ";
width: 100%;
height: 100%;
position: absolute;
z-index: -1;
top: 0;
left: 0;
background: -webkit-radial-gradient(top center, ellipse cover, rgba(255,255,255,0.2) 0%,rgba(0,0,0,0.5) 100%);
}
PLEASE NOTE: This only using webkit so it will only work in webkit browsers.
try :
-moz-linear-gradient = (Firefox)
-ms-linear-gradient = (IE)
-o-linear-gradient = (Opera)
-webkit-linear-gradient = (Chrome & safari)
#multiple-background{
box-sizing: border-box;
width: 123px;
height: 30px;
font-size: 12pt;
border-radius: 7px;
background: url("https://cdn0.iconfinder.com/data/icons/woocons1/Checkbox%20Full.png"), linear-gradient(to bottom, #4ac425, #4ac425);
background-repeat: no-repeat, repeat;
background-position: 5px center, 0px 0px;
background-size: 18px 18px, 100% 100%;
color: white;
border: 1px solid #e4f6df;
box-shadow: .25px .25px .5px .5px black;
padding: 3px 10px 0px 5px;
text-align: right;
}
<div id="multiple-background"> Completed </div>
The accepted answer works well. Just for completeness (and since I like it's shortness), I wanted to share how to to it with compass (SCSS/SASS):
body{
$colorStart: rgba(0,0,0,0);
$colorEnd: rgba(0,0,0,0.8);
#include background-image(linear-gradient(to bottom, $colorStart, $colorEnd), url("bg.jpg"));
}