Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-04-2013, 11:00 AM   PM User | #1
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,513
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
HTML5 - width=100% not valid problem

Hi,

In my HTML I have this code:

Code:
<img alt="My website pages" title = "My website pages" width="100%" height="150px" src="http://simpg.net/sys_images/simplepage.png"  >
And it displays just fine.

But when I validate it I get:
Bad value 100% for attribute width on element img: Expected a digit but saw % instead.

If I take out the width="100%" then the image doesn't stretch across the screen and doesn't look so good.

Is there an "official" way to stretch the image to fill the screen width ?

Thanks.


.
__________________
If you want to attract and keep more clients, then offer great customer support.

Support-Focus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.
jeddi is offline   Reply With Quote
Old 01-04-2013, 01:22 PM   PM User | #2
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 849
Thanks: 67
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
Use CSS:

Give it an ID like so:
Code:
<img alt="My website pages" title="My website pages" id="image" src="http://simpg.net/sys_images/simplepage.png"  >
Then in your CSS, do this:
Code:
#image
{
width: 100%;
height: 150px;
}
Give that a try and re-validate your HTML.

Kind regards,

LC.
LearningCoder is offline   Reply With Quote
Old 01-04-2013, 02:54 PM   PM User | #3
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,513
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
THat worked
__________________
If you want to attract and keep more clients, then offer great customer support.

Support-Focus.com. automates the process and gives you a trust seal to place on your website.
I recommend that you at least take the 30 day free trial.
jeddi is offline   Reply With Quote
Old 01-04-2013, 03:01 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
This is because the width and height attributes of an img are (pixel) values, so "px" in the height attribute is also invalid.

The previous post confirms that you can set these values in CSS.

An alternative approach is to make the image the background to another element. However, stretching a background-image is only available from CSS3:

Code:
background-size: 100%; /* CSS3, or */

.style1 {
        background: url(images/bg.jpg) no-repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
} /* IE 9+ */
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:07 PM.


Advertisement
Log in to turn off these ads.