我正在研究一個有多個層次的CSS菜單。在這個層面上,我有一個div,每個主題都有ID(Bar,Pie,Line等)。有沒有一種方法可以將所有這些div放在一個位置,而不必命名每個ID並放置相同的樣式? 我想我需要某種包裝,但我不確定放置它的位置以及如何在樣式表中正確調用它。如何使用一個選擇器來定位這些兒童div?
我的代碼:
<div class="menu">
<input id="s" name="UItab" type="radio" />
<label for="s">
<a href=""><span>Styles</span></a>
</label>
<div>
<div onmouseout=
"((collapseFlag == true) ? collapse('<?php echo $secondMenu?>'): expand());"
onmouseover="expand('sub-menu');">
<div id="sub-menu">
<ul class="sub-menu">
<li>
<a href="">Item1</a>
</li>
<li>
<a href="">Item2</a>
</li>
</ul>
</div>
</div>
<div id="sAdminEd" onmouseout=
"((collapseFlag == true) ? collapse('<?php echo $secondMenu?>'): expand());"
onmouseover="expand('<?php echo $secondMenu?>');">
<div id="second-sub-menu">
<ul class="second-sub-menu">
<li>
<a href="">Item1</a>
</li>
<li>
<a href="">Item2</a>
</li>
</ul>
</div>
</div>
<div id="Bar">
<ul class="second-sub-menu">
<li>
<a href="">Item1</a>
</li>
<li>
<a href="">Item2</a>
</li>
</ul>
</div>
<div id="Pies">
<ul class="second-sub-menu">
<li>
<a href="">Item1</a>
</li>
<li>
<a href="">Item2</a>
</li>
</ul>
</div>
<div id="Line">
<ul class="second-sub-menu">
<li>
<a href="">Item1</a>
</li>
<li>
<a href="">Item2</a>
</li>
</ul>
</div>
<div id="Table">
<ul class="second-sub-menu">
<li>
<a href="">Item1</a>
</li>
<li>
<a href="">Item2</a>
</li>
</ul>
</div>
<div id="Gauge">
<ul class="second-sub-menu">
<li>
<a href="">Item1</a>
</li>
<li>
<a href="">Item2</a>
</li>
</ul>
</div>
</div>
</div>
CSS:
#Bar {
display:none;
border: 1px solid #808080;
right:0;
top:57px;
background-image: url('../images/background4.png');
text-align: center;
min-width: 100%;
margin: 0 auto;
height: 20%;
}
#Pies {
display:none;
border: 1px solid #808080;
right:0;
top:57px;
background-image: url('../images/background4.png');
text-align: center;
min-width: 100%;
margin: 0 auto;
height: 20%;
}
#Line {
display:none;
border: 1px solid #808080;
right:0;
top:57px;
background-image: url('../images/background4.png');
text-align: center;
min-width: 100%;
margin: 0 auto;
height: 20%;
}
#Table {
display:none;
border: 1px solid #808080;
right:0;
top:57px;
background-image: url('../images/background4.png');
text-align: center;
min-width: 100%;
margin: 0 auto;
height: 20%;
}
#Gauge {
display:none;
border: 1px solid #808080;
right:0;
top:57px;
background-image: url('../images/background4.png');
text-align: center;
min-width: 100%;
margin: 0 auto;
height: 20%;
}
爲什麼不添加相同的類每使用該類給予同樣的風格,以這些元素? – Chris
這正是CSS類的用途... – rnevius