我正在嘗試從左到右更改第一個按鈕的背景顏色和位置,以便首先顯示第二個按鈕。但是:first-child選擇器不起作用。
我正在使用 sass。
HTML結構-
<div class="buttonWrapper">
<button class="reject" id="rcc-decline-button" aria-label="Decline cookies">Reject</button>
<button class="accept" id="rcc-confirm-button" aria-label="Accept cookies">Accept Cookies</button>
</div>
我的代碼:
.buttonWrapper button{
border: none;
border-radius: 4px;
background-color:#000;
button:first-child{
background-color:#fff;
float: right;
margin-left: 2rem;
}
}
任何幫助都受到高度贊賞。
uj5u.com熱心網友回復:
如果您使用支持嵌套的前處理器(SASS、LESS 等),則應&在嵌套中使用選擇器:
.buttonWrapper button {
border: none;
border-radius: 4px;
background-color: #000;
&:first-child{
background-color: #fff;
float: right;
margin-left: 2rem;
}
}
CSS 本身不支持像前處理器那樣的嵌套方式。常規 CSS 需要更詳細的語法(注意:上面的嵌套語法將編譯為這個普通的 CSS):
.buttonWrapper button {
border: none;
border-radius: 4px;
background-color: #000;
}
.buttonWrapper button:first-child{
background-color: #fff;
float: right;
margin-left: 2rem;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/381898.html
