How to use a radial gradient with a border-image - html

I am trying to use a border image where the source is a radial gradient. I have seen plenty of examples with images but have seen none with radial gradients.
Full example in My CodePen
#main {
width: 200px;
border: 8px solid red;
padding: 10px;
border-image:
radial-gradient( farthest-corner, #777 50%, #7770 60%) /* source */
28 / /* slice */
8px 8px 8px 8px / /* width */
4px 4px 4px 4px /* outset */
round; /* repeat */
}
I simply want to surround the box in small circles spaced a few pixels apart preferably using a CSS only solution. Though I am happy to hear other issues

You can do it with background like this:
#main {
width: 200px;
padding:10px;
background:
radial-gradient(circle at center, #777 60%, transparent 61%) top left/10px 10px repeat-x,
radial-gradient(circle at center, #777 60%, transparent 61%) bottom left/10px 10px repeat-x;
}
<div id="main">This element is surrounded by a radial-gradient-based border image!</div>
If you want all the sides you can do this:
#main {
width: 200px;
padding:13px 10px;
background:
radial-gradient(circle at center, #777 60%, transparent 61%) top left/10px 10px repeat-x,
radial-gradient(circle at center, #777 60%, transparent 61%) bottom left/10px 10px repeat-x,
radial-gradient(circle at center, #777 60%, transparent 61%) bottom left/10px 10px repeat-y,
radial-gradient(circle at center, #777 60%, transparent 61%) bottom right/10px 10px repeat-y;
}
<div id="main">This element is surrounded by a radial-gradient-based border image!</div>

Related

how to make line using css

I want to make a yellow line like in the image using css, but I don't have an idea how to make it, now I can only make line holes, but not vertical straight lines yet.
here is my code example
#holes {
-webkit-mask: radial-gradient(circle at 120px 100%, transparent 0, transparent 62px, black 62px, black 100%);
mask: radial-gradient(circle at 120px 100%, transparent 0, transparent 62px, black 62px, black 100%);
background-color: #1D3962;
background-image: radial-gradient(circle at 120px 100%, transparent 0, transparent 65px, yellow 65px, yellow 68px, transparent 68px, transparent 100%);
width: 100%;
height: 100vh;
margin: 0;
padding: 0;
}
I am writing one code for you that might solve your problem if you like the solution then please give it one like 😀
You can change the value of width to make it thin or thick.
*{
box-sizing: border-box;
margin: 0;
padding: 0;
}
#holes {
-webkit-mask: radial-gradient(circle at 120px 100%, transparent 0, transparent 62px, black 62px, black 100%);
mask: radial-gradient(circle at 120px 100%, transparent 0, transparent 62px, black 62px, black 100%);
background-color: #1D3962;
background-image: radial-gradient(circle at 120px 100%, transparent 0, transparent 65px, yellow 65px, yellow 68px, transparent 68px, transparent 100%);
width: 100%;
height: 100vh;
margin: 0;
padding: 0;
}
#holes::before{
content: "";
display: block;
width: 2px;
height: calc(100vh - 68px);
background-color: yellow;
margin-left: 120px;
}
<div id="holes"></div>

Applying mask to box-shadow

I have a div with a mask applied to it. I noticed that I can't apply a box-shadow on that same div, so I must move the shadow to a "wrapper" div.
The problem is that if the shadow is placed on the shadow div, the mask is not applied to the shadow.
How can I apply a mask to a div and to it's shadow?
.wrapper {
width: 200px;
height: 200px;
box-shadow: 17px 13px 7px 3px rgba(0,0,0,0.75);
}
.b {
width: 200px;
height: 200px;
background-color: yellow;
border: 2px solid black;
-webkit-mask: radial-gradient(
circle at center top,
transparent 30px,
black 31px
) top / 100% 51%,
radial-gradient(
circle at right bottom,
transparent 30px,
black 31px
) right bottom / 51% 51%,
radial-gradient(
circle at left bottom,
transparent 30px,
black 31px
) left bottom / 51% 51%;
-webkit-mask-repeat: no-repeat;
}
<div class="wrapper">
<div class="b"></div>
</div>
You need a drop-shadow, not a box-shadow:
.wrapper {
width: 200px;
height: 200px;
filter:drop-shadow(17px 13px 7px rgba(0,0,0,0.75));
}
.b {
width: 200px;
height: 200px;
background-color: yellow;
border: 2px solid black;
-webkit-mask: radial-gradient(
circle at center top,
transparent 30px,
black 31px
) top / 100% 51%,
radial-gradient(
circle at right bottom,
transparent 30px,
black 31px
) right bottom / 51% 51%,
radial-gradient(
circle at left bottom,
transparent 30px,
black 31px
) left bottom / 51% 51%;
-webkit-mask-repeat: no-repeat;
}
<div class="wrapper">
<div class="b"></div>
</div>

Applying multiple mask-image to a single div

I can apply a mask-image at any place on a div I want, but can I apply more than one mask-image on the same div?
Example with a single mask-image:
div {
width: 200px;
height: 200px;
background-color: green;
border: 2px solid black;
-webkit-mask-image: radial-gradient(
circle at center top,
transparent 30px,
black 31px
);
}
<div></div>
What would the code look like if I wanted to have the same mask applied at the top and at the bottom at the same time?
div {
width: 200px;
height: 200px;
background-color: green;
border: 2px solid black;
-webkit-mask-image: radial-gradient(
circle at center top,
transparent 30px,
black 31px
), radial-gradient(
circle at center bottom,
transparent 30px,
black 31px
);
}
<div></div>
Edit: I'm aware Chrome supports mask-composite, but that works (at the time of writing this) only with Chrome.
You need to play with the size and position. mask work the same way as background-image so simply imagine your self making two images on the same element (one on the top and the other on the bottom)
div {
width: 200px;
height: 200px;
background-color: green;
border: 2px solid black;
-webkit-mask:
radial-gradient( circle at center top, transparent 30px, black 31px) top,
radial-gradient( circle at center bottom, transparent 30px, black 31px) bottom;
-webkit-mask-size:100% 51%; /* each one half the size */
-webkit-mask-repeat:no-repeat; /* don't forget this */
}
<div></div>
Another idea with one mask:
div {
width: 200px;
height: 200px;
background-color: green;
border: 2px solid black;
-webkit-mask: radial-gradient(circle, transparent 30px, black 31px) 0 100px; /* 100px is half the height */
}
<div></div>
and with the border:
div {
width: 200px;
height: 200px;
background: radial-gradient(circle, transparent 30px, black 0 33px,green 33px) 0 100px border-box;
border: 2px solid black;
-webkit-mask: radial-gradient(circle, transparent 30px, black 31px) 0 100px; /* 100px is half the height */
}
<div></div>
A solution with mask-composite:
div {
width: 200px;
height: 200px;
background-color: green;
border: 2px solid black;
-webkit-mask:
radial-gradient( circle at center top, transparent 30px, black 31px),
radial-gradient( circle at center bottom, transparent 30px, black 31px),
linear-gradient(black,black); /* this layer is mandatory */
-webkit-mask-composite: destination-in;
mask-composite: exclude; /* for non-webkit browser */
}
<div></div>

Circle bullets for background with CSS and HTML

The code in CodePen here provides bullets, stripes and some squares. I want circles. I found this source but I don't know how to implement it.
Code also here
#import url(https://fonts.googleapis.com/css?family=Oswald);
div {
text-align: center;
font: bold 21px 'Oswald',sans-serif;
text-shadow: 1px 1px 0 #fff, 2px 2px 0 #999;
text-transform: uppercase;
}
.dotted {
padding: 2.25em 1.6875em;
background-image: -webkit-repeating-radial-gradient(45px 45px, circle cover, rgba(0,0,0,.90), rgba(0,0,0,.90) 2px, transparent 0px, transparent 100%);
background-image: -moz-repeating-radial-gradient(center center, rgba(0,0,0,.2), rgba(0,0,0,.2) 1px, transparent 1px, transparent 100%);
background-image: -ms-repeating-radial-gradient(center center, rgba(0,0,0,.2), rgba(0,0,0,.2) 1px, transparent 1px, transparent 100%);
background-image: repeating-radial-gradient(center center, rgba(0,0,0,.2), rgba(0,0,0,.2) 1px, transparent 1px, transparent 100%);
-webkit-background-size: 9px 9px;
-moz-background-size: 9px 9px;
background-size: 9px 9px;
}
You can do this by changing the radius, notice the rgba(0,0,0,0.5) 4px instead of rgba(0,0,0,0.5) 1px on the first line about background-image:.
Code
.dotted {
padding: 2.25em 1.6875em;
background-image: -webkit-repeating-radial-gradient(center center, rgba(0,0,0,.2), rgba(0,0,0,0.5) 4px, transparent 1px, transparent 100%);
background-image: -moz-repeating-radial-gradient(center center, rgba(0,0,0,.2), rgba(0,0,0,.2) 1px, transparent 1px, transparent 100%);
background-image: -ms-repeating-radial-gradient(center center, rgba(0,0,0,.2), rgba(0,0,0,.2) 1px, transparent 1px, transparent 100%);
background-image: repeating-radial-gradient(center center, rgba(0,0,0,.2), rgba(0,0,0,.2) 1px, transparent 1px, transparent 100%);
-webkit-background-size: 3px 3px;
-moz-background-size: 3px 3px;
background-size: 10px 10px;
}

Only vertical line in a square

I need only horizontal line in a square, I tried in this way but in my case I need only horizontal line on top ,
div {
height: 100px;
width: 200px;
border: 1px solid;
background-color: gray;
background-image: linear-gradient(to bottom, black, black), linear-gradient(to right, red, transparent), linear-gradient(to right, black, black), linear-gradient(to bottom, red, transparent);
background-repeat: no-repeat;
background-size: 1px 100%, 1px 100%, 100% 1px, 100% 1px;
background-position: 20px 0px, 21px 0px, 0px 10px, 0px 11px;
box-shadow: inset 0px 0px 3px red;
}
<div></div>
below is my working fiddle
http://jsfiddle.net/uXbn6/4322/
div {
height: 100px;
width: 200px;
border: 1px solid;
background-color: gray;
background-image:
linear-gradient(to bottom, black, black),
linear-gradient(to right, red, transparent),
linear-gradient(to right, black, black),
linear-gradient(to bottom, red, transparent);
background-repeat: no-repeat;
background-size: 1px 100%, 1px 100%, 100% 1px, 100% 1px;
background-position: 0px 10px, 0px 11px;
box-shadow: inset 0px 0px 3px red;
}
Fiddle