亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

拆分幻燈片兄弟姐妹,一個兄弟姐妹在懸停時影響另一個

拆分幻燈片兄弟姐妹,一個兄弟姐妹在懸停時影響另一個

30秒到達戰場 2022-07-15 10:25:26
我試圖實現與 Navy.com 標題類似的效果,您將鼠標懸停在一個兄弟姐妹上,它會滑動以占用大部分空間,同時縮小和隱藏另一個兄弟姐妹的內容。由于CSS標準不能選擇以前的兄弟,所以我只能實現一側而不是另一側的效果。我知道僅使用 CSS 可能無法做到這一點。預先感謝您的幫助!這是我目前正在使用的代碼:.container {  display: flex;  flex-direction: row-reverse;}.b1 {  display: flex;  order: 2;  width: 50%;  height: 150px;  padding: 10px;  background-color: rgb(40, 251, 202);  transition: all 0.5s;}.b2 {  display: flex;  width: 50%;  order: 1;  height: 150px;  padding: 10px;  background-color: rgb(227, 29, 103);  transition: all 0.5s;}.b1:hover {  width: 80%;}.b2:hover {  width: 80%;}.b1:hover~.b2 {  background-color: rgba(227, 29, 103, 0.4);  width: 20%;}.b2:hover~.b1 {  background-color: rgba(40, 251, 202, 0.4);  width: 20%;}.b1:hover~.b2 span {  display: none;}.b2:hover~.b1 span {  display: none;}<div class="container">  <div class="b2">    <span>This content will show up directly in its container.</span>  </div>  <div class="b1">    <span>This content will show up directly in its container.</span>  </div></div>
查看完整描述

1 回答

?
慕仙森

TA貢獻1827條經驗 獲得超8個贊

通過一些重組,您將能夠僅使用 CSS 來實現您想要的效果。在這個實現中,我使用了:not CSS 選擇器,并結合了一些多級:hover選擇器(因為.container和.child占用相同的空間而起作用)


雖然,只是作為一個建議:利用 flex 的自動增長,并width: 20%;完全刪除邏輯。這樣,未懸停組件的子組件將占用相等的空間,懸停的子組件仍將增長到 80% 的寬度。這將允許您動態添加更多項目,而無需更改硬編碼的 CSS。


.container {

  display: flex;

}


.child {

  width: 50%;

  height: 150px;

  padding: 10px;

  transition: all 0.5s;

}


.child--red {

  background-color: rgba(227, 29, 103, 1);

}


.container:hover .child--red:not(:hover) {

  background-color: rgba(227, 29, 103, 0.4);

}


.child--green {

  background-color: rgba(40, 251, 202, 1);

}


.container:hover .child--green:not(:hover) {

  background-color: rgba(40, 251, 202, 0.4);

}


.container:hover .child:not(:hover) span {

  display: none;

}


.container:hover .child {

  width: 20%;

}


.container:hover .child:hover {

  width: 80%;

}

<div class="container">

  <div class="child child--green">

    <span>This content will show up directly in its container.</span>

  </div>

  <div class="child child--red">

    <span>This content will show up directly in its container.</span>

  </div>

</div>


查看完整回答
反對 回復 2022-07-15
  • 1 回答
  • 0 關注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號