I have a website created in MVC4.
I have an image. And I only want to show the shape (an arrow) of the image. And I don't want to show the rest of the image (the background).
<= only the white background of the arrows has to be disappeared.
How do you do that?
I tried this, but with this the whole image will disappear, in stead of a part of it:
.images_top {
width: 30px;
text-align: center;
vertical-align: top;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
opacity:0;
}
First of all I think you can use a PNG with alpha channel.
If this is not possible look at this tutorial about how to clip images by using the SVG clip-path.
http://www.html5rocks.com/en/tutorials/masking/adobe/
Even though it is possible only in recent browsers.
Use PNG Images for Transparent Background. You can use any online converter to convert your image to PNG.
Apart from the now better supported PNG (and PNG8 with better fallback-support (looking at IE) and a (configurable) transparent color (index from the pallette) instead of alpha, pretty much just like GIF), there is also GIF which has 'always' been supported (and is no longer cumbered with legal issues, which were only due to it's LZW based compression-algorithm, that one can bypass).
Because of the lack of alpha-channel, creating nice transparent PNG8 and GIF images (without the dreaded overly visual grainy (often white) borders) is somewhat of a true art, infact pixel-art.
The trick is to touch-up the borders between color and transparancy by hand AND to set the image's background-color (when rendering from alpha channel to single color-index transparancy) to the average color of the background the images are going to be used against.
The idea of fatter png's is that they have alpha-channels which will give you (for clear example) nice shades (if you had applied such an effect) that will blend with any background. Now with modern browsers, this works pretty nice (and doesn't require the pixel-art). Pixel-art PNG8/GIF can still have it's place though, for base64 encoded ui-elements, usually small icons.
Related
So I have a png file with a solid blue color. If I open it in any paint program (have tried multiple ones) it says that the color of the entire square is rgba(126,234,242,1.0). But when I open the PNG file in a html-page, and tries to make an identical square with pure CSS, the color comes out just slightly differently, even though I'm setting the color to the same exact rgba value. How is this possible? And what can I do to match the color of the CSS square to the PNG-square?
HTML:
<img src="blue.png"/>
<div></div>
CSS:
div {
width:100px;
height: 100px;
background: rgba(126,234,242,1.0);
}
Image:
I have tried to research this subject a bit, and I believe that it has something to do with color profiles. As far as I can understand, sRGB is the default color profile for everthing web-related. However, I've made sure that Krita, the paint application I'm using, is set to use sRGB, and I've both tried checking and not checking the box that says "embed sRGB profile" when exporting the PNG file from Krita. The two squares looked different in both cases.
Thanks in advance!
EDIT:
As suggested by Temani Afif, I used the color picker in chrome to look at the rgb-values.
First square (PNG): rgba(165,230,241,1)
Second square: rgba(126,234,242,1)
So is the correct approach just to pick the color in a browser instead of in a paint application? And I still don't really understand why the colors are displayed differently.
EDIT 2:
I thought it might be helpful to explain my real-world context of this problem. I have a menu designed with CSS in my javascript game. The menu has a PNG background, and buttons whose color is defined in CSS. I also have a "concept" PNG, where the entire menu with the buttons are drawn over the background. In the real html menu, the background looks identical to how it looks in the concept PNG, and I would like the buttons to look the same as well. Just color-picking the rgb-values from the concept PNG doesn't work, as shown with example above. Doing the workaround from my first edit works for my monitor, but doesn't for other monitors.
EDIT 3:
The workaround works for different monitors with the same computer. With another computer, the squares looks different again.
I've picked out a color that I want to use throughout my website - it's the color of the logo and of the header, among other things. In my case, it's #7ed321. I've created the logo and exported it as a PNG with the color profile stripped.
Problem is, the page looks completely different in Firefox, Safari, and Chrome - each are rendering the colors their own way.
Chrome, Safari, and Firefox, from top to bottom. That's the logo and a piece of the header below. They might look the same on your screen, but they sure don't on mine.
Chrome - renders both header and logo as native #7ed321 (sRGB #94C9D6).
Safari - renders both header and logo as native #54df16 (sRGB #7ed321), a much brighter green.
Firefox - renders logo as native #54df16 (sRGB #7ED321) and header as native #7ed321 (sRGB #94C9D6). So the colors don't even match.
Basically, Chrome realizes if I asked for #7ed321 in my PNG and my CSS, that I always want to see #7ed321 on my screen, so it does the necessary conversion to sRGB to match my monitor's color profile.
Safari assumes I provided both values in sRGB, so it does no conversion to my target monitor.
Firefox does no conversion for my logo but does convert my CSS-provided #7ed321 to sRGB #94c9d6.
As a result, the same page is looking inconsistent among browsers. The difference isn't significant, but I'd like to get them looking closer if I can. Is there anything I can do to my CSS/PNG to make the page look the same?
There is a way to ensure the logo and any other occurrences of the brand color in the code are the same. That is to use CSS to color any instance of the green.
Export the logo as just the white leaf with a transparent background. Then you can form the logo using CSS to create the circle and fill in the background color. For example:
HTML
<div class="logo"></div>
CSS
.logo {
display: block;
width: 100px;
height: 100px;
border-radius: 50px;
background: #7ed321 url(../img/logo.png) center no-repeat;
}
Now the code has applied the green color, so it will match any other green you apply with CSS such as the header.
As for making all browsers and screens look the same - that's a bit of a losing battle. Users all use different screens and the color will be rendered differently. It would quite honestly be pointless spending any time trying to do anything about that.
An alternative to using CSS to build the logo like this would be to show the logo as a font. You can do that will a tool like Fontastic which allows you to then do resizing and cool CSS transitions on the logo if you wanted: http://fontastic.me/
If you have a vector version of the image you could use the svg format. With svg you can access the color hex codes for stokes and fills directly from the markup. But the problem probably has something to do with that some browsers can make use of your operating systems colour profile and others can't.
It's an ancient and crappy solution, but sometimes the best way to make sure that at least the two elements match is to color the box created with css with a 1 pixel png that you export with all the same color settings as the logo.
I have it in my mind to create:
A patterned fixed background
A white background layer overtop of the patterned background
"transparent" text that is also transparent through the white background so the patterned background as the text.
For those wiser than me out there... is this even possible? If so how?
The text transparency is easy enough rgba(0,0,0,0.1) but I can't get it beyond the white layer to the pattern.
The code so far:
#inner-header {
background: url('../images/white.png'), url('../images/angusplaid.png');
position: fixed;
z-index: 1;
}
#logo a {
color: rgba(0,0,0,0.1)
}
Is there a way to make the white background transparent only where the text is? I have my doubts but would love to have it solved either way.
Cheers.
You have various options:
The first is with CSS background-clip.
Browser support: See http://caniuse.com/#search=background-clip (All & IE 8+, -webkit- prefix for Android 2.x)
How-to (with fallbacks & catches): http://css-tricks.com/image-under-text/
The second is with SVG (SVG.js)
Browser support: See https://svgdotjs.github.io/compatibility/
How to: See https://svgdotjs.github.io. Copy the example on the homepage. The <name> you enter in var drawing = SVG('<name>') must be the ID of the div you want to ouput to.
I'm sure some text to bitmap options must exist too.
I have a PNG picture representing a monochrome white magnifying glass with an alpha channel. This image is overlayed on the top of other pictures, with a semi-transparent background such that you still see below it:
When you hover that picture, I would like it to change to red, as do textual links per my CSS.
I have considered several options:
Use a 'LEFT-POINTING MAGNIFYING GLASS' (U+1F50D) character. This wouldn't work for the (fewer and fewer) clients that don't support an extensive set of Unicode characters; but when it works, it's not guaranteed to produce a monochrome character (on Apple implementations, it's a full-color emoji).
Use a mask, as described in this other similar question. This only works when you don't mind an opaque background (mine is not opaque) or when you can tell what's underneath your element with great certainty (and then it's rather hackish and ugly).
My current solution is to use a different picture to represent the white magnifying glass and the red magnifying glass that it changes for when you hover over the picture. It's an okay solution, but I was wondering if there was a way I could have just one picture of just one color, so that I don't have to go back to change the image color if I change my mind about the color.
I'm already doing extensive use of CSS3 and HTML5, so I don't mind going deeper as long as it's supported by the latest iterations of each major browser.
Fiddle with the numbers on this to get your color.
img.magnify:hover {
filter: hue-rotate(20deg);
-webkit-filter: hue-rotate(20deg);
-moz-filter: hue-rotate(20deg);
-o-filter: hue-rotate(20deg);
-ms-filter: hue-rotate(20deg);
}
Found here - more options available
I am inserting images in TD's in a table with
style="background-image: url("my_url_goes_here")
Then I apply a transparent PNG mask in that TD so that it rounds the image corners
(same colour as background corners, and it shows the middle of the picture)
I wonder if i can write the ALT of the image in the CSS part (style = "background-image: url()) as if I am to write the ALT to the mask image (which is what users can save if they right click on the image), Google will index transparent masks with ALT from the image.
If it's not clear what I'm asking, I will explain further, just ask.
Also, a friend of mine told me just minutes ago over the phone that css3-round borders can be applied to all sorts of things, not just borders, but also images etc. It'd be lovely if this is the case, i'm not sure round borders will round images too, never tried it tho' (exception as usual IE, where they show square).
Thanks.
No, you can't add alt to background images
Yes, it's possible - http://jsfiddle.net/TyFM7/
No css does not suppport the alt tag.
As for rounding image corners with CSS that is possible.
http://www.css3.info/preview/rounded-border/
The alt attribute is meant to provide a text-equivalent in the absence of a loaded resource. It doesn't go in background images, it goes on images, areas, etc.
Source: http://www.w3.org/TR/html4/struct/objects.html#h-13.8
As for rounded corners, border-radius works on images as well - even in IE. If you want to see the current best approach to providing styles for this property, check out http://css3please.com.
img.rounded {
-webkit-border-radius: 12px;
border-radius: 12px;
}
You don't need alt tags for background images, as you wouldn't want these actually indexed.
CSS border radius can be added to most things, here is an example of an image with the border radius added:
Example of image with 30px border radius