5 replies [Last post]
tzug
Offline
Regular
Last seen: 16 years 32 weeks ago
Joined: 2004-09-28
Posts: 21
Points: 0

<img src="../images/x1.gif" alt="" border="0" style="background: red"/>

i mean...
is it legal to put the style="background: red" inside an img tag

roytheboy
roytheboy's picture
Offline
Guru
North Wales, UK
Last seen: 7 years 41 weeks ago
North Wales, UK
Timezone: GMT+1
Joined: 2004-09-18
Posts: 2233
Points: 41

is this legal :

Run it through the validator for your chosen DOCTYPE and find out.

Life's a b*tch and then you die!

DCElliott
DCElliott's picture
Offline
Leader
Halifax, Canada
Last seen: 4 years 5 days ago
Halifax, Canada
Timezone: GMT-3
Joined: 2004-03-22
Posts: 828
Points: 0

is this legal :

You can use an inline style (what styles inside tags are called) with any properties that apply to the tag in question. Your code would be more properly written:

<img src="../images/x1.gif" alt="" style="border:0; background-color:#ff0000 ;" />

Note the changes: border moved into the style=, background-color is the property for just the color. You use background as the shorthand when you are specifying multiple properties: background-color, background-image, background-position, background-repeat, etc. all in one declaration. I also changed the color to hex since named colors won't validate. Also, always remember to leave a space between the last attribute and the forward slash terminating an empty tag (empty tags are tags without closing tags, eg: meta, link, hr, br, img)

DE

David Elliott

Before you ask
LearnXHTML|CSS
ValidateHTML|CSS

tzug
Offline
Regular
Last seen: 16 years 32 weeks ago
Joined: 2004-09-28
Posts: 21
Points: 0

is this legal :

ok tnx
what CSS validator u r using ?
i use the w3c validator but its not checking for css inside the tags

SORRY
MY MISTAKE
IT DOES CHECKS INSIDE THE TAGS :oops:

kk5st/2
Offline
Regular
Last seen: 16 years 27 weeks ago
Timezone: GMT-6
Joined: 2004-11-01
Posts: 27
Points: 0

is this legal :

DCElliot sz:

Quote:
I also changed the color to hex since named colors won't validate.
Not completely true. The following sixteen name-value colors are part of html 4.0, and do validate;
  • aqua,
  • black,
  • blue,
  • fuschia,
  • gray,
  • green,
  • lime,
  • maroon,
  • navy,
  • olive,
  • purple,
  • red,
  • silver,
  • teal,
  • white, and
  • yellow.

cheers,

gary

[/]

…there is no publishing concept so simple that money, knowledge of HTML arcana, and graphic design can't make slow, confusing, and painful for users.
–Greenspun, MIT

DCElliott
DCElliott's picture
Offline
Leader
Halifax, Canada
Last seen: 4 years 5 days ago
Halifax, Canada
Timezone: GMT-3
Joined: 2004-03-22
Posts: 828
Points: 0

is this legal :

*Ouch* my bad. I guess I am reflecting on the fact that all my favorite colors won't validate, like "mediumvioletred" and "cornflowerblue" and "darkorchid" and of course the longest named color of all "lightgoldenrodyellow"

As for validation the W3C CSS-validator can be found at: http://jigsaw.w3.org/css-validator/ for those who didn't know. It has a text area that you can plop bits of CSS into to check them on the fly.

DE

David Elliott

Before you ask
LearnXHTML|CSS
ValidateHTML|CSS