omg
omg

Reputation: 139862

why the class margin not work?

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;
}

Upvotes: 5

Views: 11175

Answers (6)

the_drow
the_drow

Reputation: 19181

Try changing you class name maybe?

margin is an attribute. I'm not sure if CSS has reserved keywords though.

Upvotes: 0

Nick Retallack
Nick Retallack

Reputation: 19561

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

Upvotes: 10

dutchflyboy
dutchflyboy

Reputation: 641

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

Upvotes: 0

James
James

Reputation: 82096

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">   

Upvotes: 1

pedrofernandes
pedrofernandes

Reputation: 16854

put

<style>
   .margin {    
     width:40px;    
     height:auto;
   }
</style>

Upvotes: 0

Moayad Mardini
Moayad Mardini

Reputation: 7341

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

Upvotes: 0

Related Questions