html {
background:#ffffff;
}
body {
height:250px;
background: linear-gradient(
to bottom,
#ffffff 0px,
#ffffff 100px,
#0065A2 100px,
#0065A2 145px,
#074A8B 145px,
#074A8B 163px,
#0065A2 163px,
#0065A2 203px,
transparent 203px
);
}
I am trying to use a background linear gradient and with great surprise it works good on Firefox and IE but not on Google Chrome.
The code is here for example: https://jsfiddle.net/be1rgpez/1/
background: linear-gradient(
to bottom,
#ffffff 0px,
#ffffff 100px,
#0065A2 100px,
#0065A2 145px,
#074A8B 145px,
#074A8B 163px,
#0065A2 163px,
#0065A2 203px,
transparent 203px
);
I need a linear gradient with several color stops, but using Google Chrome it renders a strange shadow between colors (see image left box). The effect I need is "striped" without shadows).
In the attachment I show what I see using Chrome. The left box is what I need but without the shadows (like in the right box). The same jsfiddle renders correctly on Firefox and IE.
UPDATE: this is a zoomed picture. As you can see, the left box has a small shadow between the white and the blue color (and also between other colors).
try this code:
.left {
background: linear-gradient( to bottom, #ffffff 0px, #ffffff 100px, #0065A2 100px);
background: -webkit-linear-gradient( to bottom, #ffffff 0px, #ffffff 100px, #0065A2 100px);
}
.right {
background: linear-gradient( to bottom, #ffffff 0px, #ffffff 100px, #0065A2 100px);
background: -webkit-linear-gradient( to bottom, #ffffff 0px, #ffffff 100px, #0065A2 100px);
}
I found that there's an issue between linear gradient and containers overflow.
I tried many solutions and it didn't work.
Then when i tried to give overflow:auto, it worked for me.
this is before i apply the fix to the right container which holds many content
this is after applying the overflow: auto !important; to the right container
and it works fine now without any issue and here it is.
You have defined the same starting points two times for different colors. The below code without the duplicates looks fine:
.left {
background: linear-gradient(
to bottom,
#ffffff 0px,
#0065A2 100px,
#074A8B 145px,
#0065A2 163px,
transparent 203px
);
}
Related
I'm looking to create a gradient background for my content area. The gradient would simply be solid white, fading in from zero opacity at the top and again fading back to zero opacity at the bottom. As the content height is highly variable, relative color-stop locations don't fare well.
At the moment I have this CSS:
background: linear-gradient(
to bottom,
rgba(255,255,255,0) 0%,
rgba(255,255,255,1) 500px,
rgba(255,255,255,1) 90%,
rgba(255,255,255,0) 100%
);
I'm looking to replace the 90% with something that would equal (content height) - 500px. Is this possible and how is it done?
Thanks!
Simply use calc:
body {
min-height:1500px;
margin:0;
background: linear-gradient(
to bottom,
rgba(255,255,255,0) 0%,
rgba(255,255,255,1) 500px,
rgba(255,255,255,1) calc(100% - 500px),
rgba(255,255,255,0) 100%
);
}
html {
background:pink;
}
Or consider multiple background where you can adjust background-size/background-position
body {
min-height: 1500px;
margin: 0;
background:
/* Top part will take 500px*/
linear-gradient(to bottom, transparent, #fff) top/100% 500px,
/*Bottom part will take 500px*/
linear-gradient(to top, transparent, #fff) bottom/100% 500px,
/*Middle part will take (100% - 2*500px) */
linear-gradient(#fff,#fff) center/100% calc(100% - 1000px);
background-repeat:no-repeat;
}
html {
background: pink;
}
IE and Edge do not seem to be able to calculate the height correctly in this gradient. Does anyone have a solution?
background: linear-gradient(180deg, rgba(255,255,255,0) 100px, #f5f5f5 100px, #f5f5f5 calc(100% - 100px), rgba(255,255,255,0) calc(100% - 100px));
In this case, as you are using a transparent "stripe", you can cheat by using two linear gradients both only going 50% of the height.
You start one from the top and the second from the bottom
div {
height: 100vh;
background:
linear-gradient(180deg, transparent 100px, #f5f5f5 100px, #f5f5f5 50%, transparent 50%),
linear-gradient(0deg, transparent 100px, #f5f5f5 100px, #f5f5f5 50%, transparent 50%);
}
body {
margin: 0;
padding: 0;
background: pink; /* for demo purposes */
}
<div></div>
Codepen Demo
Is it possible or is there a trick to make a background pixelated like the one in the image attached?
I use a background image, but as you can see it doesn't scale and it flashs on page scrolling.
Now I have CSS thanks to vlcekmi3:
background-color: white;
background-image: linear-gradient(45deg, black 25%, transparent 25%, transparent 75%, black 75%, black),
linear-gradient(45deg, black 25%, transparent 25%, transparent 75%, black 75%, black);
background-size:100px 100px;
background-position: 0 0, 50px 50px;
But I'm unable to make it exactly like the image. Can someone check it?
Any code, resource, tutorial, and suggestion is appreciated.
From thirtydot's comment in the first post. Should have posted it as an answer - Brilliant. I almost missed it. Please rate his comment up :) I am only posting this as an answer so it might help others as it helped me.
Using a base64 encoded message:
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAABZJREFUeNpi2r9//38gYGAEESAAEGAAasgJOgzOKCoAAAAASUVORK5CYII=);
http://jsfiddle.net/thirtydot/v7T98/3/
Here's the best I could come up with to match your image. It's adapted from the example here by Lea Verou What will be your fallback for non css3 browsers?
body {
background-image: -moz-linear-gradient(45deg, #666 25%, transparent 25%),
-moz-linear-gradient(-45deg, #666 25%, transparent 25%),
-moz-linear-gradient(45deg, transparent 75%, #666 75%),
-moz-linear-gradient(-45deg, transparent 75%, #666 75%);
background-image: -webkit-gradient(linear, 0 100%, 100% 0, color-stop(.25, #666), color-stop(.25, transparent)),
-webkit-gradient(linear, 0 0, 100% 100%, color-stop(.25, #666), color-stop(.25, transparent)),
-webkit-gradient(linear, 0 100%, 100% 0, color-stop(.75, transparent), color-stop(.75, #666)),
-webkit-gradient(linear, 0 0, 100% 100%, color-stop(.75, transparent), color-stop(.75, #666));
background-image: -webkit-linear-gradient(45deg, #666 25%, transparent 25%),
-webkit-linear-gradient(-45deg, #666 25%, transparent 25%),
-webkit-linear-gradient(45deg, transparent 75%, #666 75%),
-webkit-linear-gradient(-45deg, transparent 75%, #666 75%);
background-image: -o-linear-gradient(45deg, #666 25%, transparent 25%),
-o-linear-gradient(-45deg, #666 25%, transparent 25%),
-o-linear-gradient(45deg, transparent 75%, #666 75%),
-o-linear-gradient(-45deg, transparent 75%, #666 75%);
background-image: linear-gradient(45deg, #666 25%, transparent 25%),
linear-gradient(-45deg, #666 25%, transparent 25%),
linear-gradient(45deg, transparent 75%, #666 75%),
linear-gradient(-45deg, transparent 75%, #666 75%);
-moz-background-size: 2px 2px;
background-size: 2px 2px;
-webkit-background-size: 2px 2.1px; /* override value for webkit */
background-position: 0 0, 1px 0, 1px -1px, 0px 1px;
}
jsfiddle example
The "flickering" you observe is is not a software issue, but a hardware one. Basically, it's caused by that fact that the pixels on your screen can't change color instantly. Since your dotted background consists of alternating rows of pixels, any time you scroll down by an odd number of pixels, there will be a brief moment when your screen is switching between two shifted copies of the pattern, and this will appear as flicker.
This thread on Graphic Design Stack Exchange features an even more dramatic example of the same effect, and also explains why it happens in more detail. Just for a quick demonstration, let me borrow one of the images from Volker Siegel's answer:
Note how, on most screens, this image will show a noticeable "pulsing" effect when scrolled. (It may also appear to flicker a bit even while just looking at it, simply because the photoreceptors in your eyes also have some response delay and adaptation effects.)
Anyway, the only way you can stop your dotted background from flickering while scrolling is to make it not scroll. Fortunately, there's a CSS property just for that:
background-attachment: fixed;
Other than that, there's not much else to it. The best way to actually render the background is almost certainly with a simple two-color PNG image. You can even make the image semitransparent, so that you can layer it on top of different colored backgrounds. See the snippet below for a demonstration:
body {
background-color: white;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGUlEQVQ4y2NgoBJwoJAedcGoC0ZdMOAuAABF0hABJ/8lyQAAAABJRU5ErkJggg==);
background-attachment: fixed;
}
<p>blah</p><p>blah</p><p>blah</p><p>blah</p><p>blah</p><p>blah</p>
<p>blah</p><p>blah</p><p>blah</p><p>blah</p><p>blah</p><p>blah</p>
<p>blah</p><p>blah</p><p>blah</p><p>blah</p><p>blah</p><p>blah</p>
<p>blah</p><p>blah</p><p>blah</p><p>blah</p><p>blah</p><p>blah</p>
Note how the pattern does not flicker when you scroll it with the inner scroll bar. (It does flicker when you scroll the whole SO page, because the pattern is attached to the <iframe> it's displayed in, and will scroll along with it.)
(BTW, the inline image I've used in the snippet above is 16 × 16 pixels, even though the actual pattern is just 2 × 2 pixels. Repeating it a few times doesn't cost much in terms of file size, though, and might be slightly safer, as I seem to recall some older browsers having issues with very small background images.)
How about this one?
.card {
background: linear-gradient(90deg, #fff 2px, transparent 1%) center, linear-gradient(#fff 2px, transparent 1%) center, #ccc;
background-size: 5px 5px;
height: 10em;
width: 30em;
position: relative;
}
.text {
font-size: 2em;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
<div class="card">
<div class="text">
Hello world!
</div>
</div>
In general the formula is
// color
$bg-color: #fff;
$dot-color: $gray-darker;
// Dimensions
$dot-size: 3px;
$dot-space: 5px;
background: linear-gradient(90deg, $bg-color ($dot-space - $dot-size), transparent 1%) center,
linear-gradient($bg-color ($dot-space - $dot-size), transparent 1%) center, $dot-color;
background-size: $dot-space $dot-space;
as seen # https://codepen.io/edmundojr/pen/xOYJGw
This is because of background-size, so just try this:
background-size:2px 2px;
Without all the browser prefixes:
background: linear-gradient(
45deg,
#fff,
#fff 50%,
#000 50%,
#000
);
background-size: 2px 2px;
I have a div which is a wrapper of my half website and on the left side there's a category list. The wrapper itself is in grey color.
What I want is that it would switch from grey color to white. Here's an example image how I'd like it to be:
Is there a solution to this?
EDIT
If it will be of any help here's my wrapper's css:
#wrapper{
width: 980px;
margin: 0 auto;
background: #f3f3f3;
}
If I understand you correctly, you're looking for a way to add a gradient. Below you find the CSS for a gradient going from left to right with the colors #FFFFFF to #F3F3F3.
Please be aware, that gradients haven't been standardized yet, and many browsers have their own implementiation. This is why there are multiple directives (prefixed -o- for Opera, -moz- for Mozilla, etc.):
#wrapper {
...
background-image:
linear-gradient(left , rgb(255,255,255) 35%, rgb(243,243,243) 84%);
background-image:
-o-linear-gradient(left , rgb(255,255,255) 35%, rgb(243,243,243) 84%);
background-image:
-moz-linear-gradient(left , rgb(255,255,255) 35%, rgb(243,243,243) 84%);
background-image:
-webkit-linear-gradient(left , rgb(255,255,255) 35%, rgb(243,243,243) 84%);
background-image:
-ms-linear-gradient(left , rgb(255,255,255) 35%, rgb(243,243,243) 84%);
background-image: -webkit-gradient(
linear,
left top,
right top,
color-stop(0.35, rgb(255,255,255)),
color-stop(0.84, rgb(243,243,243))
);
}
Here's a convenient CSS Gradient Generator
What you need are gradients.
Try this generator or just read about them
I'm trying to make a gradient background for my website, http://www.lathamcity.com
The problem is, as you can see, it just repeats the blue and cyan a bunch of times instead of making a gradient out of them.
To add to the mystery, when two links are clicked on to open a third div, the gradient suddenly changes. The third div extends below the second one, and the distance between them is occupied by the first gradient color and the rest up to the top of the page is just a normal gradient.
Here's the code I'm using for the gradients.
body{
background-color: #1B0D70;
background-image: linear-gradient(bottom, rgb(214,231,232) 49%, rgb(36,155,171) 75%);
background-image: -o-linear-gradient(bottom, rgb(214,231,232) 49%, rgb(36,155,171) 75%);
background-image: -moz-linear-gradient(bottom, rgb(214,231,232) 49%, rgb(36,155,171) 75%);
background-image: -webkit-linear-gradient(bottom, rgb(214,231,232) 49%, rgb(36,155,171) 75%);
background-image: -ms-linear-gradient(bottom, rgb(214,231,232) 49%, rgb(36,155,171) 75%);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.49, rgb(214,231,232)),
color-stop(0.75, rgb(36,155,171))
);
}
Currently your body height is 0px because your most of the element are absolute position.
Write this in your css:
html, body{
height:100%;
}