2016-05-05 4 views
0

私はその数がCSSセレクターに含まれていないことがわかりました。なぜCSSのセレクタでIDを数値にすることができないのですか?

<!DOCTYPE html> 
 
<html> 
 
<style type="text/css"> 
 
    div{width:350px;word-wrap:break-all; } 
 
    #1{float:left;} 
 
</style> 
 
<div class="up"> 
 
    <p><img id="1" src="http://i.imgur.com/Vt9ni32.jpg?1" /> Web graphics are visual representations used on a Web site to enhance or enable the representation of an idea or feeling, in order to reach the Web site user. Graphics may entertain, educate, or 
 
emotionally impact the user, and are crucial to strength of branding, clarity of illustration, and ease of use for interfaces. Examples of graphics include maps, photographs, designs and patterns, family trees, diagrams, architectural or engineering 
 
blueprints, bar charts and pie charts, typography, schematics, line art, flowcharts, and many other image forms. 
 
    </p> 
 
</div> 
 

 
</html>

CSSセレクタ内の数字は、右のテキストが上から始まっていない場合には、ギャップがここに残って、あなたがid=2または他の番号にid=1を変更するために、それは使用されません#1{float:left;}#2{float:left;}に変更すると、その隙間はそのまま残ります。
数字を単語に変更すると、次のようにギャップが消えます。あなたが数字で始まるIDを使用してはならないHTML 4では

<!DOCTYPE html> 
 
<html> 
 
<style type="text/css"> 
 
    div{width:350px;word-wrap:break-all; } 
 
#test{float:left;} 
 
</style> 
 
<div class="up"> 
 
    <p><img id="test" src="http://i.imgur.com/Vt9ni32.jpg?1" /> Web graphics are visual representations used on a Web site to enhance or enable the representation of an idea or feeling, in order to reach the Web site user. Graphics may entertain, educate, 
 
or emotionally impact the user, and are crucial to strength of branding, clarity of illustration, and ease of use for interfaces. Examples of graphics include maps, photographs, designs and patterns, family trees, diagrams, architectural or engineering 
 
blueprints, bar charts and pie charts, typography, schematics, line art, flowcharts, and many other image forms. 
 
    </p> 
 
</div> 
 

 
</html>

+2

そのないIDは数字にすることはできませんことを。任意の英数字の値を指定できますが、数字で始めることはできません。文字で始める必要があります。 ref:https://msdn.microsoft.com/en-us/library/ms533880(v=vs.85).aspx – zipzit

+3

注:私は[Mozilla](https://developer.mozilla.org/en)から参照してください'この制限がHTML5で取り除かれました、IDは互換性のために文字で始まるべきです。 'と言われましたが、これは他のものの純粋な複製であると私は信じています。答えはstackoverflowで。それを見つけました:http://stackoverflow.com/questions/70579/what-are-valid-values-for-the-attribute-in-html/79022#79022 – zipzit

答えて

0

HTML 5は、IDの数字で開始することができて幸せです、しかし、CSSではありません:read more here

+0

そのリンクターゲットで素晴らしい記事を書いてください! –

+0

私が発見した1つの楽しいことは、IEはフォームで数字で始まる名前が好きではないということです。フォーム['1_inforow']を実行しようとすると、実際にフォームが1に変換され、最初のフォーム入力が返されます:/ – karina

1

、それはレンダリングかもしれないが、(あなたが経験してきたように)いくつかの機能が壊れる可能性があります。しかし、HTML5では(acceptable IDs)が可能ですが、新しいHTML ID仕様はCSSに反映されないため、セレクタはまだ失敗します。 Read more here

関連する問題