CSSの特異性、およびクラスとIDの使用方法について学びます。これらの概念は、CSSの管理に役立ちます。
したがって、HTMLには次のようなものがあります。
<ul></ul>
<ul class="foo"></ul>
<ul class="foo" id="bar"></ul>
次に、CSSで:
/* This targets all ul elements */
ul {
font-size: 2em;
}
/* This targets only ul elements with a class of foo. It's more specific (has a higher specificity) than the above */
ul.foo {
font-size: 3em;
color: aqua;
}
/* The ul with a class of foo and an id of bar gets both sets of styles, but as ID has a higher specificity than class, the font size will be bigger. */
ul#bar {
font-size: 4em;
}
編集:ああ、問題がわかりました!CSSファイルは、とのアイテム<ul class="menu">
を<ul class="lblue">
それぞれターゲットにしているように見えます。があります<ul class="menu lblue slide">
。これは、両方のCSSファイルが同じulをターゲットにし、一方が他方をオーバーライドすることを意味します。結果は完全な混乱になります。
HTMLで2つのメニューを分離し、それに応じてターゲットを設定する必要があります。
<ul class="menu"><!-- Put the menu HTML code here --></ul>
<ul class="lblue"><!-- Put the lblue HTML code here --></ul>
また、id属性を誤解しているようです。IDはページごとに1回しか使用できず、スペースを含めることはできません。したがってid="lblue li"
、まったく機能しません。今のところそれらを削除することをお勧めします!