CSS Stripes, repeating-linear-gradient bug - css

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

Related

Hot to make gradient half red / half blue?

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>

Infinite chevron line

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>

How do make a shape with 4 beveled edges

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>

Border-image gradient pattern in triangle shape

I want to create an odd shaped triangle with css. My first thought was to use transparent borders with transform: rotate and it worked (see left triangle). Now I want to use a gradient border image pattern as background for a same triangle but I can't make it work. I tried many things like changing border-width, using wrappers and overflow:hidden among others, nothing worked. Here I post one of my tries (see right shape) as you see the pattern takes all the space, not following the triangle shape. Any ideas?
#top-left {
position:absolute;
left:78px;
width: 0;
height: 0;
border-top: 100px solid transparent;
border-right: 80px solid black;
border-bottom: 50px solid transparent;
-webkit-transform: rotate(-20deg);
}
#top-right {
position:absolute;
left:300px;
width: 0;
height: 0;
border-image: repeating-linear-gradient( 0deg, pink, pink 1%, purple 1%, purple 8%) 10;
border-image-width: 100px 80px 50px 0px;
border-width: 100px 80px 50px 0px;
border-style: solid;
-webkit-transform: rotate(-20deg);
}
<div id="wrapper">
<div id="top-left"></div>
<div id="top-right"></div>
</div>
Edit: Andrey Fedorov's answer is good, but there is a problem when the background is not a solid color, like this for example:
body{
background-color: #6d695c;
background-image:
repeating-linear-gradient(120deg, rgba(255,255,255,.1), rgba(255,255,255,.1) 1px, transparent 1px, transparent 60px),
repeating-linear-gradient(60deg, rgba(255,255,255,.1), rgba(255,255,255,.1) 1px, transparent 1px, transparent 60px),
linear-gradient(60deg, rgba(0,0,0,.1) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.1) 75%, rgba(0,0,0,.1)),
linear-gradient(120deg, rgba(0,0,0,.1) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.1) 75%, rgba(0,0,0,.1));
background-size: 70px 120px;
}
#wrapper {
position: relative;
}
#top-left {
position:absolute;
left:0px;
width: 0;
height: 0;
border-top: 100px solid #fff;
border-right: 80px solid transparent;
border-bottom: 50px solid #fff;
-webkit-transform: rotate(-20deg);
}
#top-right {
position:absolute;
z-index: -10;
left:0;
width: 0;
height: 0;
border-image: repeating-linear-gradient( 0deg, pink, pink 1%, purple 1%, purple 8%) 10;
border-image-width: 100px 80px 50px 0px;
border-width: 100px 80px 50px 0px;
border-style: solid;
-webkit-transform: rotate(-20deg);
}
<div id="wrapper">
<div id="top-left"></div>
<div id="top-right"></div>
</div>
You still can use linear-gradient with no-repeat and background-size to draw each pieces :
examples by steps from a single tag :
/* testing gradients */
p , div#wrapper {
width:80px;
float:left;
margin:1em;
height:150px;
/* see me then remove this shadow */
box-shadow:0 0 0 2px;
}
p {
background:
linear-gradient(130deg, transparent 49.75%, pink 50.5%) 0 42px no-repeat ;
background-size:
100% 15px;
transform: rotate(-20deg);
}
p + p{
background:
linear-gradient(130deg, transparent 49.75%, pink 50.5%) 0 42px no-repeat ,
linear-gradient(130deg,transparent 62px, purple 63px) top no-repeat;
background-size:
100% 15px,
100% 65%;
}
p + p + p {
background:
linear-gradient(130deg, transparent 49.75%, pink 50.5%) 0 42px no-repeat ,
linear-gradient(130deg,transparent 62px, purple 63px) top no-repeat,
linear-gradient(33deg , transparent 42px, pink 43px) no-repeat bottom;
background-size:
100% 15px,
100% 65%,
100% 8px;
}
p+ p + p + p {
background:
linear-gradient(130deg, transparent 49.75%, pink 50.5%) 0 42px no-repeat ,
linear-gradient(130deg,transparent 62px, purple 63px) top no-repeat,
linear-gradient(33deg , transparent 42px, pink 43px) no-repeat bottom,
linear-gradient(33deg, transparent 42px, purple 43px) bottom no-repeat;
background-size:
100% 15px,
100% 65%,
100% 8px,
100% 35.5%;
}
p:last-of-type{
box-shadow:0 0
}
/* your original CSS/issue */
body{
background-color: #6d695c;
background-image:
repeating-linear-gradient(120deg, rgba(255,255,255,.1), rgba(255,255,255,.1) 1px, transparent 1px, transparent 60px),
repeating-linear-gradient(60deg, rgba(255,255,255,.1), rgba(255,255,255,.1) 1px, transparent 1px, transparent 60px),
linear-gradient(60deg, rgba(0,0,0,.1) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.1) 75%, rgba(0,0,0,.1)),
linear-gradient(120deg, rgba(0,0,0,.1) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.1) 75%, rgba(0,0,0,.1));
background-size: 70px 120px;
}
#wrapper {
position: relative;
}
#top-left {
position:absolute;
left:0px;
width: 0;
height: 0;
border-top: 100px solid #fff;
border-right: 80px solid transparent;
border-bottom: 50px solid #fff;
-webkit-transform: rotate(-20deg);
transform: rotate(-20deg);
}
#top-right {
position:absolute;
z-index: -10;
left:0;
width: 0;
height: 0;
border-image: repeating-linear-gradient( 0deg, pink, pink 1%, purple 1%, purple 8%) 10;
border-image-width: 100px 80px 50px 0px;
border-width: 100px 80px 50px 0px;
border-style: solid;
-webkit-transform: rotate(-20deg);
transform: rotate(-20deg);
}
<!-- your issue -->
<div id="wrapper">
<div id="top-left"></div>
<div id="top-right"></div>
</div>
<!-- p for testing purpose -->
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
inbricated element + gradient & transform could do too:
body{
background-color: #6d695c;
background-image:
repeating-linear-gradient(120deg, rgba(255,255,255,.1), rgba(255,255,255,.1) 1px, transparent 1px, transparent 60px),
repeating-linear-gradient(60deg, rgba(255,255,255,.1), rgba(255,255,255,.1) 1px, transparent 1px, transparent 60px),
linear-gradient(60deg, rgba(0,0,0,.1) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.1) 75%, rgba(0,0,0,.1)),
linear-gradient(120deg, rgba(0,0,0,.1) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.1) 75%, rgba(0,0,0,.1));
background-size: 70px 120px;
}
div.inbricate {
margin:1em;
height:150px;
width:80px;
position:relative;
overflow:hidden;
transform:rotate(-20deg);
box-shadow: 0 0 ;
}
.inbricate div {
transform:rotate(31deg) scale(1.2, 0.9) skew(-5deg);
transform-origin: 100% 102%;
height:100%;
background:linear-gradient(-40deg, pink 8%, purple 8%, purple 65%, pink 65%, pink 75%, purple 75% )
}
<div class=inbricate>
<div>
</div>
</div>
One possible solution is this:
Put both shapes in the same place.
Using z-index make the one with the pattern go behind the other
Use white (or whatever color is the shape background) to paint the border area outside the triangle.
Make transparent the border that had the triangle color
#wrapper {
position: relative;
}
#top-left {
position:absolute;
left:0px;
width: 0;
height: 0;
border-top: 100px solid #fff;
border-right: 80px solid transparent;
border-bottom: 50px solid #fff;
-webkit-transform: rotate(-20deg);
}
#top-right {
position:absolute;
z-index: -10;
left:0;
width: 0;
height: 0;
border-image: repeating-linear-gradient( 0deg, pink, pink 1%, purple 1%, purple 8%) 10;
border-image-width: 100px 80px 50px 0px;
border-width: 100px 80px 50px 0px;
border-style: solid;
-webkit-transform: rotate(-20deg);
}
<div id="wrapper">
<div id="top-left"></div>
<div id="top-right"></div>
</div>

Using css3 for background of website

I want to get exactly this result with CSS3 and HTML5 texhnologies using no images.
here is HTML
<div id="overlay"></div>
<div id="lines"></div>
and CSS
body {
background: #45484d;
z-index:-5;
}
#lines {
background-size: 20px 20px;
background-image: -webkit-repeating-linear-gradient(0deg, #fff, #fff 2px, transparent 2px, transparent 7px),-webkit-repeating-linear-gradient(-90deg, #fff, #fff 2px, transparent 2px, transparent 7px);
background-image: -moz-repeating-linear-gradient(0deg, #fff, #fff 2px, transparent 2px, transparent 7px),-moz-repeating-linear-gradient(-90deg, #fff, #fff 2px, transparent 2px, transparent 7px);
background-image: -o-repeating-linear-gradient(0deg, #fff, #fff 2px, transparent 2px, transparent 7px),-o-repeating-linear-gradient(-90deg, #fff, #fff 2px, transparent 2px, transparent 7px);
background-image:repeating-linear-gradient(0deg, #fff, #fff 2px, transparent 2px, transparent 7px),repeating-linear-gradient(-90deg, #fff, #fff 2px, transparent 2px, transparent 7px);
height:100%;
width:100%;
opacity:0.14;
position:absolute;
top:0;
left:0;
z-index:-4;
}
#overlay {
position:absolute;
top:0;
left:0;
height:100%;
width:100%;
z-index:-3;
}
I kinda get some piece of reuslt on jsfiddle:
http://jsfiddle.net/tt13/BA8Wk/2/
But can't figure out what to do else. Can anyone help me to achieve this result?
http://i.stack.imgur.com/6BrlY.jpg
dabblet: http://dabblet.com/gist/4649123
jsfiddle: http://jsfiddle.net/W4LpR/6/ (try opening the results in a larger window)
HTML
<div id="overlay"></div>
<div id="lines"></div>
<div id="lines2"></div>
CSS
body {
background-image: -ms-radial-gradient(center, circle closest-corner, #636363 0%, #27282B 100%);
background-image: -moz-radial-gradient(center, circle closest-corner, #636363 0%, #27282B 100%);
background-image: -o-radial-gradient(center, circle closest-corner, #636363 0%, #27282B 100%);
background-image: -webkit-gradient(radial, center center, 0, center center, 447, color-stop(0, #636363), color-stop(1, #27282B));
background-image: -webkit-radial-gradient(center, circle closest-corner, #636363 0%, #27282B 100%);
background-image: radial-gradient(circle closest-corner at center, #636363 0%, #27282B 100%);
z-index:-5;
}
#lines {
background-size: 20px 20px;
background-image: -webkit-repeating-linear-gradient(0deg, #fff, #fff 1px, transparent 2px, transparent 20px),-webkit-repeating-linear-gradient(-90deg, #fff, #fff 1px, transparent 2px, transparent 20px);
background-image: -moz-repeating-linear-gradient(0deg, #fff, #fff 1px, transparent 2px, transparent 20px),-moz-repeating-linear-gradient(-90deg, #fff, #fff 1px, transparent 2px, transparent 20px);
background-image: -o-repeating-linear-gradient(0deg, #fff, #fff 1px, transparent 2px, transparent 20px),-o-repeating-linear-gradient(-90deg, #fff, #fff 1px, transparent 2px, transparent 20px);
background-image:repeating-linear-gradient(0deg, #fff, #fff 1px, transparent 2px, transparent 20px),repeating-linear-gradient(-90deg, #fff, #fff 1px, transparent 2px, transparent 20px);
height:100%;
width:100%;
opacity:0.14;
position:absolute;
top:0;
left:0;
z-index:-4;
}
#lines2 {
background-size: 100px 100px;
background-image: -webkit-repeating-linear-gradient(0deg, #fff, #fff 2px, transparent 2px, transparent 100px),-webkit-repeating-linear-gradient(-90deg, #fff, #fff 2px, transparent 2px, transparent 100px);
background-image: -moz-repeating-linear-gradient(0deg, #fff, #fff 2px, transparent 2px, transparent 100px),-moz-repeating-linear-gradient(-90deg, #fff, #fff 2px, transparent 2px, transparent 100px);
background-image: -o-repeating-linear-gradient(0deg, #fff, #fff 2px, transparent 2px, transparent 100px),-o-repeating-linear-gradient(-90deg, #fff, #fff 2px, transparent 2px, transparent 100px);
background-image:repeating-linear-gradient(0deg, #fff, #fff 2px, transparent 2px, transparent 100px),repeating-linear-gradient(-90deg, #fff, #fff 2px, transparent 2px, transparent 100px);
height:100%;
width:100%;
opacity:0.14;
position:absolute;
top:0;
left:0;
z-index:-3;
}
#overlay {
position:absolute;
top:0;
left:0;
height:100%;
width:100%;
z-index:-2;
}
My try on this (only -webkit rules (Chrome) for demo):
background-size: 100px 100px;
background-image:
repeating-linear-gradient(0deg, #999, transparent 2px, transparent 20px),
repeating-linear-gradient(0deg, #fff 1px, transparent 2px, transparent 100px),
repeating-linear-gradient(90deg, #999, transparent 2px, transparent 20px),
repeating-linear-gradient(90deg, #fff 1px, transparent 2px, transparent 100px);
(fiddle)
And here's one with added stripes:
background-size:4px 4px;
background-image:
repeating-linear-gradient(45deg, transparent, transparent 1px, #333 2px, transparent 3px);

Resources