Why is class margin not working?

The code is as follows:

<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;
}
+5
source share
6 answers

You cannot give it a width because it is an inline element.

This property indicates the contents of the width of the boxes generated by the block level and replaced items. This property does not apply to non-replaced line level elements. - CSS 2.1 Width Property

You can fix this by making a block or element of an inline block instead:

display:inline-block

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

margin-left:40px
+10
source

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

. :

<link rel="stylesheet" type="text/css" title="RSS" href="MyStyleSheet.css">   
+1

, CSS: CSS .

0

put

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

Try changing the name of the class, maybe?

marginis an attribute. I'm not sure CSS has reserved keywords.

0
source

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

0
source

All Articles