I am applying this CSS rule to some divs on a web application. Basically I need to display a border around the div, but without using the border property.
It works on every browser but Firefox. Can anyone help me understand what I'm doing wrong?
div {
margin: 20px;
width: 100px;
height: 100px;
background-color: #F8F9FA;
background-image: radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px), radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px), radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px), radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px);
background-image: -moz-radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px), -moz-radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px), -moz-radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px), -moz-radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px);
background-position: top, right, bottom, left;
background-size: 1px 1px, 1px 1px;
background-repeat: repeat-x, repeat-y;
}
<div></div>
https://jsfiddle.net/za74L1st/1/
Many thanks!
This a job for linear-gradient not radial-gradient.
.box {
margin: 20px;
width: 100px;
height: 100px;
background-color: #F8F9FA;
background-image:
linear-gradient(#dedede,#dedede),
linear-gradient(#dedede,#dedede),
linear-gradient(#dedede,#dedede),
linear-gradient(#dedede,#dedede);
background-position: top, right, bottom, left;
background-size: 100% 1px,1px 100%;
background-repeat: no-repeat;
}
<div class="box"></div>
You are for sure facing subpixel rendring issue since you are defining very small circles having less than 1px radius. If you increase the values you will see something on Firefox:
.box {
margin: 20px;
width: 100px;
height: 100px;
background-color: #F8F9FA;
background-image:
/* doesn't matter what you put here as value since the background-size is already small */
radial-gradient(#dedede 51px, transparent 51px),
radial-gradient(#dedede 50px, transparent 50px),
radial-gradient(#dedede 99px, transparent 5px),
radial-gradient(#dedede 54px, transparent 54px);
background-position: top, right, bottom, left;
background-size: 1px 1px;
background-repeat: repeat-x, repeat-y;
}
<div class="box"></div>
Related
I liked this book design in iBooks and have been wondering can it be easily made with css?
Original photo
have you tried gradients and shadows ?
.cover {
background: linear-gradient(to right, rgb(60, 13, 20) 3px, rgba(255, 255, 255, 0.5) 5px, rgba(255, 255, 255, 0.25) 7px, rgba(255, 255, 255, 0.25) 10px, transparent 12px, transparent 16px, rgba(255, 255, 255, 0.25) 17px, transparent 22px), url(https://images-na.ssl-images-amazon.com/images/I/51pnouuPO5L.jpg);
box-shadow: 0 0 5px -1px black, inset -1px 1px 2px rgba(255, 255, 255, 0.5);
margin: auto;
border-radius: 5px;
width: 389px;
height: 500px;
}
body {
min-height: 100vh;
display: flex;
}
<div title=" Don't make me think " class="cover"></div>
I think this could be pretty easily done with gradients in CSS. Here's a (very rough) example fiddle: https://jsfiddle.net/6yok9c4w/
HTML:
<div class="overlay">
</div>
<img src="https://images-na.ssl-images-amazon.com/images/I/51pnouuPO5L.jpg" />
CSS:
.overlay {
width: 400px;
height: 500px;
position: fixed;
top: 0;
left: 0;
background: linear-gradient(90deg, rgba(2,0,36,.5) 0%, rgba(0,0,0,.5) 2%, rgba(255,255,255,.5) 3%, rgba(247,254,255,.5) 5%, rgba(0,0,0,.5) 7%, rgba(255,255,255,.5) 13%, rgba(255,255,255,.2) 100%);
}
img {
position: fixed;
top: 0;
left: 0;
z-index: -1;
}
I used this tool to generate the gradient: https://cssgradient.io/
With more effort and tweaking, I think you can get really close to the original.
So, I'm trying to create an border of 1px, with a color 30% green, 20% red, 27% blue, with 70% of opacity, it is possible? I'm using sass but I have not found a way to make this
.box
width: 100px
height: 100px
background: gray
margin: 50px auto 0 auto
border-color: #ff0000 #0000ff
My pen: http://codepen.io/mejingjard/pen/xwxLKO?editors=110
Yes it's possible, and it's actually really simple with rgba()
border-color: rgba(20%,30%,27%,0.7);
Read about this and more sass color functions at
http://sass-lang.com/documentation/Sass/Script/Functions.html#rgba-instance_method
You can give this a try, however this alternative is with four borders, not the three. With RGBA you can change the opacity. You can visit http://www.cssportal.com/css3-rgba-generator/ to generate the CSS3 RGBA colours; there you can also change the opacity.
div {
width: 100px;
height: 100px;
margin: auto;
}
.one {
border-top: 1px solid rgba(0, 255, 0, 0.7);
border-right: 1px solid rgba(255, 0, 0, 0.7);
border-bottom: 1px solid rgba(0, 0, 255, 0.7);
border-left: 1px solid rgba(255, 0, 0, .5);
<div class="one"></div>
Alternatively if you wanted to go for more of a gradient look you can try applying a CSS3 gradient within a pseudo-element, however only two border colors are adopted, and it's without the opacity.
.one{
margin: auto;
width: 100px;
height: 100px;
border: 1px solid transparent;
-moz-border-image: -moz-linear-gradient(top, #E93478 0%, #FF0 100%);
-webkit-border-image: -webkit-linear-gradient(top, #E93478 0%, #FF0 100%);
border-image: linear-gradient(to bottom, #E93478 0%, #FF0 100%);
border-image-slice: 1;}
<div class="one"></div>
I would like to have a mask that's fading out 16px from both sides.
So like: 16px fading in - white - 16px fading out.
What I got is this: DEMO
-webkit-mask-image: linear-gradient(to right, transparent, white), linear-gradient(to left, transparent, white);
-webkit-mask-repeat: no-repeat, no-repeat;
-webkit-mask-size: 16px 40px, 16px 40px;
-webkit-mask-position: 0 0, 100% 0;
-webkit-mask-origin: padding-box, padding-box;
The only problem is that it's not visible in the middle. How can i fix this?
One option is to add a third gradient (which will actually be uniformly white) covering the whole surface, and use -webkit-mask-composite: copy to make sure the other two gradients replace the parts on the sides:
-webkit-mask-image: linear-gradient(to right, transparent, white), linear-gradient(to left, transparent, white), linear-gradient(to right, white, white);
-webkit-mask-composite: copy;
-webkit-mask-repeat: no-repeat, no-repeat, no-repeat;
-webkit-mask-size: 16px 40px, 16px 40px, 100% 100%;
-webkit-mask-position: 0 0, 100% 0, 0 0;
-webkit-mask-origin: padding-box, padding-box, padding-box;
Demo: http://codepen.io/anon/pen/crEyL
Note that of course, all of this only works on WebKit browsers.
Try this.
Here is the codepen for demo CODEPEN
Also I have attached the code, If you have any doubt let me know.
html
<div class="div">
<span>Example Program</span>
</div>
CSS
.div {
box-shadow: 0 16px 0px 0px white, 0 -16px 0px 0px white, 12px 0 15px -4px rgba(31, 73, 125, 0.8), -12px 0 15px -4px rgba(31, 73, 125, 0.8);
-webkit-mask-position: 0 0, 100% 0;
-webkit-mask-size: 16px 40px, 16px 40px;
width: 30%;
height: 40px;
margin: 50px;
background: red;
}
span {
display: block;
background: rgb(255, 255, 255);
height: 40px;
}
This did the trick. Pretty hacky solution.
-webkit-mask-image: linear-gradient(white, white),linear-gradient(to right, white, transparent), linear-gradient(to left, white, transparent);
-webkit-mask-repeat: repeat,no-repeat, no-repeat;
-webkit-mask-size: 100% 100%,16px 100%, 16px 100%;
-webkit-mask-position: 0 0,0 0, 100% 0;
-webkit-mask-origin: padding-box, padding-box, padding-box;
-webkit-mask-composite: source-out;
Solution demo
I am trying to accomplish the left widget box below and as you can see, there is a diagonal linear gradient, as well as a shine from top to bottom. The one I created in CSS is to the right, while the one I am trying to accomplish is to the left. Is there a way I can accomplish this using only one background property? Or would I need to surround the entire div with another div so I can overlay a semi-transparent gradient on it? Thanks
UPDATED with code:
.drk-grad {
background: linear-gradient(to bottom, #d2d2d2 7%, #b1b1b1 100%);
-webkit-border-radius: 10px;
border-radius: 10px;
background-clip: padding-box;
-webkit-box-shadow: 0px 1px 3px 1px #969494;
box-shadow: 0px 1px 3px 1px #969494;
border-top: 1px solid rgba(255, 255, 255, 0.7);
border-left: 1px solid rgba(255, 255, 255, 0.3);
}
SOLUTION:
background: repeating-linear-gradient(rgba(255,255,255,.5) -1%, rgba(107, 107, 107, 0.1), repeating-linear-gradient(135deg, #b6b6b6, #B6B6B6 10px, #b2b2b2 10px, #b2b2b2 20px);
Generally you can add multiple backgrounds, separated by commas. The first one listed will appear on top.
http://css-tricks.com/stacking-order-of-multiple-backgrounds/
http://lea.verou.me/css3patterns/
Here's a basic outline. Play with the numbers for your exactly desired effect:
div {
background:
linear-gradient(to top, transparent, #b1b1b1 100%),
gray repeating-linear-gradient(45deg, transparent, transparent 35px,
rgba(255, 255, 255, 0.5) 35px,
rgba(255, 255, 255, 0.5) 70px);
background-clip: padding-box;
border-left: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 10px;
border-top: 1px solid rgba(255, 255, 255, 0.7);
box-shadow: 0px 1px 3px 1px #969494;
height: 250px;
width: 250px;
}
Demo: https://jsbin.com/fidaxigaxi/edit?html,css,output
I have a solid background color on a button, and I'm looking for some CSS(3?) that would overlay a semi-transparent white on top of the color, but only on the top 50% of it. I'm looking for a non-gradient, non-image-based shine effect.
How can this be accomplished without using an image? It's ok if the solution doesn't support older browsers.
EDIT: bookcasey's answer below seems to work except the font is also made transparent...
<!DOCTYPE html>
<html>
<head>
<style>
a
{
display: inline-block;
padding:30px;
background: salmon;
position: relative;
text-align: center;
text-decoration:none;
color:#000;
font-size:20pt;
font-weight:bold;
}
a:before
{
content: '';
width: 100%;
height: 50%;
background: rgba(255,255,255,0.5);
position: absolute;
top: 0;
left:0;
}
</style>
</html>
<body>
<div>
Test Link
</div>
</body>
</html>
Thanks,
Andy
Use an absolutely positioned pseudo element on a relative parent.
Demo
a {display: block; width: 100px; height: 50px; background: salmon; position: relative;}
a:before {
content: '';
width: 100%;
height: 50%;
background: rgba(255,255,255,.5);
position: absolute;
top: 0;
left:0;
}
Another, completely different technique (mentioned, but not explained in the comments) is the use of CSS3 gradients with a hard color stop.
a {display: block; width: 100px; height: 50px; position: relative;
background: -webkit-gradient(linear, 50% 100%, 50% 0%, color-stop(50%, rgba(255, 255, 255, 0)), color-stop(50%, rgba(255, 255, 255, 0.5))), salmon;
background: -webkit-linear-gradient(bottom, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, 0.5) 50%), salmon;
background: -moz-linear-gradient(bottom, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, 0.5) 50%), salmon;
background: -o-linear-gradient(bottom, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, 0.5) 50%), salmon;
background: linear-gradient(bottom, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, 0.5) 50%), salmon;}
Demo