Currently the whole thing is red.
How would I make this gradient, half the left side red, half blue?
That is all I am trying to do in the code.
div {
width: 640px;
height: 340px;
background:
linear-gradient(45deg,
transparent,
transparent 7px,
red 7px,
red 7.5px,
transparent 7.5px,
transparent 10px),
linear-gradient(-45deg,
transparent,
transparent 7px,
red 7px,
red 7.5px,
transparent 7.5px,
transparent 10px);
background-size: 10px 10px;
}
<div></div>
Use your gradient configuration inside mask then consider a regular background for your separation. I optimized you gradient configuration a little as well:
div {
width: 640px;
height: 340px;
background: linear-gradient(90deg, red 50%,blue 0);
-webkit-mask:
linear-gradient( 45deg, #0000 7px, #000 0 7.5px, #0000 0 10px),
linear-gradient(-45deg, #0000 7px, #000 0 7.5px, #0000 0 10px);
-webkit-mask-size: 10px 10px;
}
<div></div>
You could use repeating-linear-gradient, background-size, background-position , background-repeat and background-position all together. So you can lay on different areas differents sized gradients
Possible example:
div {
border:solid;
width: 640px;
aspect-ratio:3/1.5;
background:
repeating-linear-gradient( 45deg,transparent 0 7px,red 7px 8px,transparent 8px 10px) 0 0 / 50% 100% no-repeat,
repeating-linear-gradient(135deg,transparent 0 7px,red 7px 8px,transparent 8px 10px) 0 0 / 50% 100% no-repeat,
repeating-linear-gradient(225deg,transparent 0 7px,blue 7px 8px,transparent 8px 10px) 100% 0 / 50% 100% no-repeat,
repeating-linear-gradient(135deg,transparent 0 7px,blue 7px 8px,transparent 8px 10px) 100% 0px / 50% 100% no-repeat
ivory /* bgcolor */
}
<div></div>
On top of half of the block we place the layer in a pseudo-element with a css filter on the background. Filter properties are different. In our case, we apply a filter that rotates the hue palette backdrop-filter: hue-rotate(240deg) so that the red becomes blue. 240deg means rotate 240 degrees clockwise.
div {
width: 640px;
height: 340px;
background: linear-gradient(45deg, transparent, transparent 7px, red 7px, red 7.5px, transparent 7.5px, transparent 10px), linear-gradient(-45deg, transparent, transparent 7px, red 7px, red 7.5px, transparent 7.5px, transparent 10px);
background-size: 10px 10px;
position: relative;
}
div::after {
position: absolute;
left: 50%;
top: 0;
display: block;
width: 50%;
height: 100%;
content: '';
backdrop-filter: hue-rotate(240deg);
}
<div></div>
Related
I have a striped divider in CSS, with repeating linear gradient, but it is doing some strange thing, here is an image :
As you can see, the thickness of some of the stripes are not the same, I would like to have the striped divider like this, but all with the same "font-weight", I tried to fix the code adding or reducing pixels, but not working
Here is the code :
.striped_divider {
height: 20px;
background: -webkit-repeating-linear-gradient(135deg, transparent 2px, transparent 7px,#cccccc 8px,#cccccc 8px);
background: -o-repeating-linear-gradient(135deg, transparent 2px, transparent 7px,#cccccc 8px,#cccccc 8px);
background: repeating-linear-gradient(-45deg, transparent 2px, transparent 7px,#cccccc 8px,#cccccc 8px);
}
<div class="striped_divider"></div>
You can do nothing, this is how gradient are rendred when we deal with small close values (especially in Google Chrome, in Fiferfox it should be better).
Increase the values and you will see that the effect will slowly disappear:
.striped_divider0 {
height: 20px;
margin:5px;
background: repeating-linear-gradient(-45deg, transparent 2px, transparent 7px, #cccccc 8px, #cccccc 8px);
}
.striped_divider {
height: 20px;
margin:5px;
background: repeating-linear-gradient(-45deg, transparent 2px, transparent 7px, #cccccc 7px, #cccccc 8px);
}
.striped_divider1 {
height: 20px;
margin:5px;
background: repeating-linear-gradient(-45deg, transparent 2px, transparent 7px, #cccccc 7px, #cccccc 10px);
}
.striped_divider2 {
height: 20px;
margin:5px;
background: repeating-linear-gradient(-45deg, transparent 2px, transparent 7px, #cccccc 7px, #cccccc 15px);
}
<div class="striped_divider0"></div>
<div class="striped_divider"></div>
<div class="striped_divider1"></div>
<div class="striped_divider2"></div>
You can try skew transformation, it should give better result:
.striped_divider {
height: 20px;
margin: 5px;
background: repeating-linear-gradient(to right, transparent 2px, transparent 9px, #cccccc 10px, #cccccc 10px);
transform: skew(-45deg);
}
.striped_divider1 {
height: 20px;
margin: 5px;
background: repeating-linear-gradient(-45deg, transparent 2px, transparent 7px, #cccccc 8px, #cccccc 8px);
}
<div class="striped_divider"></div>
<div class="striped_divider1"></div>
As you can see in the example below (I've added a css zoom) the lines are indeed the same width. As #Roy already said, it's just an optical illusion.
Edit: I noticed I didn't provide you with a possible solution. As already noted by #Roy, a possible solution would be to repeat an image. The image doesn't have to be particularly high quality, so I don't think it will influence your performance.
.striped_divider {
height: 20px;
background: -webkit-repeating-linear-gradient(135deg, transparent 2px, transparent 7px,#cccccc 8px,#cccccc 8px);
background: -o-repeating-linear-gradient(135deg, transparent 2px, transparent 7px,#cccccc 8px,#cccccc 8px);
background: repeating-linear-gradient(-45deg, transparent 2px, transparent 7px,#cccccc 8px,#cccccc 8px);
transform: scale(2.5);
}
<div class="striped_divider"></div>
It indeed seems like a rendering issue, at least in Chrome.
To get around this, you can use linear-gradient & background-size instead:
.striped_divider {
height: 20px;
background-image: linear-gradient(-45deg,
#cccccc 6.25%,
#ffffff 6.25%,
#ffffff 50%,
#cccccc 50%,
#cccccc 56.25%,
#ffffff 56.25%,
#ffffff 100%
);
background-size: 8px 8px;
}
<div class="striped_divider"></div>
I made this using https://stripesgenerator.com
I don't how it can't be named in english - I neither don't know in french to be honest - but I need to design an infinite line composed by normal and invert chevron. It's seems to be called a chevron line.
Here's an example of what I want and I only need one line :
Here what I've done so far with before and after pseudo elements. Maybe there's another way that i can't think of. Right now i didn't achieve to display it as chevron, i don't understand how repeating linear gradient works for the position.
.chevron-line {
position: relative;
height: 15px;
background: white;
}
.chevron-line::before,
.chevron-line::after {
content: '';
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.chevron-line::before {
background: repeating-linear-gradient(135deg,
#000, #000 5px /* black stripe */,
transparent 0, transparent 20px /* blue stripe */
);
}
.chevron-line::after {
background: repeating-linear-gradient(-135deg,
transparent 0px, transparent 10px /* blue stripe */,
#000, #000 15px /* black stripe */,
transparent 0px, transparent 20px /* blue stripe */
);
}
<div class="chevron-line"></div>
you can do this with css gradient
div.box {
height: 500px;
background:
linear-gradient(135deg, #ffffff 25%, transparent 25%) -50px 0,
linear-gradient(225deg, #ffffff 25%, transparent 25%) -50px 0,
linear-gradient(315deg, #ffffff 25%, transparent 25%),
linear-gradient(45deg, #ffffff 25%, transparent 25%);
background-size: 100px 100px;
background-color: #000000;
}
<div class="box">
</div>
make it thin like this
div.box {
height: 500px;
background:
linear-gradient(135deg, #ffffff 35%, transparent 35%) -50px 0,
linear-gradient(225deg, #ffffff 35%, transparent 35%) -50px 0,
linear-gradient(315deg, #ffffff 35%, transparent 35%),
linear-gradient(45deg, #ffffff 35%, transparent 35%);
background-size: 100px 100px;
background-color: #000000;
}
<div class="box"></div>
I do not know if this is even possible with only css. I want to make a circle with transparent horizontal lines and you can change size and position of each of these lines. Something like this png picture:
I did this so far, but it is not responsive it has not transparent lines inside, but you can move all lines freely.
.enjoy-css {
box-sizing: content-box;
width: 300px;
height: 300px;
position: absolute;
border: none;
border-radius: 150px;
background: linear-gradient(white, white), linear-gradient(white, white), linear-gradient(white, white), linear-gradient(white, white), linear-gradient(white, white)black;
background-repeat: no-repeat;
background-position: 90% 90%, 55% 75%, 90% 10%, 95% 30%, 90%;
background-origin: padding-box;
background-size: 124px 20px, 153px 20px, 124px 20px, 153px 20px, 80px 20px;
}
<div class="enjoy-css">
<span></span>
</div>
You can use svg to create the responsive shapes like below.
For this first you have to create the svg of your shape inside svg <symbol> tag so that you can use this later.
Then create a div having class enjoy-css and then use the previously created svg using <use>. Don't forget to give width="100%" to the <svg> for responsive purpose
svg.defs-only {
display: block;
position: absolute;
height: 0;
width: 0;
margin: 0;
padding: 0;
border: none;
overflow: hidden;
}
body {
background: gold;
}
.enjoy-css {
max-width: 400px;
}
<svg class="defs-only" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400px" height="400px">
<symbol id="potofgold" >
<path fill-rule="evenodd" fill="rgb(0, 0, 0)"
d="M387.395,270.000 L154.000,270.000 L154.000,298.000 L374.370,298.000 C368.372,308.648 361.409,318.675 353.632,328.000 L103.000,328.000 L103.000,356.000 L325.121,356.000 C290.863,383.519 247.363,400.000 200.000,400.000 C89.543,400.000 0.000,310.457 0.000,200.000 C0.000,177.987 3.567,156.809 10.136,137.000 L263.000,137.000 L263.000,109.000 L21.855,109.000 C28.645,95.734 36.895,83.344 46.356,72.000 L238.000,72.000 L238.000,44.000 L74.879,44.000 C109.140,16.485 152.638,0.000 200.000,0.000 C310.457,0.000 400.000,89.543 400.000,200.000 C400.000,224.628 395.538,248.212 387.395,270.000 ZM326.000,187.000 L63.000,187.000 L63.000,215.000 L326.000,215.000 L326.000,187.000 Z"/>
</symbol>
</svg>
<div class="enjoy-css"><svg viewBox="0 0 400 400" width="100%"><use xlink:href="#potofgold"/></svg></div>
This is it:
body {
background: #aaa;
background: url(http://www.lorempixel.com/600/600/abstract); /* background to show transparency */
}
.circle {
max-width: 20em; /* Set the max diameter */
margin: 0 auto;
}
.circle span {
position: relative;
display: block;
padding-bottom: 100%;
}
.circle span::after {
content: "";
display: block;
position: absolute;
width: 100%;
top: 0;
bottom: 0;
border-radius: 50%;
background-image: linear-gradient(
black 10%,
transparent 10%,
transparent 18%,
black 18%,
black 28%,
transparent 28%,
transparent 36%,
black 36%,
black 45%,
transparent 45%,
transparent 55%,
black 55%,
black 64%,
transparent 64%,
transparent 72%,
black 72%,
black 82%,
transparent 82%,
transparent 90%,
black 90%
),
linear-gradient(to right, transparent 60%, black 60%),
linear-gradient(to right, transparent 70%, black 70%),
linear-gradient(
to right,
black 15%,
transparent 15%,
transparent 85%,
black 85%
),
linear-gradient(to left, transparent 60%, black 60%),
linear-gradient(to left, transparent 70%, black 70%);
background-size: 100%, 100% 20%, 100% 40%, 100% 20%, 100% 20%, 100% 20%;
background-position: top, top, top, 40%, 0 70%, 0 90%;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<html>
<body>
<div class="circle">
<span></span>
</div>
</body>
</html>
I'm trying to make a shape with four negatively curved corners, and I tried the radial gradients. However, only one of the corners is being applied, and I can't figure out why.
https://jsfiddle.net/xiej/1Lqysaho/1/
#shape2 {
width: 120px;
height: 120px;
position: absolute;
top: 400px;
right: 400px;
background-image:
radial-gradient(circle at 0px 0px, #FFF 0px, #FFF 60px, #F00 60px),
radial-gradient(circle at 0px 120px, #FFF 0px, #FFF 60px, #F00 60px),
radial-gradient(circle at 120px 0px, #FFF 0px, #FFF 60px, #F00 60px),
radial-gradient(circle at 120px 120px, #FFF 0px, #FFF 60px, #F00 60px);
}
The last color stop of each radial gradient is covering up the rest of the square, think of them layering over each other. I'm not sure that my fix is the best way to get the shape you're looking for, but I think this will make the shape at least! I shortened the stops to end the radial gradient before it would cover any of the other three corners.
https://jsfiddle.net/1Lqysaho/2/
background: #F00;
background-image:
radial-gradient(circle at 0px 0px, #FFF 60px, #f00 1px, transparent 1px),
radial-gradient(circle at 0px 120px, #FFF 60px,#f00 1px, transparent 1px),
radial-gradient(circle at 120px 0px, #FFF 60px,#f00 1px, transparent 1px),
radial-gradient(circle at 120px 120px, #FFF 60px,#f00 1px, transparent 1px);
div.round {
background:
-webkit-radial-gradient(0 100%, circle, rgba(204,0,0,0) 14px, #c00 15px),
-webkit-radial-gradient(100% 100%, circle, rgba(204,0,0,0) 14px, #c00 15px),
-webkit-radial-gradient(100% 0, circle, rgba(204,0,0,0) 14px, #c00 15px),
-webkit-radial-gradient(0 0, circle, rgba(204,0,0,0) 14px, #c00 15px);
}
div, div.round {
background-position: bottom left, bottom right, top right, top left; c
-moz-background-size: 50% 50%;
-webkit-background-size: 50% 50%;
background-repeat: no-repeat;
}
div {
width: 130px;
height:100px;
margin:15px auto;
padding:13px 15px;
}
<div class="round"></div>
I want to create Round Edges Rectangle With Gradient Color Stripes Border.
I want to use the img tag or div tag to include the image and the Gradient Striped Border.
This is how it needs to look like:
I try to search around and i found that (SCSS) example: https://jsfiddle.net/rami7250/yujsz7wf/
and i got this SCSS code:
.module {
background: white;
border: 1px solid #ccc;
margin: 3%;
> h2 {
padding: 1rem;
margin: 0 0 0.5rem 0;
}
> p {
padding: 0 1rem;
}
/*animation: widen 10s linear alternate infinite;*/
}
.stripe-1 {
color: white;
background: repeating-linear-gradient(
45deg,
#606dbc,
#606dbc 10px,
#465298 10px,
#465298 20px
);
}
As you can see, that feature effect only background and not border.
How do I make that Rectangle to display Gradient Color Stripes in his Border Via CSS/SCSS?
One option would be to use a linear-gradient in the required pattern as background-image and put the required content on top of this background. This approach would work as long as the content, be it image or any text or whatever doesn't require to be transparent. The output is also responsive as can be seen by hovering on the element.
With just the strips: (a white layer is placed on top of the gradient to show only the strips)
div {
height: 250px;
width: 400px;
background: linear-gradient(white, white),
linear-gradient(60deg, orange 0%, orange 3.5%, white 3.5%, white 7%, hotpink 7%, hotpink 10.5%, black 10.5%, black 14%, brown 14%, brown 17.5%, aqua 17.5%, aqua 21%, green 21%, green 25%, orange 25%, orange 28.5%, white 28.5%, white 32%, hotpink 32%, hotpink 35.5%, black 35.5%, black 39%, brown 39%, brown 42.5%, aqua 42.5%, aqua 46%, green 46%, green 50%, orange 50%, orange 53.5%, white 53.5%, white 57%, hotpink 57%, hotpink 60.5%, black 60.5%, black 64%, brown 64%, brown 67.5%, aqua 67.5%, aqua 71%, green 71%, green 75%, orange 75%, orange 78.5%, white 78.5%, white 82%, hotpink 82%, hotpink 85.5%, black 85.5%, black 89%, brown 89%, brown 92.5%, aqua 92.5%, aqua 96%, green 96%, green 100%);
padding: 10px 20px;
border-radius: 20px;
background-origin: content-box, padding-box;
background-clip: content-box, padding-box;
}
/* just for demo */
div {
transition: all 1s;
}
div:hover {
height: 300px;
width: 500px;
}
<div></div>
With image inside the div:
div {
height: 250px;
width: 400px;
background: linear-gradient(white, white), linear-gradient(60deg, orange 0%, orange 3.5%, white 3.5%, white 7%, hotpink 7%, hotpink 10.5%, black 10.5%, black 14%, brown 14%, brown 17.5%, aqua 17.5%, aqua 21%, green 21%, green 25%, orange 25%, orange 28.5%, white 28.5%, white 32%, hotpink 32%, hotpink 35.5%, black 35.5%, black 39%, brown 39%, brown 42.5%, aqua 42.5%, aqua 46%, green 46%, green 50%, orange 50%, orange 53.5%, white 53.5%, white 57%, hotpink 57%, hotpink 60.5%, black 60.5%, black 64%, brown 64%, brown 67.5%, aqua 67.5%, aqua 71%, green 71%, green 75%, orange 75%, orange 78.5%, white 78.5%, white 82%, hotpink 82%, hotpink 85.5%, black 85.5%, black 89%, brown 89%, brown 92.5%, aqua 92.5%, aqua 96%, green 96%, green 100%);
padding: 10px 20px;
border-radius: 20px;
background-origin: content-box, padding-box;
background-clip: content-box, padding-box;
}
img {
height: 250px;
width: 400px;
}
/* just for demo */
div, img {
transition: all 1s;
}
div:hover, div:hover img {
height: 300px;
width: 500px;
}
<div>
<img src='http://lorempixel.com/400/250/nature/1' />
</div>
With repeating linear gradient: (thanks to vals for creating the demo)
div {
height: 250px;
width: 400px;
background: linear-gradient(white,white), repeating-linear-gradient(60deg, orange 0%, orange 3.5%, white 3.5%, white 7%, hotpink 7%, hotpink 10.5%, black 10.5%, black 14%, brown 14%, brown 17.5%, aqua 17.5%, aqua 21%, green 21%, green 25%);
background-attachment: padding-box, border-box;
padding: 10px 20px;
border-radius: 20px;
background-origin: content-box, padding-box;
background-clip: content-box, padding-box;
}
/* just for demo */
div {
transition: all 1s;
}
div:hover {
height: 300px;
width: 500px;
}
<div>
</div>
Note: The jagged edges are something that are tough to avoid when using angled gradients. They can be reduced by adjusting the color stop points.
There is no need for this to be so convoluted, it takes two lines of CSS:
.module {
border: 20px solid;
border-image: repeating-linear-gradient(45deg,#606dbc,#606dbc 10px,#465298 10px,#465298 20px) 20;
}
A fork of your Fiddle: https://jsfiddle.net/5k70jt5f/1/
Found somthing that can be a key to that design. See here: https://jsfiddle.net/rami7250/jaca7sb4/
Here is the source of the code: http://codepen.io/SitePoint/pen/DKhkf
CSS:
div {
position: relative;
height: 100%;
}
div:before, div:after {
position: absolute;
content: '';
height: 1em;
top: 0;
left: 0;
right: 0;
}
div:after {
top: auto;
bottom: 0;
}
div:before {
background: linear-gradient(90deg, #1abc9c 1%, #2ecc71 1%, #2ecc71 29%, #3498db 29%, #3498db 32%, #9b59b6 32%, #9b59b6 37%, #34495e 37%, #34495e 53%, #f1c40f 53%, #f1c40f 69%, #e67e22 69%, #e67e22 67%, #e74c3c 67%, #e74c3c 74%, #ecf0f1 74%, #ecf0f1 100%, #95a5a6 100%);
}
div:after {
background: linear-gradient(90deg, #1abc9c 10%, #2ecc71 10%, #2ecc71 12.5%, #3498db 12.5%, #3498db 28%, #9b59b6 28%, #9b59b6 35%, #34495e 35%, #34495e 60%, #f1c40f 60%, #f1c40f 69%, #e67e22 69%, #e67e22 83%, #e74c3c 83%, #e74c3c 88%, #ecf0f1 88%, #ecf0f1 96%, #95a5a6 96%);
}
div {
padding-top: 20px;
width: 450px;
}
However, i cant set it on the right and left side of the div. Only top and bottom effected.
Another idea, we can mask a repeating linear gradient background.
body {
background: gray;
}
.stripe {
--thickness: 10px;
--stripe: 20px;
height: 200px;
width: 300px;
--mask: linear-gradient(#000 0 0) 0 0/100% var(--thickness) no-repeat,
linear-gradient(#000 0 0) 0 0/var(--thickness) 100% no-repeat,
linear-gradient(#000 0 0) 0 100% / 100% var(--thickness) no-repeat,
linear-gradient(#000 0 0) 100% 0/ var(--thickness) 100% no-repeat;
-webkit-mask: var(--mask);
mask: var(--mask);
background: repeating-linear-gradient(45deg, #febf28 0 var(--stripe), #000 var(--stripe) calc(var(--stripe) * 2))
}
.original-gradient {
margin-top: 20px;
--stripe: 20px;
height: 200px;
width: 300px;
background: repeating-linear-gradient(45deg, #febf28 0 var(--stripe), #000 var(--stripe) calc(var(--stripe) * 2))
}
<div class="stripe"></div>
<div class="original-gradient"></div>