html - 尝试使用 CSS 和弹性框将段落移动到按钮下的下一行
问题描述
我在玩按钮和 css,我想知道是否有一种方法可以让这一段说 (Hover Me) 使用 flexbox 进入按钮下方。抱歉,如果这有点太模糊或者我发布了错误的代码,这是我的第一次。对未来的任何指示或提示表示赞赏。谢谢。
/*Makes the background */
#background {
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
z-index: -1;
}
/* Makes the background black when the button is hovered */
#button:hover~#background {
background-color: black;
}
/* Centers the button and the paragraph */
section {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
button {
display: flex;
align-items: center;
justify-content: center;
height: 80px;
width: 40px;
border: 1px solid royalblue;
background-color: skyblue;
transition: 1s;
border-radius: 10px;
margin-right: 15px;
}
button:hover {
background-color: indigo;
color: white;
box-shadow: 3px -4px 10px GREY;
transform: translateY(0.25em);
}
<section>
<button id="button">Lights
<br>Off!</br>
</button>
<p>(Hover Me)</p>
<div id="background"></div>
</section>
解决方案
尝试flex-direction: column;
在部分添加
/*Makes the background */
#background {
position:absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
z-index: -1;
}
/* Makes the background black when the button is hovered */
#button:hover ~ #background {
background-color: black;
}
/* Centers the button and the paragraph */
section {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
button {
display: flex;
align-items: center;
justify-content: center;
height:80px;
width: 40px;
border: 1px solid royalblue;
background-color: skyblue;
transition: 1s;
border-radius: 10px;
margin-right: 15px;
}
button:hover {
background-color: indigo;
color: white;
box-shadow: 3px -4px 10px GREY;
transform: translateY(0.25em);
}
<section>
<button id="button">Lights
<br>Off!</br>
</button>
<p>(Hover Me)</p>
<div id="background"></div>
</section>
推荐阅读
- asp.net - 如何将多个参数从表单传递到 Asp.net MVC 核心中的控制器?
- azure-data-factory - Azure 数据工厂 WebHook 在 1 分钟后失败
- python - 运行 selenium 后如何从 twitter 检索数据
- reinforcement-learning - TRPO - RL:我需要让一个 8DOF 机械臂移动到指定点。我需要在 Gazebo 环境中使用 OpenAI gym 来实现 TRPO RL 代码吗?
- mediawiki - 我如何上传图像并同时向它们添加货物元数据?
- javascript - Formik FieldArray 使用 Yup 进行嵌套对象验证
- javascript - 在具有角度的第二个自然获取浏览器中设置自定义标题
- graph - 图形 API 创建新组和团队 - 图形资源管理器中的“请求中的无效绑定属性名称成员”问题
- node.js - MongoDB 投影参数在 findOne() 中不起作用
- perl - Perl Net::SMTP 在调用 auth() 时/之前突然断开连接