tags:

views:

223

answers:

6

The code is as below:

<html>
<head>
<title>test</title>
</head>
<body>
<div><span>shanghai</span><span class="margin"> </span><span>male</span></div>
</body>
</html>

.margin {
    width:40px;
    height:auto;
}
A: 

You should indicate that this is a CSS rule : Ways to include CSS in your page.

Moayad Mardini
yup,.margin is a css rule
Shore
I see, but you put that rule outside the html doc, how can the browser know that this is a piece of CSS?!
Moayad Mardini
A: 

put

<style>
   .margin {    
     width:40px;    
     height:auto;
   }
</style>
pho3nix
Isnt that what I did,hm?
Shore
Did you put it into a .html and see the effect?
Shore
Yes and work very well :)
pho3nix
ic,it's working in ie,but not in firefox.
Shore
+1  A: 

CSS should go into the head section and should also be wrapped in < style > tags...

Unless you are accessing this value from a stylesheet. You would need to reference this in the head section of your document:

<link rel="stylesheet" type="text/css" title="RSS" href="MyStyleSheet.css">
James
sorry,I did,but omited in my post
Shore
what browser are you using?
James
firefox..... .
Shore
Use padding-right instead of width.
James
the above code works in ie but not in firefox,do you know why?
Shore
I tested in firefox/chrome/IE and it works in all 3...
James
+2  A: 

You can't give it a width because it is an inline element.

This property specifies the content width of boxes generated by block-level and replaced elements. This property does not apply to non-replaced inline-level elements. -- CSS 2.1 Width property

You can fix this by making it a block or inline-block element instead:

display:inline-block

However, this may not be supported by some browsers. You can probably achieve the same result with this, however:

margin-left:40px
Nick Retallack
still the same :(
Shore
margin-left helps!
Shore
inline-block works on spans in IE - see http://www.quirksmode.org/css/display.html. FF2 is still less than happy with inline-block though
Dan F
A: 

Try changing you class name maybe?
'margin' is an attribute. I'm not sure if css has reserved keywords though.

the_drow
tried,not working,though
Shore
good to know that css doesn't behave this way :)neat.
the_drow
A: 

I think the problem is that the tag is empty. Just put "&nbsp;" between the two tags.

dutchflyboy
tried,not help,though
Shore