Using css3 for background of website - css

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);

Related

Background linear gradient transition makes box shake

So this is kind of hard to show, but I will try my best.
Basically I am trying to create a button, or div, that has some corner borders, which then expands on hover, just like this:
HTML:
<div class="container">
<div class="other-container">
<div class="corner-box">This is </div>
</div>
</div>
CSS:
.container {
display: grid;
}
.other-container {
width: 200px;
height: 100px;
transition: all 0.1s ease-in;
display: grid;
margin: 0px auto;
}
.corner-box {
box-sizing: border-box;
background:
linear-gradient(to right, black 2px, transparent 2px) 0 0,
linear-gradient(to right, black 2px, transparent 2px) 0 100%,
linear-gradient(to left, black 2px, transparent 2px) 100% 0,
linear-gradient(to left, black 2px, transparent 2px) 100% 100%,
linear-gradient(to bottom, black 2px, transparent 2px) 0 0,
linear-gradient(to bottom, black 2px, transparent 2px) 100% 0,
linear-gradient(to top, black 2px, transparent 2px) 0 100%,
linear-gradient(to top, black 2px, transparent 2px) 100% 100%;
transition: all 0.2s ease-in-out;
background-repeat: no-repeat;
background-size: 20px 20px;
width: 100%;
height: 100%;
&:hover {
background:
linear-gradient(to right, black 2px, transparent 2px) 0 0,
linear-gradient(to right, black 2px, transparent 2px) 0 100%,
linear-gradient(to left, black 2px, transparent 2px) 100% 0,
linear-gradient(to left, black 2px, transparent 2px) 100% 100%,
linear-gradient(to bottom, black 2px, transparent 2px) 0 0,
linear-gradient(to bottom, black 2px, transparent 2px) 100% 0,
linear-gradient(to top, black 2px, transparent 2px) 0 100%,
linear-gradient(to top, black 2px, transparent 2px) 100% 100%;
background-repeat: no-repeat;
background-size: 50% 50%;
transition: all 0.2s ease-in-out;
}
}
As such, this actually seems to work when I just run this code. So no problem there. However, when I try to implement it in my project something weird happens.
Basically I am trying to put it in my own code like this (modified of course) in my own code:
<div class="content">
<div class="corner-box">This is a test</div>
<div class="second-div">
<div class="corner-box">This is a test</div>
</div>
</div>
My CSS for this looks like this:
.content {
display: grid;
grid-template-columns: 1fr;
padding: 200px;
box-sizing: border-box;
align-content: start;
position: relative;
}
.second-div {
width: 100%;
min-height: 100vh;
padding-top: 150px;
align-self: start;
}
.corner-box {
box-sizing: border-box;
background:
linear-gradient(to right, teal 2px, transparent 2px) 0 0,
linear-gradient(to right, teal 2px, transparent 2px) 0 100%,
linear-gradient(to left, teal 2px, transparent 2px) 100% 0,
linear-gradient(to left, teal 2px, transparent 2px) 100% 100%,
linear-gradient(to bottom, teal 2px, transparent 2px) 0 0,
linear-gradient(to bottom, teal 2px, transparent 2px) 100% 0,
linear-gradient(to top, teal 2px, transparent 2px) 0 100%,
linear-gradient(to top, teal 2px, transparent 2px) 100% 100%;
background-repeat: no-repeat;
background-size: 20px 20px;
width: 200px;
height: 100%;
padding: 25px;
transition: all 1.0s ease-in-out;
&:hover {
background:
linear-gradient(to right, teal 2px, transparent 2px) 0 0,
linear-gradient(to right, teal 2px, transparent 2px) 0 100%,
linear-gradient(to left, teal 2px, transparent 2px) 100% 0,
linear-gradient(to left, teal 2px, transparent 2px) 100% 100%,
linear-gradient(to bottom, teal 2px, transparent 2px) 0 0,
linear-gradient(to bottom, teal 2px, transparent 2px) 100% 0,
linear-gradient(to top, teal 2px, transparent 2px) 0 100%,
linear-gradient(to top, teal 2px, transparent 2px) 100% 100%;
background-repeat: no-repeat;
background-size: 50% 50%;
transition: all 1.0s ease-in-out;
}
}
The problem, which I just can't figure out, is that the transition of the corner-box div inside the second-div looks like this (sorry for the bad gif):
I hope it shows that the transition/animation makes the right border of the box kind of shaky/wobbly, resulting in a not so pretty effect.
However, the box outside the second-div container works as intended, i.e.:
I honestly have no idea what is happening here. I have tried to strip anything not needed, and it seems that SOMETIMES it might be a positioning issue. So places where I have the box in containers that are center-aligned it sometimes disappear. But like in this case, there really are no positioning at all. Additionally, if I remove the display: grid it also seems to disappear in this case, but in other cases (as my example in the beginning) display: grid has no effect.
So it's kind of inconclusive. And I just can't remove my display: grid, as that is the basis of my entire setup.
So yeah, does anyone might have an answer to why this is happening ?

CSS Stripes, repeating-linear-gradient bug

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

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>

More background colors without gradients?

Is there any css function like linear-gradient which renders provided colors without gradient?
Thank you very much for your help.
With gradients you achieve it. Try this:
background: -webkit-repeating-linear-gradient(-45deg, rgba(255,255,255,0), rgba(255,255,255,0) 80px, rgba(255,255,255,0.2) 80px, rgba(255,255,255,0.2) 150px);
background: -moz-repeating-linear-gradient(-45deg, rgba(255,255,255,0), rgba(255,255,255,0) 80px, rgba(255,255,255,0.2) 80px, rgba(255,255,255,0.2) 150px);
background: -o-repeating-linear-gradient(-45deg, rgba(255,255,255,0), rgba(255,255,255,0) 80px, rgba(255,255,255,0.2) 80px, rgba(255,255,255,0.2) 150px);
background: -ms-repeating-linear-gradient(-45deg, rgba(255,255,255,0), rgba(255,255,255,0) 80px, rgba(255,255,255,0.2) 80px, rgba(255,255,255,0.2) 150px);
background: repeating-linear-gradient(-45deg, rgba(255,255,255,0), rgba(255,255,255,0) 80px, rgba(255,255,255,0.2) 80px, rgba(255,255,255,0.2) 150px);
background-color: green;
box-shadow: inset 0 0 10px rgba(0,0,0,0.4);
Check this plunker
(Source : http://www.the-art-of-web.com/css/linear-gradients/)
Update as per ur comment:
Check this plunker
You can create all sorts of patterns, including stripes, arrows, zig-zags, etc.
Example for zig-zag-patterns:
background:
linear-gradient(135deg, #ECEDDC 25%, transparent 25%) -50px 0,
linear-gradient(225deg, #ECEDDC 25%, transparent 25%) -50px 0,
linear-gradient(315deg, #ECEDDC 25%, transparent 25%),
linear-gradient(45deg, #ECEDDC 25%, transparent 25%);
background-size: 100px 100px;
background-color: #EC173A;
(Source: http://lea.verou.me/css3patterns/ )

css3 gradient and sprite at the same time

Now I found this already of SO, and everyone seems to think it works great How do I combine a background-image and CSS3 gradient on the same element?
For some reason when I do it, it fails. The image works alone, and so does the gradient. What am I doing wrong?
.cSub {
background: #00f;
background-image: url("../images/header/Down_Arrow.svg") 9px 8px no-repeat, -moz-linear-gradient(-45deg, #0088b7 0%, #006da4 100%);
background-image: url("../images/header/Down_Arrow.svg") 9px 8px no-repeat, -webkit-linear-gradient(-45deg, #0088b7 0%, #006da4 100%);
background-image: url("../images/header/Down_Arrow.svg") 9px 8px no-repeat, -o-linear-gradient(-45deg, #0088b7 0%, #006da4 100%);
background-image: url("../images/header/Down_Arrow.svg") 9px 8px no-repeat, -ms-linear-gradient(-45deg, #0088b7 0%, #006da4 100%);
background-image: url("../images/header/Down_Arrow.svg") 9px 8px no-repeat, linear-gradient(135deg, #0088b7 0%, #006da4 100%);
border-top: 2px solid #0089b7;
}
You have background-image as the property but you put all the background value for it, just put background instead of background-image.
.cSub {
background: #00f;
background: url("../images/header/Down_Arrow.svg") 9px 8px no-repeat, -moz-linear-gradient(-45deg, #0088b7 0%, #006da4 100%);
background: url("../images/header/Down_Arrow.svg") 9px 8px no-repeat, -webkit-linear-gradient(-45deg, #0088b7 0%, #006da4 100%);
background: url("../images/header/Down_Arrow.svg") 9px 8px no-repeat, -o-linear-gradient(-45deg, #0088b7 0%, #006da4 100%);
background: url("../images/header/Down_Arrow.svg") 9px 8px no-repeat, -ms-linear-gradient(-45deg, #0088b7 0%, #006da4 100%);
background: url("../images/header/Down_Arrow.svg") 9px 8px no-repeat, linear-gradient(135deg, #0088b7 0%, #006da4 100%);
border-top: 2px solid #0089b7;
width:200px;
height:auto
}
you need to mentiion width and the height to get display the background.

Resources