【发布时间】:2021-01-20 15:53:11
【问题描述】:
我试图通过添加一个矩形来制作一些动画效果,当按钮(不是矩形,因为它设置为width: 0px;)被用户悬停在按钮上时,该矩形在按钮上展开。不过,我真的不知道该怎么做,所以我被屏蔽了。
所以:
- 有一个按钮。
- 某处有一个矩形。
- 矩形宽度为 0px。
- 当按钮悬停时,我希望 矩形 的宽度从 0 增加到 200 像素。 不是按钮。
我接受 javascript 解决方案,但只喜欢真正的基本解决方案,因为我是初学者,如果不向我解释,我将无法理解 javascript。
目前,这是我的代码:
HTML:
<div class="flex-container">
<div class="sidebar">
<button style="margin-top: 100px;" onclick="Accueil()"><div style="z-index: 2;">Accueil</div></button>
<div class="rectangle" name="acc" style="top: 100px;"></div>
<button onclick="Thés()"><div style="z-index: 2;">Thés</div></button>
<div class="rectangle" name="the" style="top: 100px;"></div>
<button onclick="Tisanes()"><div style="z-index: 2;">Tisanes</div></button>
<div class="rectangle" name="tis" style="top: 100px;"></div>
<button onclick="Théières()"><div style="z-index: 2;">Théières</div></button>
<div class="rectangle" name="thei" style="top: 100px;"></div>
</div>
CSS:
.sidebar > button {
margin: 20px; /* marge de 30px entre les boutons */
width: 200px;
height: 60px;
max-height: 60px !important;
max-width: 200px !important;
background-color: #F5FAD2;
text-align: center;
font-size: 24px;
border-radius: 7%;
border: none;
transition-duration: 0.4s;
cursor: pointer;
color: #404040;
position: relative;
}
.rectangle {
width: 0px;
height: 60px;
color: rgba(255, 255, 255, 0.144);
border-radius: 7%;
border: none;
transition: width 1.1s ease 0s;
transition-timing-function: ease;
transition-delay: 0s;
position: absolute;
z-index: 1;
}
.rectangle button:hover {
width: 200px;
}
谢谢。
【问题讨论】:
标签: html css animation hover transition