Jump to content

Class IMG


pmdesign

Recommended Posts

Hi there,I'm wondering how you can use a picture in your CSS class.Well i'm using the "background-image: url()" option to put an image inside my class, but i need to use "width" and "height" just to be the image displayed...Well i don't think it's the best way. So is there any way you can declare a class with "src" option, and when it's used somewhere in the code, a picture is displayed. I dont wanna use "width" or "height" options cause some of the browsers do not understand it well.Well hope somebody could help me :)

Link to comment
Share on other sites

You can't use <img src="#">? That would be the best way to display an image without a height or width... but I'm assuming you already knew that. However I don't think there is a way for you to do what you are asking.

Link to comment
Share on other sites

You can't use <img src="#">? That would be the best way to display an image without a height or width... but I'm assuming you already knew that. However I don't think there is a way for you to do what you are asking.
Thanks, i knew it but i was trying to make sure it's not possible at this time :)
Link to comment
Share on other sites

The problem is not with the browsers, they actually understand it well but the problem is that if you use an img element you should use the required attributes width and height as well - at least if you want your code to be valid.So, in my opinion, you should always use height and width, and the CSS will override the settings if necessary :) but please don't make the mistake of soo many to deliver invalid code!

Link to comment
Share on other sites

I do not believe that the <img> tag code will be invalid if you don't add the height and width to them. The height and width on an image is really optional, they are just added there to make sure your intended size for the image stays even if you lose the image its self. :)

Link to comment
Share on other sites

It is entirely optional. I use NO width/height tags and I've never had problems with validation. People recommend you use width/height because a lot of layouts depends on the image being a certain size - meaning, if the image doesn't load, some element following it will be out of place. Also, if somebody turns image loading off (perhaps they're still on a 9600bps modem or on a cellphone) then your layout could turn to poop. Also, even if the images do load right, they don't start loading until the HTML is downloaded (I think - either way, the HTML gets downloaded a lot quicker than the images), meaning the user will find a crummy looking layout that jumps around as images fill in their spots. I get away without using width/height because I rely on CSS to control layout.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...