html - 如果我在按钮中有一个图像,并且按钮的宽度在悬停时增加,我如何将图像的位置固定在最初的位置?
问题描述
当我将鼠标悬停在按钮上时,它会根据需要改变宽度,但是图像会向中心移动。我想把它固定在左边,这样当按钮的宽度改变时它就不会移动。这是我的代码。我正在使用 React 构建:
<div>
<button
className={
this.state.activecut === true
? "designstudiobuttonleftopactive"
: "designstudiobuttonlefttop"
}
onClick={this.cutActiveHandler}
>
<img src={shirtlogo} id="cutlogo" alt="" />
</button>
</div>
.designstudiobuttonlefttop {
width: 60px;
height: 60px;
margin-top: 150px;
display: block;
border: 1px solid #574904;
border-radius: 50%;
background-color: white;
color: #574904;
text-align: center;
margin-left: 50px;
}
.designstudiobuttonlefttop:hover {
background-color: #f2f2f2;
color: #574904 !important;
text-decoration: underline;
transition-delay: 100ms !important;
cursor: pointer !important;
width: 200px;
border-radius: 50px 50px 50px 50px;
}
#cutlogo {
width: 50px;
height: 50px;
padding-right: 5px;
}
.designstudiobuttonleftopactive {
color: #574904 !important;
border: none;
background-color: white;
text-align: center;
text-decoration: underline;
cursor: pointer;
margin-top: 100px;
display: block;
margin-left: 50px;
}
解决方案
用于float: left
将其保留在按钮的左侧。
.designstudiobuttonlefttop {
width: 60px;
height: 60px;
margin-top: 150px;
display: block;
border: 1px solid #574904;
border-radius: 50%;
background-color: white;
color: #574904;
text-align: center;
margin-left: 50px;
}
.designstudiobuttonlefttop:hover {
background-color: #f2f2f2;
color: #574904 !important;
text-decoration: underline;
transition-delay: 100ms !important;
cursor: pointer !important;
width: 200px;
border-radius: 50px 50px 50px 50px;
}
#cutlogo {
width: 50px;
height: 50px;
padding-right: 5px;
}
.designstudiobuttonleftopactive {
color: #574904 !important;
border: none;
background-color: white;
text-align: center;
text-decoration: underline;
cursor: pointer;
margin-top: 100px;
display: block;
margin-left: 50px;
}
<div>
<button
class="designstudiobuttonlefttop"
onClick={this.cutActiveHandler}
>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT6vxI3cA6w8ocAr3KWNHdMmq5gkkhYSuacNYaFCrQxZmeBUo2m" id="cutlogo" alt="" width="40" height="40" style="float: left;"/>
</button>
</div>
推荐阅读
- connection - Nestjs - Typeorm 自定义连接名称
- r - 如何在 shinydahsboardPlus 中更改用户图片?
- sql - 选择在多个地方有孩子的父母
- c - 将结构中的 void 指针转换为结构以访问成员
- python - 如何访问字典内的列表索引
- java - 为什么我在打开玩家库存时收到错误消息?
- flutter - 如何使用 video_player 插件在 Flutter Web 上播放 .m3u8 文件?
- curl - 使用 curl 将 Zip 文件上传到 Private Nexus Repo
- javascript - Formik/yup 验证不会触发错误消息
- java - Hybris 18.11 与 GSON 和 Stripe 冲突