I have noticed that svg icons that placed via 'img' tag aren't rendered correctly in safari. They end up being all blurry. I have created a simple html page and pasted the same svg icon multiple time using different methods :
I am a bit frustrated why does the 'img' tag lower the quality of the icon?
Thank you in advance!
Edit: I have created a demo
Maybe it will be helpful for someone - Safari can't correct render IMG tag (SVG format) for retina display - so the solution is - UP size image - the result you can see here
Demo
Костыль для сафари (in Russian)
#svg {
width: 20px;
height: 21px;
div {
position: relative;
transform: scale(0.25);
transform-origin: 0 0;
height: 100%;
&:before {
content: '';
display: block;
position: absolute;
width: 400%;
height: 400%;
background-image: url(http://svgshare.com/i/1Le.svg);
background-size: contain;
background-repeat: no-repeat;
}
}
}
.w-img {
width: 20px;
height: 21px;
img {
height: 400%;
width: 400%;
vertical-align: middle;
transform: scale(0.25);
transform-origin: 0 0;
}
}
I'm sorry it's probably late but I had a similar problem and it was because of the blur filter, when I put the shadow on another element and kept the original one on top of it, it worked fine. E.g., you have to duplicate your icon element, apply shadow to it and finally place it below the actual icon.
When you put SVG into an <img> tag, it basically bitmaps the vector file. So where the SVG is capable of scaling and remaining sharp at all sizes, the <img> tag treats it analogous to a gif and any scaling will compromise the quality of the image.
Using SVG as an img | CSS Tricks
If I save the SVG to a file, I can use it directly in an <img> tag.
<img src="kiwi.svg" alt="Kiwi standing on oval">
In Illustrator, our artboard was 612px ✕ 502px. That's exactly how big the image will on the page, left to itself. You can change the size of it though just by selecting the img and changing its width or height, again like you could a PNG or JPG. Here's an example of that.
So in short, by using an <img> tag, you lock the size of the base image. This then allows the browser to determine the quality of the image, which is going to be directly proportional to how different from the original size you are trying to display the image. In this case, as can be expected, safari is handling it less elegantly than if you displayed the SVG using another means.
Related
I was trying to have an image or maybe multiple images as a background and wanted it also it being simple to change it to a video as well, in case I want to.
However, with <img> I noticed an issue and with CSS, I couldn't reproduce the same that <img> did, so I came up with <video> and its attribute poster instead.
I'm wondering if that's a good idea. Below I explained what I tried and examples so you can see the difference between the <img> and CSS one.
I put an <img> as a background. The only issue is that it is selectable, however there are properties like user-select, but browsers like IE didn't support it.
Here is an example with <img>:
* {
padding: 0;
margin: 0;
}
html {
height: 100%;
width: 100%;
}
body {
background-color: #090909;
}
div.background {
position: fixed;
top: 0;
bottom: 0;
height: 100%;
width: 100%;
z-index: -1;
overflow: hidden;
}
div.background img {
position: absolute;
min-width: 100%;
min-height: 100%;
max-width: none;
max-height: none;
height: auto;
width: auto;
top: 0;
}
<html>
<body>
<div class="background">
<img src="https://i.imgur.com/sMzN1LP.png" draggable="false">
</div>
<div style="color: white;">Text</div>
</body>
</html>
https://jsfiddle.net/hd6orszb/1/
Here, when you zoom out, the image stays in the screen, it's like background-size: cover. And when you zoom in, after zooming over 100%, it will zoom in the image as well. Which was okay, however the <img> can be dragged and selected and user-select doesn't work anywhere. The attribute "draggable" does, however even if you add user-select: none;, if you press CTRL + A, and drag the Text, in Chrome at least you can see the image being dragged as well. And I didn't wanted that.
So I used CSS, because this doesn't happen with the "background" property:
https://jsfiddle.net/5n6mtyb4
Now if you zoom out there and zoom in, there's nothing that keeps resizing it, like I did for <img>, so I added background-size: cover. But if you zoom in and out it will stay the same, but I wanted to keep the effect <img> did.
So I didn't had any idea, what else I could do. I think with #media it might be a bit hard because it's zooming, where anything can have a different size, I guess.
Other thing was using <video> with the poster attribute.
https://jsfiddle.net/5n6mtyb4/1/
Which was unselectable like the CSS one and behaves like <img> just unselectable as well. However I'm not sure if this is the ideal way to do it and if there could be any issues with that.
So I'm wondering, if there's a better way to do it, or if <video> is completely fine as an alternative to <img>.
For IE9, you'll need to add unselectable="on" attribute it is like user-select:none;, and for drag you can add draggable=flase i find the background is the ideal, but video is fine also it has no problems with it using the poster.
Edit Nov 20: you can make psuedo element before Or after and they won't be selectable neither draggable, but you can't set width or height on the url(img)
You can accomplish this by adding these lines to CSS of your image:
img {
user-drag: none;
user-select: none;
}
That should be the answer.
Is there a way to remove the border when an image is not yet loaded but the height and width are set?
I am creating a lazy loading so the icon will be centred inside as a background image, until image loads.
http://codepen.io/anon/pen/bgoqYv
same code in the snippet also
body {
padding: 50px;
}
img {
height: 200px;
width: 200px;
/* border: 0 !important; */
background-image: url(https://i0.wp.com/cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.16.1/images/loader-large.gif);
background-repeat: no-repeat;
background-position: 50% 50%;
}
<img src="http://www.site/nonexistant.jpg" />
You can't style the "broken image". But you can work around it. For example you can replace the broken image with some little javascript:
<img src="idonotexist.jpg" onerror="this.src='trans.png';">
Of course you can write it cleaner in js instead inside the img tag.
Alternatively, you can work with pseudo classes to hide the broken image etc. Have a look here: https://bitsofco.de/styling-broken-images/
I am using a wordpress template to control my website. On the home page is a small header with "Home About Us Contact Us" etc etc and then below that is an image that transitions to another image which transitions to another image. This image is too large for my liking so I am trying to shrink it. So I go to the CSS and adjust the image size, however because there is text on the bottom of the image it is being cut off.
I would like to maintain the image width but just make it a little shorter, say about 75% of the original design.
Below is what I think is the applicable code
.camera_wrap {
height: 672px!important;
max-width: 1920px;
display: none;
position: relative;
z-index: 0;
margin: 0 auto 60px!important;
I added the height: 672px!important; code which makes it about the height I want but again the bottom gets cut off. I would prefer to have the CSS re-size the image instead of clip it. But all of my searches haven't turned up how to do this. I am just finding the re-size attribute.
Try using a path to the img rather than the images class to control the styling for the image.
example html
<div class="image-div">
<img class="image">
</div>
instead of
.image { height: 500px; }
try
.image-div img { height: 500px; }
Also, here's an example of a fiddle and an example in that fiddle of how to affect change to only the second image using nth-child
https://jsfiddle.net/Hastig/g6m5nqc9/1/
.image:nth-child(n+2) {
height: 75px;
}
I have a video background on my website, which want to have a blur overlay over it. Something like IOS7 Notification Center. Since I could not do it by Photoshop. I thought to use blur effect in CSS. It seems also doesn not do what I want.
However, I made a div class width 100% height and width. and choose white color as background, then gave it the blur element. It does not work the way I want, anyway.
#blur{
width: 100%;
height: 100%;
z-index: -1;
position: fixed;
background: #FFF;
top: 0;
filter:blur(350px);
-o-filter:blur(350px);
-ms-filter:blur(350px);
-moz-filter:blur(350px);
-webkit-filter:blur(350px);
}
HTML : <div id="blur"> </div>
This is an example like what I am looking for: http://wpuploads.appadvice.com/wp-content/uploads/2013/06/117.jpg
Any idea?
A CSS blur filter will blur what's part of the layer, not what's behind or in front of the layer. So you may need to apply this type of filter directly to the video container.
I'm not 100% sure this is your issue since no HTML was added to the question.
UPDATE:
I just tested this on YouTube.com and if I apply a blur filter directly to the <video /> element, the video plays blurred.
Don't think i understand the question correctly. But if you want a white layer on top of the video you need to add the opacity property in your css code, to give the effect of a transparent overlay.
opacity: 0.4;
Your code should then look like
#blur{
width: 100%;
height: 100%;
z-index: -1;
position: fixed;
background: #FFF;
top: 0;
filter:blur(350px);
-o-filter:blur(350px);
-ms-filter:blur(350px);
-moz-filter:blur(350px);
-webkit-filter:blur(350px);
opacity: 0.4;
}
Something interesting happens in my website. It is in active development and I keep adding and adding stuff to the website's sprite PNG file. Sometimes I add so many icons and blocks that I NEED to change the height of the image, but when I do this, some (NOT ALL!) elements appear on different locations.
For example I have a PNG image with size 900x900 pixels. I mapped the CSS styles to the proper coordinates, they I added 200 pixels of transparent space at the bottom of the image and some styles report different positions :< breaking stuff around the website. So each time I increase the sprite file, I have to open various CSS files and add X pixels (the amount of height I've added). I even added a 1px baseline on the top of the sprite so that I would be certain that I am not changing any positions but just the height.
I read the specification even in the RFCs and the coordinate system start is at x=0,y=0 which is the top left corner of the image. It doesn't make sense to me :(
UPDATE: Some of the containers that give me bugs are made with positive coordinates rather than negative. I still can't explain it to myself, why stuff like that happens.
UPDATE: So the sprite is located at this URL http://lucho.hoolwars.com/img/sprites.png
and here are few styles that change coordinates if the height of the sprite changes
.job-summary {
width: 330px;
height: 45px;
background: transparent url(/img/sprites.png) -15px 435px;
cursor: default;
}
.popup-title {
background: url('../img/sprites.png') -425px -1077px transparent;
width: 275px;
color: black;
font-weight: normal;
}
.popup-close {
position: absolute;
background: url('../img/sprites.png') -771px -972px transparent;
right: -9px;
top: -22px;
width: 38px;
height: 38px;
z-index: 2;
cursor: pointer;
}
Each time I change the height of "sprites.png" those coordinates are no longer valid :|
I think I know whats going on. Hard to explain - but I'll give it a shot.
I believe you have configured some of your sprite images based on the repeating background, because you are not using no-repeat. Every time you add more images to the sprite any icons that were configured on a repeated image will shift.
You will need to:
1) Add no-repeat to your background (any icons that were using a repeated image will probably now be blank)
2) Reconfigure all your classes to use negative values (always use negative values for your image sprites)
I would suggest you setup your sprites similar to this:
CSS
.sprite-map {
background: url(sprites.png) no-repeat;
}
.job-summary {
background-position: -80px 0;
width: 100px;
height: 80px;
}
.popup-title {
background-position: -15px -100px;
width: 200px;
height: 100px;
}
.popup-close {
background-position: -15px -472px;
width: 50px;
height: 50px;
}
HTML
<div class="job-summary sprite-map"></div>
<div class="popup-title sprite-map"></div>
<div class="popup-close sprite-map"></div>
That way you only need to specify the URL to the sprite once. Now when you add images to the bottom or the right of the sprite - nothing else will be affected.
Also if you're familiar with Sass - Compass makes image sprites incredibly easy. It might be worth taking a look at if you're interested: http://compass-style.org/help/tutorials/spriting/
Hope this helps!