【发布时间】:2026-01-12 12:35:01
【问题描述】:
我正在使用flexbox 来控制按钮的 UI。
当我将Add new 部分悬停时,高度根本没有被完全覆盖。
但是当我将展开箭头悬停时它可以工作
在 App.js 中
return (
<div className="App">
<div className="media">
<div className="media__bar media__header">
<div className="media__header__add">
<div className="media__header__add__new">
<AddPhotoAlternateIcon fontSize="small" />
<span>Add new</span>
</div>
<button>
<ExpandMoreIcon style={{ color: "white" }} />
</button>
</div>
</div>
</div>
</div>
);
css
.App {
font-family: sans-serif;
text-align: center;
}
.media {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
}
.media .media__header {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
margin-top: 1rem;
padding-left: 1rem;
}
.media .media__header .media__header__add {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
color: white;
background-color: #c9356e;
padding: 0.1rem;
}
.media .media__header .media__header__add span {
font-size: 0.9rem;
}
.media .media__header .media__header__add button {
background-color: transparent;
border: none;
}
.media .media__header .media__header__add button:hover {
background-color: #ab235a;
}
.media .media__header .media__header__add .media__header__add__new {
padding-left: 0.5rem;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
.media .media__header .media__header__add .media__header__add__new:hover {
cursor: pointer;
background-color: #ab235a;
}
代码沙盒:
https://codesandbox.io/s/divine-pond-6zy5s?file=/src/styles.css
【问题讨论】:
-
这可能会有所帮助 - *.com/questions/32828249/…
标签: javascript html css reactjs flexbox