我有以下的HTMLCSS繼承不父類的屬性
<div id="borderContainer" class="scViewer" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline',gutters:false">
<div id="buttonPagerContentPane" data-dojo-type="dijit/layout/ContentPane" align="center" data-dojo-props="region:'bottom'" class="buttonContentPane">
<div id="buttonPagerTitle" class="ContentPaneTitle">
Sheet Selector <br>
</div>
<button data-dojo-type="dijit/form/Button" type="button" data-dojo-attach-point="PreviousButtonAttachNode" id="previousButton" class="scViewButtonContent buttonContentPane">
Previous
</button>
<button data-dojo-type="dijit/form/Button" type="button" data-dojo-attach-point="NextButtonAttachNode" id="nextButton" class="scViewButtonContent">
Next
</button>
</div>
</div>
下面CSS:
.scViewer {
color: #2546ff;
}
.scViewer .buttonContentPane {
padding: 5px 5px;
color:#FFFFFF;
border-radius: 5px;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
}
.scViewer .ContentPaneTitle{
color: #2546ff;
font-weight: bold;
}
.scViewer .buttonContentPane .scViewButtonContent{
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.4);
text-decoration: none;
}
我的問題是,這兩個一個/下一個按鈕不繼承buttonContentPane類沒有明確定義它,即使它在父代buttonPagerTitle <div>
之內。爲了演示上述內容,我明確定義了不帶buttonContentPane屬性的nextButton,開發工具中生成的HTML不包含定義的buttonContentPane,但是遺傳部分包含buttonContentPane,其屬性變灰:
我的總體目標是在我的組織中重新使用樣板CSS代碼。我的語法錯了嗎?我不正確地構造選擇器嗎?感謝您的時間
是他們下一個類= 「scViewer」 的地方?由於您只發布了其他代碼的圖片,因此我們無法「按Ctrl-f」查找它們是否存在。一般提示:代碼圖片絕對沒用。 –
@MarcB是的,它被聲明爲根div,我原本排除它,但它在那裏(見編輯)。圖片只是爲了說明該類在開發工具中確實沒有定義。 – Rice
據我所知,在CSS屬性不被子元素繼承。因此.scViewer .buttonContentPane只會影響類.buttonContentPane的元素。使用.scViewer .buttonContentPane .scViewButtonContent明確定義按鈕是一個選項,可以根據需要爲其指定樣式,也可以使用逗號嘗試.scViewer .buttonContentPane,.scViewer .buttonContentPane按鈕,因此不必編寫相同的代碼兩次。編輯:只有特定的CSS樣式可以由父類(字體家族,文本對齊等)的孩子繼承 – Benneb10