Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Site Design > Graphics & Design Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Graphics & Design Discussion Forum Post your graphics design questions/comments/ideas in here. Ask questions, post tutorials, discuss trends and best practices. Sub-forum for website accessibility and usability.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-15-2006, 03:40 AM
WebProWorld Pro
 

Join Date: Oct 2003
Location: Alberta, Canada
Posts: 264
weegillis RepRank 1
Default Width and Height attribute replacement in CSS

Somewhere along the way I picked up the idea that it is possible to remove width and height attributes to the CSS, rather than include them with the img tag. Perhaps I misunderstood. For example,
Code:
[img]images/image.jpg[/img]
would become,
Code:
[img]image/image.jpg[/img]
with the CSS,
Code:
.my_image{
	width:200px;
	height:150px;
}
As near as I can tell, the browser will still be able to map out the page without excessive calculations (the main reason for including the attributes). The space for the image is still reserved when the page is being drawn so surrounding content is able to flow into place, regardless of when the actual image arrives.

Now I can see the folly in this thinking, but favour the compactness, especially when dozens of pages have the same image element (though with perphaps a different picture). Can anyone help clarify the pros and cons of this line of approach?

Thanks, Roy
__________________
Volunteer for something in your community today!
Reply With Quote
  #2 (permalink)  
Old 10-16-2006, 07:26 PM
bj's Avatar
bj bj is offline
WebProWorld 1,000+ Club
 

Join Date: Apr 2005
Location: Delaware Valley, PA
Posts: 1,208
bj RepRank 2bj RepRank 2
Default

There are a couple older browsers that work better where floats are involved if images have width and height specified in the html. One example is when you've used a class to float an image left or right so you could wrap text around it, and wanted to use the class on different and differently sized images. It's not necessary in the newer browsers, but it is a good idea so you're backwards compatible.

Also, for those on a dialup connection, they won't have a layout jump around every time an image loads, since the space will be "reserved".
Reply With Quote
  #3 (permalink)  
Old 10-16-2006, 07:49 PM
WebProWorld Pro
 

Join Date: Oct 2003
Location: Alberta, Canada
Posts: 264
weegillis RepRank 1
Default

So for the sake of backward compatability it is better to have the page 300 bytes larger (assuming 12 images). Seems we're never going to be free to make the most of CSS, no matter what.

Can one assume that since Google uses what amounts to HTML 3.x these attributes are important to their spiders?

One needn't expect that screen readers need any information with respect to image size, so it makes more sense to remove width and height, as superfluous to the markup. Might there be a time when we can actually implement this approach?
__________________
Volunteer for something in your community today!
Reply With Quote
  #4 (permalink)  
Old 10-16-2006, 07:54 PM
WebProWorld Member
 

Join Date: Aug 2006
Posts: 47
PARoss RepRank 0
Default

Roy,

You might include this in your CSS style sheet, too:

a img, img {
border:0;
}

It eliminates the border for all images.

Phil
__________________
www.paross.com &
www.webproper.com
Reply With Quote
  #5 (permalink)  
Old 10-16-2006, 08:06 PM
bj's Avatar
bj bj is offline
WebProWorld 1,000+ Club
 

Join Date: Apr 2005
Location: Delaware Valley, PA
Posts: 1,208
bj RepRank 2bj RepRank 2
Default

You need to have it specified somewhere for it to be backward compatible re floats, and also for it to be kinder to dialup folks.

I guess I wasn't clear in my explanation.

For instance, in css--

img.leftfloat {
float: left;
}

and in html:
[img]myimage.gif[/img]

OR

img.leftfloat {
float: left;
width: 200px;
height: 100px;
}

[img]myimage.gif[/img]

The first example allows you to use any size image and float it left. The second will give you a floated left image that is width 200px and height 100px no matter what size it is, which could result in funhouse mirror distortion if it isn't 200 x 100.

Screen readers don't "read" what's in tags except as it applies to their particular chore, ie the alt attribute, so I doubt it's much overhead where they're concerned.
Reply With Quote
  #6 (permalink)  
Old 10-17-2006, 06:37 PM
iany's Avatar
WebProWorld Pro
 

Join Date: Sep 2003
Location: Stirling, Scotland
Posts: 243
iany RepRank 1
Default

You could also use:

img.myimg {
float: left;
width: 12.5em;
height: 6.25em;
}
[img]myimage.gif[/img]

Do this for each image and you will have zooming images too.

Ian
__________________
Ian Young
http://www.iyesolutions.co.uk
Reply With Quote
  #7 (permalink)  
Old 10-17-2006, 07:03 PM
bj's Avatar
bj bj is offline
WebProWorld 1,000+ Club
 

Join Date: Apr 2005
Location: Delaware Valley, PA
Posts: 1,208
bj RepRank 2bj RepRank 2
Default

True, as long as you don't mind the pixellation and loss of quality in the image that results with zoom.
Reply With Quote
  #8 (permalink)  
Old 10-17-2006, 07:15 PM
iany's Avatar
WebProWorld Pro
 

Join Date: Sep 2003
Location: Stirling, Scotland
Posts: 243
iany RepRank 1
Default

Sure in extreme zooms the image is all to hell in a hand bag and it depends on the quality of the original but where I have used em's with images, the trade off is acceptable.
__________________
Ian Young
http://www.iyesolutions.co.uk
Reply With Quote
  #9 (permalink)  
Old 10-17-2006, 08:06 PM
WebProWorld Pro
 

Join Date: Oct 2003
Location: Alberta, Canada
Posts: 264
weegillis RepRank 1
Default

Quote:
Originally Posted by iany
You could also use:

img.myimg {
float: left;
width: 12.5em;
height: 6.25em;
}
[img]myimage.gif[/img]

Do this for each image and you will have zooming images too.
This works 'nearly correctly' as long as the inherited font-size relates 12.5em to 200px, and 6.25em to 100px.

The downside to relative sizing of images is that there really is no guarantee that all users will see the image at its correct size, with no scaling applied by the browser. We might be taking a pretty big chance leaving it up to the browser, since some may render images rather more poorly than others when scaled to fit the relative sized viewport.

The idea of declaring image size in the CSS applies not just to floats, but to any redundant image element of fixed size, regardless how it is inserted in the layout, float, absolute position, image block or plain inline. As a rule, one might always include a width to accompany any float, for the sake of some browsers that don't deal well with floats, such as IE Mac 5.x. For example,
Code:
img{
	border:none;
}
img.inpage{
	width:300px;height:225px;
	border:3px double #b0d0c0;
	position:relative;z-index:10;
}
img.inpage.left{float:left;margin:6px 8px 0 0}
img.inpage.right{float:right;margin:6px 0 0 8px}
Sightly off topic, the position and z-index properties are applied to keep the image on top of the parent layer (also positioned relatively). This overcomes the disappearing float problem often experienced in IE.

In the following example, images are inline, positioned by text alignment in their parent container. Descendant selectors dial in the appropriate image:
Code:
div.content.photo_box{text-align:center}
div.content.photo_box p{margin-top:2em;margin-bottom:1.8em;text-align:center}
div.content.photo_box h3{margin-right:50px;text-align:right}
div.content.photo_box img{
	display:inline;
}
div.photo_box p img{
	width:512px;height:384px;
	border:4px double #a0c0b0;
}
div.photo_box h3 img{
	width:200px;height:150px;
	vertical-align:middle;
	border:3px double #a0c0b0;
}
__________________
Volunteer for something in your community today!
Reply With Quote
  #10 (permalink)  
Old 10-18-2006, 04:29 AM
iany's Avatar
WebProWorld Pro
 

Join Date: Sep 2003
Location: Stirling, Scotland
Posts: 243
iany RepRank 1
Default

Quote:
Originally Posted by weegillis
The downside to relative sizing of images is that there really is no guarantee that all users will see the image at its correct size, with no scaling applied by the browser. We might be taking a pretty big chance leaving it up to the browser, since some may render images rather more poorly than others when scaled to fit the relative sized viewport.
This seems to me a lack of understanding of em's and CSS and how they relate in various browsers.

The use of em's in IE6 can cause problems in defining font size, but only if the font size is not defined in the body.
eg body{font-size:100%}. Other than that there is no problem using em's for font or images across all browsers.
The use of img width/height in em is not restricted to floats in any case.
I have tested in Konqueror, Safari, Mac IE5.2, IEs (5.5,6,7), FF1.5&2 at 800x600, 1024x768 and 1280 800 and they all render images defined in this way fine.
If you use only em's for all positioning, then your entire page will zoom holding the layout stable.

BJ's point about zooming causing breaks in pixellation and therefore resolution is more important.

Have a look at this link where I have used my own site as an exmple of em defined image:

http://www.browsercam.com/public.aspx?proj_id=292331
__________________
Ian Young
http://www.iyesolutions.co.uk
Reply With Quote
Reply

  WebProWorld > Site Design > Graphics & Design Discussion Forum
Tags: , , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0