I am an open-source developer and going for pure HTML5 and CSS3 with my webframework (http://m-m-m.sf.net). I want to draw a validation error icon via input:invalid rule in CSS aligned to the right. But it is only working in FF but not in webkit based browsers such as Chrome or Safari. I created a minimal standanlone html (without validation and :invalid) for testing:
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
<!--
input {
border-color: #ff2222;
background-color: #ff8888;
background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='1em' height='1em'><g><circle cx ='8' cy ='8' r ='8' style='fill:%23ff0000;stroke:none'/><text x='6' y='13' style='font-size:14px;fill:%23ffffff;stroke:none;font-family:Monospaced;font-weight:bold'>!</text></g></svg>");
background-repeat: no-repeat;
/* background-size: auto; */
background-position: 98% 50%;
}
-->
</style>
</head>
<body>
<input type="text" placeholder="type here" />
</body>
</html>
Any ideas?
Why is SVG not showing up in Chrome? Chrome browser doesn't support SVG format with <img src=””> tag anymore. Peoples are facing issues that they aren't able to see their images in Chrome browser because the images are in SVG format. So I found a solution to display SVG image in Chrome browser with <object> tag.
Make sure the image path is set correctly in the background-image url. Once you have made sure that your CSS file is linked correctly, also check that the image itself is set correctly. Again, you will want to open your code inspector in the browser to check.
SVG images can be used as background-image in CSS as well, just like PNG, JPG, or GIF. All the same awesomeness of SVG comes along for the ride, like flexibility while retaining sharpness. Plus you can do anything a raster graphic can do, like repeat.
I recommend moving your css from the inline scope. Assuming that your . png file actually exists, try setting the background size and repeat tags. If that doesn't work, try checking in your browser's developer tools for the response codes and making sure that the url is correct.
You may try base64 encoded data uris for svg background images.
This is how it would look in CSS:
input {
border-color: #ff2222;
background-color: #ff8888;
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iMTZweCIgaGVpZ2h0PSIxNnB4Ij48Zz48Y2lyY2xlIGN4PSI4IiBjeT0iOCIgcj0iOCIgZmlsbD0iI2ZmMDAwMCIgc3Ryb2tlPSJub25lIiAvPjx0ZXh0IHg9IjYiIHk9IjEzIiBzdHlsZT0iZm9udC1zaXplOiAxNHB4OyBmb250LWZhbWlseTogU2Fucy1zZXJpZjsgZm9udC13ZWlnaHQ6IGJvbGQ7IHN0cm9rZTogbm9uZTsgZmlsbDogI2ZmZmZmZjsiPiE8L3RleHQ+PC9nPjwvc3ZnPg==");
background-repeat: no-repeat;
/* background-size: auto; */
background-position: 98% 50%;
}
I changed the font-family
to Sans-serif as the other (Monospaced) font got rendered 2px more to the right by Chrome on Windows, you could play with this a little. I used this online encoder.
Here is the same svg with the Monospaced font:
background-image: url("data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iMTZweCIgaGVpZ2h0PSIxNnB4Ij48Zz48Y2lyY2xlIGN4PSI4IiBjeT0iOCIgcj0iOCIgZmlsbD0iI2ZmMDAwMCIgc3Ryb2tlPSJub25lIiAvPjx0ZXh0IHg9IjYiIHk9IjEzIiBzdHlsZT0iZm9udC1zaXplOiAxNHB4OyBmb250LWZhbWlseTogTW9ub3NwYWNlZDsgZm9udC13ZWlnaHQ6IGJvbGQ7IHN0cm9rZTogbm9uZTsgZmlsbDogI2ZmZmZmZjsiPiE8L3RleHQ+PC9nPjwvc3ZnPg==");
and a jsfiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With