CSS gradients start to fade when generating more lines every x% - html

I'm trying to create a gradient that simply shows a red line every x%.
When I start generating more lines the red stripes seems to start fading into white.
the .four-stripes selector gives a nice result, but when I add one more red line, like in more-stripes everything starts to get blurry...
See codepen for an example:
div {
width: 1200px;
height: 20px;
}
.four-stripes {
background: linear-gradient(90deg,red 0.00% 0.27%,transparent 0.27% 1.92%,red 1.92% 2.19%,transparent 2.19% 3.84%,red 3.84% 4.11%,transparent 4.11% 5.75%,red 5.75% 6.03%,transparent 6.03% 100%);
}
.more-stripes {
background: linear-gradient(90deg,red 0.00% 0.27%,transparent 0.27% 1.92%,red 1.92% 2.19%,transparent 2.19% 3.84%,red 3.84% 4.11%,transparent 4.11% 5.75%,red 5.75% 6.03%,transparent 6.03% 7.67%,red 7.67% 7.95%,transparent 7.95% 100%)
}
<div>
<div class="four-stripes"></div>
<div class="more-stripes"></div>
</div>

Using "repeating-linear-gradient" may help.
div {
width: 1200px;
height: 20px;
}
.more-stripes {
background: repeating-linear-gradient(
90deg,
red,
red 5px,
transparent 5px,
transparent 20px
);
}
<div>
<div class="more-stripes"></div>
</div>

make the gradient easy and adjust the background-size.
div {
height: 20px;
margin:5px;
}
.four-stripes {
background:
linear-gradient(to right,red 5px,transparent 0 100%)
left/25% 100%;
}
.more-stripes {
background:
linear-gradient(to right,red 5px,transparent 0 100%)
left/15% 100%;
}
<div>
<div class="four-stripes"></div>
<div class="more-stripes"></div>
</div>
Or like this if you want to keep a fixed distance between stripes:
div {
height: 20px;
margin:5px;
}
.four-stripes {
background:
repeating-linear-gradient(to right,red 0 5px,transparent 0 40px)
left/calc(4*40px) 100% no-repeat;
}
.more-stripes {
background:
repeating-linear-gradient(to right,red 0 5px,transparent 0 40px)
left/calc(6*40px) 100% no-repeat;
}
<div>
<div class="four-stripes"></div>
<div class="more-stripes"></div>
</div>

Related

How to draw a background-image with multiple radial-gradient or linear-gradient?

I want to create a background-image with a gradient effect like below, how can I implement it?
And here is what I'm trying to do, and abviously I failed.
background:
radial-gradient(circle at 50% 0%,#060319 30%,#110844 ,#7226aa ,#fcb6f7 40%,transparent 50%),
radial-gradient(circle at 50% 100%,#060319 30%,#110844 ,#7226aa ,#fcb6f7 40%,transparent 50%);
body,
html,
* {
margin: 0;
padding: 0;
}
/* prettier-ignore */
body {
height: 100vh;
color: #fff;
background:
radial-gradient(circle at 50% 0%,#060319 30%,#110844 ,#7226aa ,#fcb6f7 40%,transparent 50%),
radial-gradient(circle at 50% 100%,#060319 30%,#110844 ,#7226aa ,#fcb6f7 40%,transparent 50%);
background-color: #fcb6f7;
}
.text-box {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
border: 1px solid red;
height: 100vh;
}
(codepen)
The closest i can get, change the gradient to
background:
radial-gradient(circle closest-corner at 50% 0%, rgba(6 3 25 / 1) 105%, rgba(114 38 170 / 1) 130%, transparent 200%),
radial-gradient(circle closest-corner at 50% 100%, rgba(6 3 25 / 1) 105%, rgba(114 38 170 / 1) 130%, transparent 200%);
You can use Hex, I changed it to RGBA for experiment.
But you really need to have a vertical container to the effect to show correctly, else it will combine and look weird.

How do I make a div like this be able to expand to any size while having the corner triangles stay the same size?

As I said in the title, I want this div to be able to be any size, but without the corner triangles or the line on top getting bigger:
How could I achieve something like this with CSS?
You may use gradients and padding.
possible example
body {
background:linear-gradient(to bottom left , #f8f3e0, silver, #f8f3e0, silver, #f8f3e0, silver, #f8f3e0, silver, #f8f3e0, silver ) ;
}
div {
margin: 1em;
padding: 1.6em 0.5em 1em;
background:
linear-gradient(140deg, transparent 1em, black 1.07em) 0 0 / 1.7em 1.45em no-repeat,
linear-gradient(220deg, transparent 1em, black 1.07em) 100% 0 / 1.7em 1.45em no-repeat,
linear-gradient( to bottom, transparent 1.3em, black 1.3em 1.45em, #e0e5c1 1.45em);
}
div+div {
width: 50vmin;
float: left;
filter:drop-shadow(0 0 1px crimson);
}
div+div+div {
width: 30vmax;
filter: drop-shadow(1px 0px) drop-shadow(-1px 0px) drop-shadow(0 1px); /* a border ? */
}
<div>
<h1>title</h1>
<p>Whatever comes inside</p>
</div>
<div>
<h1>title</h1>
<p>Whatever comes inside</p>
</div>
<div>
<h1>title</h1>
<p>Whatever comes inside</p>
</div>
an idea using clip-path:
.box {
/* adjust the variable to control the clip-path*/
--b:10px;
--c:8px;
/**/
border-top:10px solid #000;
height:100px;
background:#e0e5c1;
clip-path:polygon(var(--b) 0,var(--b) var(--c),calc(100% - var(--b)) var(--c),calc(100% - var(--b)) 0,100% var(--c),100% 100%,0 100%,0 var(--c));
}
<div class="box"></div>

CSS - fading gradient border from-to

I want to make my whole div section with fading border. Here is my code:
.usermanagement {
-webkit-border-image: -webkit-gradient(
linear,
left top,
left bottom,
from(#fff),
to(#afd4ec),
color-stop(0.2, #afd4ec)
)
0 0 0 0 repeat repeat;
}
The effect is exactly what I want but only for top:
Then all goes to light blue and finishes like this:
Without this fading effect. I want to make the same effect as in the top for the bottom end of the section. How it is possible?
You can try like below. make sure to correctly set the different values.
.box {
height:50px; /* this need to be a multiple of 10 for the effect to work */
border-top: 10px solid;
border-bottom:10px solid;
background:#f2f2f2;
border-image:repeating-linear-gradient(#fff 0,red 10px) 10;
}
<div class="box"></div>
You can also do it with multiple background:
.box {
height:50px;
border-top:10px solid transparent;
border-bottom:10px solid transparent;
background:
linear-gradient(#fff ,red ) top,
linear-gradient(#fff ,red ) bottom, /* use (red, #fff) here for the opposite effect */
#f2f2f2;
background-size:100% 10px;
background-origin:border-box;
background-repeat:no-repeat;
}
<div class="box"></div>

CSS / HTML gradient fill pattern is glitchy in Firefox

The following is a minimal (ish) example in which a chequered gradient fill pattern is glitchy in Firefox (version 74) i.e. it is not pixel perfect. There are line artefacts. Why is this? Is that normal? Is there a fix, other than using an image for the background?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" />
<style>
.r{width:20px;height:20px;background:white;float:left;}
.w{overflow:hidden;}
#p75{
width:80px;
height:20px;
background-position:0px 0px,10px 10px;
background-size:20px 20px;
background-image:linear-gradient(45deg,#ccc 25%,transparent 25%,transparent 75%,#ccc 75%,#ccc 100%),
linear-gradient(45deg,#ccc 25%,white 25%,white 75%,#ccc 75%,#ccc 100%);
float:left;
}
</style>
</head>
<body>
<div class="w">
<div class="r">0</div>
<div id="p75"></div>
</div>
</body>
Rotating gradients have always had that problem for more on that check this question
One way to fix the issue is to not use angles at all, and make use of repeating gradients.
html {
height: 100%;
background:
repeating-linear-gradient(90deg, #fff 0px 10px, transparent 10px 20px),
repeating-linear-gradient(0deg, #000 0px 10px, #fff 10px 20px);
background-blend-mode: difference;
}
Edit: thanks to #Temani Afif without repeating gradient.
html {
height: 100%;
background:
linear-gradient(90deg, #fff 50%, transparent 0) 0 0/20px 100%,
linear-gradient(0deg, #000 50%, #fff 0) 0 0/100% 20px;
background-blend-mode: difference;
}
you can overlap them a tiny bit , here i added 0.1% to the color start/stop setup , chrome use to be the one.
.r {
width: 20px;
height: 20px;
background: white;
float: left;
}
.w {
overflow: hidden;
}
#p75,
.p75 {
width: 80px;
height: 20px;
background-position: 0px 0px, 10px 10px;
background-size: 20px 20px;
background-image: linear-gradient(45deg, #ccc 25%, transparent 25.1%, transparent 75%, #ccc 75.1%, #ccc 100%), linear-gradient(45deg, #ccc 25%, white 25.1%, white 75%, #ccc 75.1%, #ccc 100%);
float: left;
}
.p75 {
margin:0 1em 1em;
height: 200px;
width:100%;
background-size: 19px 19px;
<div class="w">
<div class="r">0</div>
<div id="p75"></div>
</div>
<p>or decrease background-size of 1px</p>
<div class="p75"></div>
Another solution is to set the whole pattern from triangles and pretune values via css custom properties :
div {
--bgsize: 40;
--sq1: 0 0;
--sq2: calc(var(--bgsize) / 2 * 1px) calc(var(--bgsize) / 2 * 1px);
--sq3: var(--sq2);
--sq4: calc(var(--bgsize) * 1px ) 0px;
}
#a20:checked ~ div { --bgsize: 20; }
#a50:checked ~ div { --bgsize: 50; }
#a150:checked~ div { --bgsize: 150;}
#a100:checked~ div { --bgsize: 100;}
div {
height:200px;
background:
linear-gradient(45deg, gray 25% , transparent 26%),
linear-gradient(225deg, gray 25% , transparent 26%),
linear-gradient(45deg, gray 25% , transparent 26%),
linear-gradient(225deg, gray 25% , transparent 26%)
;
background-position:
var(--sq1) ,
var(--sq2) ,
var(--sq3) ,
var(--sq4);
background-size: calc(var(--bgsize) * 1px) calc(var(--bgsize) * 1px );
}
reset bg-size:<br>
<label for=a20>20px</label><input type=radio name=test id=a20>
<label for=a100>100px</label><input type=radio name=test id=a100>
<label for=a150>150px</label><input type=radio name=test id=a150>
<div></div>
demo with option to reset --bgsize and color
https://codepen.io/gc-nomade/pen/GRJGXwv

Using "display:block" but can't keep my image on the same horizontal plane as the text

I would like to keep a CSS3 arrow on the same horizontal plane as some text. In other words, I would like all this to stay on the same horizontal plane ...
<div style="display:block">
<div id="downArrow" class="downArrow arrow"></div>
- 1.5780377548310014 / -0.01013426671732404 %
</div>
I thought "display:block" would do the trick but apparently not -- https://jsfiddle.net/6m7vegwc/ . Only problem is the CSS for the arrow requires an "after"
.downArrow:after {
background: linear-gradient(120deg, transparent 63%, #fff 63%),
linear-gradient(-120deg, transparent 63%, #fff 63%),
linear-gradient(to top, #ccc, #000);
}
and I think this is throwing things off. Anyway, how can I keep my arrow on the same horizontal plane as the text?
The simplest fix would be to make them all display inline-block.
#oneDayChange > div {
display: inline-block;
vertical-align: middle;
}
.arrow {
display: inline-block;
vertical-align: middle;
}
.arrow:after {
height: 50px;
width: 50px;
display: inline-block;
content: '';
}
.upArrow:after {
background: linear-gradient(60deg, transparent 63%, #fff 63%), linear-gradient(-60deg, transparent 63%, #fff 63%), linear-gradient(to bottom, #ccc, #000);
}
.downArrow:after {
background: linear-gradient(120deg, transparent 63%, #fff 63%), linear-gradient(-120deg, transparent 63%, #fff 63%), linear-gradient(to top, #ccc, #000);
}
<div id="oneDayChange">
One day change
<div>
<div id="downArrow" class="downArrow arrow"></div>
- 1.5780377548310014 / -0.01013426671732404 %
</div>
</div>
I believe you are looking for display:inline alternatively use a instead of a as inline is its normal state.
Here is a guide that explains it in full https://www.w3schools.com/css/css_display_visibility.asp
What you are looking for is display: inline but you could simplify your example by just swapping the <div>s against <span>s because <span> tags are by default display: inline
If you want to have everything more steady and centered, you can also use display: flex which takes it's children and spreads them horizontally and stretches them vertically by default.
#oneDayChange {
display: flex;
justify-content: flex-start; /* align to the left */
align-items: center; /* center content vertically */
}
.arrow:after {
height:50px;
width:50px;
display: inline-block;
content:'';
}
.upArrow:after {
background: linear-gradient(60deg, transparent 63%, #fff 63%),
linear-gradient(-60deg, transparent 63%, #fff 63%),
linear-gradient(to bottom, #ccc, #000);
}
.downArrow:after {
background: linear-gradient(120deg, transparent 63%, #fff 63%),
linear-gradient(-120deg, transparent 63%, #fff 63%),
linear-gradient(to top, #ccc, #000);
}
<div id="oneDayChange">
One day change
<span id="downArrow" class="downArrow arrow"></span>
- 1.5780377548310014 / -0.01013426671732404 %
</div>
This can be done with display: flex
<div id="oneDayChange">
...
<div style="display:flex; flex-direction: row;">
...
</div>
Read more about flexbox (one of the better css innovations in recent years) here