請查看我的Flexbox布局顯示& quot了解更多& quot懸停時的按鈕和文本描述。我試圖使用。列:hover +。隱藏選擇器,但。隱藏類似乎不能正常工作。
關于代碼的功能和設計,我有幾個問題:
最初,我想隱藏按鈕,只在右邊顯示 懸停時的側面。 我還希望當鼠標懸停在按鈕上時顯示描述文本。 提前感謝您的幫助!
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
margin: 0;
padding: 0;
height: 100%;
}
body {
background-color: #10172b;
font-family: Poppins, Arial, "sans-serif";
color: #ffffff;
}
.container {
display: flex;
justify-content: space-between;
background: #10172b;
}
.column {
flex: 1;
background-color: #f1f1f1;
transition: flex 0.5s;
cursor: pointer;
background: #293346;
margin-right: 20px;
}
.column:hover {
flex: 0 0 60%;
}
.responsive {
max-width: 100%;
height: auto;
}
.purple {
align-self: flex-end;
background-color: #6d38f1;
color: #ffffff;
font-size: 16px;
padding: 10px 24px;
border: 0px;
box-shadow: 0px;
text-align: left;
}
.purple:hover {
background-color: #15E333;
}
.hide {
display: none;
}
.description:hover + .hide {
display: block;
}
<div class="container">
<div class="column">
<div style="padding-left: 15px;">
<h3>Services</h3>
<p class="description hide">Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit</p>
</div>
<img src="https://placehold.co/400x400.png" alt="Services" class="responsive"/>
<button class="purple hide">Learn More ►</button>
</div>
<div class="column">
<div style="padding-left: 15px;">
<h3>Warehouse</h3>
<p>Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit</p>
</div>
<img src="https://placehold.co/400x400.png" alt="Warehouse" class="responsive"/>
<button class="purple">Learn More ►</button>
</div>
<div class="column">
<div style="padding-left: 15px;">
<h3>IIOT</h3>
<p>Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit</p>
</div>
<img src="https://placehold.co/400x400.png" alt="IIOT" class="responsive"/>
<button class="purple">Learn More ►</button>
</div>
</div>
如果我沒理解錯的話,我相信這就是你想要的。 我在CSS的底部添加了2條規則。
最后一個規則是搜索包含懸停按鈕的父節點。找到后,它顯示第一列的文本。
關于:has()選擇器的更多信息可以在這里找到。
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
body {
background-color: #10172b;
font-family: Poppins, Arial, "sans-serif";
color: #ffffff;
}
.container {
display: flex;
justify-content: space-between;
background: #10172b;
}
.column {
flex: 1;
background-color: #f1f1f1;
transition: flex 0.5s;
cursor: pointer;
background: #293346;
margin-right: 20px;
}
.column:hover {
flex: 0 0 60%;
}
.responsive {
max-width: 100%;
height: auto;
}
.purple {
align-self: flex-end;
background-color: #6d38f1;
color: #ffffff;
font-size: 16px;
padding: 10px 24px;
border: 0px;
box-shadow: 0px;
text-align: left;
}
.purple:hover {
background-color: #15E333;
}
.hide {
display: none;
}
/* Added */
.column:hover>button.hide {
display: inline-block;
}
.column:has(button:hover) p.description {
display: block;
}
<div class="container">
<div class="column">
<div style="padding-left: 15px;">
<h3>Services</h3>
<p class="description hide">Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit</p>
</div>
<img src="https://placehold.co/400x400.png" alt="Services" class="responsive" />
<button class="purple hide">Learn More ►</button>
</div>
<div class="column">
<div style="padding-left: 15px;">
<h3>Warehouse</h3>
<p>Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit</p>
</div>
<img src="https://placehold.co/400x400.png" alt="Warehouse" class="responsive" />
<button class="purple">Learn More ►</button>
</div>
<div class="column">
<div style="padding-left: 15px;">
<h3>IIOT</h3>
<p>Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit</p>
</div>
<img src="https://placehold.co/400x400.png" alt="IIOT" class="responsive" />
<button class="purple">Learn More ►</button>
</div>
</div>
請嘗嘗這個
body {
background-color: #10172b;
font-family: Poppins, Arial, "sans-serif";
color: #ffffff;
}
.container {
display: flex;
justify-content: space-between;
background: #10172b;
width: 1100px;
}
.widget-image {
padding-top:100px;
display: inline-block;
}
.column {
background-color: #f1f1f1;
transition: flex 0.5s;
cursor: pointer;
background: #293346;
margin-right: 20px;
flex-direction: column;
}
.column:hover {
flex: 0 0 550px;
transition: 1.5s;
}
.column:hover .widget-image {
padding: 0px;
margin: 0px;
}
.column:hover .learn-more-button {
margin: 0px;
}
.responsive {
max-width: 100%;
height: auto;
}
.learn-more-button {
background-color: #6d38f1;
color: #ffffff;
font-size: 16px;
padding: 10px 24px;
border: 0px;
box-shadow: 0px;
text-align: left;
}
.learn-more-button:hover {
background-color: #15E333;
}
.hide {
display: none;
}
/* Added */
.column:hover>button.hide {
display: inline-block;
}
.column:hover>p.hide {
display: inline-block;
}
.description {
width: 350px;
text-align: justify;
padding-right: 10px;
padding-left: 20px;
}
.column:hover .description {
display: block;
}
.heading-prix {
padding-left: 20px;
font-size: 28px;
font-family: Poppins, "sans-serif";
font-weight: 600;
}
<div class="container">
<div class="column">
<p class="heading-prix">Services</p>
<p class="description hide">Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit</p>
<img src="https://placehold.co/350x300.png" alt="Services" class="widget-image responsive" />
<button class="learn-more-button hide" style="align-items: flex-end;" >Learn More ►</button>
</div>
<div class="column">
<p class="heading-prix">Warehouse</p>
<p class="description hide">Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit</p>
<img src="https://placehold.co/350x300.png" alt="Warehouse" class="widget-image responsive" />
<button class="learn-more-button hide">Learn More ►</button>
</div>
<div class="column">
<p class="heading-prix">IIOT</p>
<p class="description hide">Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit</p>
<img src="https://placehold.co/350x300.png" alt="IIOT" class="widget-image responsive" />
<button class="learn-more-button hide">Learn More ►</button>
</div>
</div>
上一篇網格項目沒有跨越兩列
下一篇vue 路由設置標題