How to apply CSS to half of a point feature? - css

Due to I can not use server-side StyledLayerDescriptor (SLD) coding, neither I want to load external graphics I would like to use CSS to style my OpenLayers' point features.
In detail I would like to fill half (or 1/3) of a point feature with different colors.
A CSS code might be
#OpenLayers\.Geometry\.Point_111{
fill: red !important;
background: -moz-linear-gradient(-45deg, #ce275f 50%, #1e5799 50%, #207cca 50%, #7db9e8 100%) !important; /* FF3.6+ */
}
The feature is not assigned to a class.
Is that possible? Are there any other possibilities?

I immediately thought of this:
.circle {
height: 100px;
width: 100px;
border-radius: 50%;
background: #000000; /* Old browsers */
background: -moz-linear-gradient(left, #000000 1%, #000000 50%, #ff00ff 50%, #ff00ff 100%, #ff00ff 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(1%,#000000), color-stop(50%,#000000), color-stop(50%,#ff00ff), color-stop(100%,#ff00ff), color-stop(100%,#ff00ff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #000000 1%,#000000 50%,#ff00ff 50%,#ff00ff 100%,#ff00ff 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, #000000 1%,#000000 50%,#ff00ff 50%,#ff00ff 100%,#ff00ff 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, #000000 1%,#000000 50%,#ff00ff 50%,#ff00ff 100%,#ff00ff 100%); /* IE10+ */
background: linear-gradient(to right, #000000 1%,#000000 50%,#ff00ff 50%,#ff00ff 100%,#ff00ff 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000', endColorstr='#ff00ff',GradientType=1 ); /* IE6-9 */
}
JSfiddle
Gradient generated with Ultimate CSS Gradient Generator

Related

Is it possible to combine a low opacity gradient and background color

Here's what I'm trying to do: http://jsfiddle.net/wLyqvrn1/1/
table {
height: 200px;
width: 200px;
background-color: #444557; /* this doesn't show below the gradient */
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#000000+0,ffffff+100&0.1+0,0.1+100 */
background: -moz-linear-gradient(top, rgba(0,0,0,0.1) 0%, rgba(255,255,255,0.1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.1)), color-stop(100%,rgba(255,255,255,0.1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(0,0,0,0.1) 0%,rgba(255,255,255,0.1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(0,0,0,0.1) 0%,rgba(255,255,255,0.1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(0,0,0,0.1) 0%,rgba(255,255,255,0.1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(0,0,0,0.1) 0%,rgba(255,255,255,0.1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1a000000', endColorstr='#1affffff',GradientType=0 ); /* IE6-9 */
}
Even though there is an answer to and older question about this, maybe it is better to add some more thorough explanation.
background-color is one of the properties inside background
When you set
background: linear-gradient(...);
even thought it looks like you are not changing background-color, you are doing so !
background expands to all of its properties, and then resets them (also because it is defined later than background-color)

Weird horizontal line with gradient in retina Safari

I have this strange horizontal line across the my gradient div. It is only showing in Safari and only on retina displays and I can't figure out why. Has anyone else had this problem?
HTML:
<div class="img-gradient2"></div>
CSS:
.img-gradient2 {
position: absolute;
width: 100%;
height: 100%;
background: -moz-linear-gradient(top, rgba(0,0,0,0) 26%, rgba(0,0,0,0.01) 27%, rgba(0,0,0,0.5) 68%, rgba(0,0,0,0.6) 100%); /* FF3.6+ */
background: -webkit-linear-gradient(top, rgba(0,0,0,0) 26%,rgba(0,0,0,0.01) 27%,rgba(0,0,0,0.5) 68%,rgba(0,0,0,0.6) 100%); /* Chrome,Safari4+ */
background: -o-linear-gradient(top, rgba(0,0,0,0) 26%,rgba(0,0,0,0.01) 27%,rgba(0,0,0,0.5) 68%,rgba(0,0,0,0.6) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(0,0,0,0) 26%,rgba(0,0,0,0.01) 27%,rgba(0,0,0,0.5) 68%,rgba(0,0,0,0.6) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(0,0,0,0) 26%,rgba(0,0,0,0.01) 27%,rgba(0,0,0,0.5) 68%,rgba(0,0,0,0.6) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00000000', endColorstr='#99000000',GradientType=0 ); /* IE6-9 */
}
I've run into the same bug. It appears to be triggered by a gradient background in Webkit on a retina display. I've reproduced it on a MBP and an iPad.
After a little testing, I've figured out a work around. Since the Webkit rendering engine appears to be painting a one pixel line of non-transparent background along the edge of the gradient, you can simply tell it to position the background one pixel up by tweaking the background-position-y. (For other folks reading this, if you are doing a side-to-side gradient rather than top-to-bottom, then change that to background-position-x.)
However, this will expose the underlying content by one pixel on the opposite side from the gradient, so you can change the absolute position of the gradient overlay by one.
background-position-y: -1px;
bottom: -1px;
Depending on your setup, changing the bottom (or top) might not produce the desired result depending on how the gradient interacts with the underlying content. Still, the background-position-y trick will remove the black line which might be better.
Full Code
.img-gradient2 {
position: absolute;
width: 100%;
height: 100%;
/** Workaround fix for Webkit black-line on retina displays **/
background-position-y: -1px;
bottom: -1px;
/**/
background: -moz-linear-gradient(top, rgba(0,0,0,0) 26%, rgba(0,0,0,0.01) 27%, rgba(0,0,0,0.5) 68%, rgba(0,0,0,0.6) 100%); /* FF3.6+ */
background: -webkit-linear-gradient(top, rgba(0,0,0,0) 26%,rgba(0,0,0,0.01) 27%,rgba(0,0,0,0.5) 68%,rgba(0,0,0,0.6) 100%); /* Chrome,Safari4+ */
background: -o-linear-gradient(top, rgba(0,0,0,0) 26%,rgba(0,0,0,0.01) 27%,rgba(0,0,0,0.5) 68%,rgba(0,0,0,0.6) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(0,0,0,0) 26%,rgba(0,0,0,0.01) 27%,rgba(0,0,0,0.5) 68%,rgba(0,0,0,0.6) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(0,0,0,0) 26%,rgba(0,0,0,0.01) 27%,rgba(0,0,0,0.5) 68%,rgba(0,0,0,0.6) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00000000', endColorstr='#99000000',GradientType=0 ); /* IE6-9 */
}

css multiple gradients with colour stops

I have created a simple css bar with colour stops using the following:
#testing{
width:100%;
height:40px;
background-image: -webkit-linear-gradient(left, #034a96 80%, #eab92d 50%);
background-image: -moz-linear-gradient(top, #034a96 50%, #eab92d 51%);
background-image: -ms-linear-gradient(top, #034a96 50%, #eab92d 51%);
background-image: -o-linear-gradient(top, #034a96 50%, #eab92d 51%);
background-image: linear-gradient(top, #034a96 50%, #eab92d 51%);
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
}
What I would like to do is have the first 80% of the bar is have a gradient that goes from the top with colour #034a96 to #0663c7 and then just that gradient colouring 50% of the bar. Then with the other 51% I have another gradient from the top with #eab92d to #c79810. What I'm asking is if it is possible to have multiple gradients with in each other eg:
background-image: -webkit-linear-gradient(left, top #034a96 to #0663c7 50%, top #eab92d to #c79810 51%);
Or something along those lines. I hope I'm being clear with everything. Thanks in advance
Yes, you can.
One simple example (not exactly your colourset, but it shows the plan):
background: #b8e1fc; /* Old browsers */
background: -moz-linear-gradient(top, #b8e1fc 0%, #a9d2f3 10%, #90bae4 25%, #90bcea 37%, #90bff0 50%, #6ba8e5 51%, #a2daf5 83%, #bdf3fd 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b8e1fc), color-stop(10%,#a9d2f3), color-stop(25%,#90bae4), color-stop(37%,#90bcea), color-stop(50%,#90bff0), color-stop(51%,#6ba8e5), color-stop(83%,#a2daf5), color-stop(100%,#bdf3fd)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #b8e1fc 0%,#a9d2f3 10%,#90bae4 25%,#90bcea 37%,#90bff0 50%,#6ba8e5 51%,#a2daf5 83%,#bdf3fd 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #b8e1fc 0%,#a9d2f3 10%,#90bae4 25%,#90bcea 37%,#90bff0 50%,#6ba8e5 51%,#a2daf5 83%,#bdf3fd 100%); /* Opera 11.10+ */
background: linear-gradient(to bottom, #b8e1fc 0%,#a9d2f3 10%,#90bae4 25%,#90bcea 37%,#90bff0 50%,#6ba8e5 51%,#a2daf5 83%,#bdf3fd 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b8e1fc', endColorstr='#bdf3fd',GradientType=0 ); /* IE6-9 */
This code doesn't create multi-step gradients in IE.
Up to IE9, these aren't possible at all (only simple gradients), but IE9 supports SVG data. It's a bit complicated to write, but you should have a look at http://www.colorzilla.com/gradient-editor. It's an online-tool for creating CSS code for gradients. It also supports SVG gradients for IE9.

<body> background img doesnt display in IE

I'm creating website and I ran into a problem with internet explorer (tested on ver. 8) where it doesn't display background image for
this is my code:
body {
background: rgb(255,255,255); /* Old browsers */
background-image: url(../images/bg.png);
background-image: url(../images/bg.png), -moz-linear-gradient(top, rgba(255,255,255,1) 0%, rgba(105,205,249,1) 100%); /* FF3.6+ */
background-image: url(../images/bg.png), -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,1)), color-stop(100%,rgba(105,205,249,1))); /* Chrome,Safari4+ */
background-image: url(../images/bg.png), -webkit-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(105,205,249,1) 100%); /* Chrome10+,Safari5.1+ */
background-image: url(../images/bg.png), -o-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(105,205,249,1) 100%); /* Opera 11.10+ */
background-image: url(../images/bg.png), -ms-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(105,205,249,1) 100%); /* IE10+ */
background-image: url(../images/bg.png), linear-gradient(to bottom, rgba(255,255,255,1) 0%,rgba(105,205,249,1) 100%); /* W3C */
background-repeat: no-repeat;
background-position: 0 0;
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
}
Any idea how to address this issue?
Check out this fiddle for the example. I don't know whether you want like this or not. But its working on IE as well. Check it. Example
body {
background: rgb(255,255,255); /* Old browsers */
background-image: url(../images/bg.png);
background-image: url(../images/bg.png), -moz-linear-gradient(top, rgba(255,255,255,1) 0%, rgba(105,205,249,1) 100%); /* FF3.6+ */
background-image: url(../images/bg.png), -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,1)), color-stop(100%,rgba(105,205,249,1))); /* Chrome,Safari4+ */
background-image: url(../images/bg.png), -webkit-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(105,205,249,1) 100%); /* Chrome10+,Safari5.1+ */
background-image: url(../images/bg.png), -o-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(105,205,249,1) 100%); /* Opera 11.10+ */
background-image: url(../images/bg.png), -ms-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(105,205,249,1) 100%); /* IE10+ */
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#FFFFFF', endColorstr='#6BCEF9')"; /* IE8 */
background-image: url(../images/bg.png), linear-gradient(to bottom, rgba(255,255,255,1) 0%,rgba(105,205,249,1) 100%); /* W3C */
background-repeat: no-repeat;
background-position: 0 0;
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
}
Here, I added the following line.
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#FFFFFF', endColorstr='#6BCEF9')"; /* IE8 */
Check it and let me know. Thanks
I found this
http://social.msdn.microsoft.com/Forums/en-ZA/iewebdevelopment/thread/4771f218-42fc-43b0-b0fd-bda98eef12ad
it talks about background images in IE8 conflicting with JS declarations. Not sure if that is the problem here. I know you shouldn't have a hasLayout issue here, but you might want to try putting a display:block; on the body. You should also make sure that the body is getting sized to the content inside of it (i.e. make sure floats are cleared etc -- although this would most likely be the culprit, only if your bgs were failing in most clients).
I like to put a border: 1px solid red; around stuff that I'm trying to position or debug something. Hope that helps some, sorry the answer isn't more complete.
also, another way to test this would be to add in IE conditional statements after css includes and then play around from there.

CSS gradients in IE9

I tried using the "ultimate CSS gradient generator" and it produced the following:
background: #657575; /* Old browsers */
background: -moz-linear-gradient(left, #657575 0%, #758585 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#657575), color-stop(100%,#758585)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #657575 0%,#758585 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, #657575 0%,#758585 100%); /* Opera11.10+ */
background: -ms-linear-gradient(left, #657575 0%,#758585 100%); /* IE10+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#657575', endColorstr='#758585',GradientType=1 ); /* IE6-9 */
background: linear-gradient(left, #657575 0%,#758585 100%); /* W3C */
But is seems that the gradient does not work at least with my version of IE9. So is there any way I can produce a simple horizontal gradient with IE9?
Does IE9 support CSS linear gradients?
background:#fff;
background-image: -moz-linear-gradient(top, #fff, #000);
background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0, #fff),color-stop(1, #000));
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#ffffff', endColorstr='#000000');/*For IE7-8-9*/
height: 1%;/*For IE7*/
Here is a site that might help you regarding CSS gradients:
http://www.htmlcenter.com/blog/cross-browser-gradient-backgrounds/
In my option, for fixed height elements I usually use a 1px image and repeat that image across the width of the element. That way you know it will look the same in all browsers.
Example:
.element{
height: 30px;
background: url(<1px image location>) repeat-x;
}
There are also websites that will create these gradient images for you. Here is one that is free to use:
http://www.ogim.4u2ges.com/gradient-image-maker.asp

Resources