简体   繁体   English

尝试使用 CSS 和弹性框将段落移动到按钮下的下一行

[英]Trying to move a paragraph to the next line under a button using CSS and flex box

Im playing around with buttons and css and I'm wondering if there is a way I can get this paragraph that says (Hover Me) to go under the button using flexbox.我在玩按钮和 css,我想知道是否有办法让这一段说(悬停我)使用 flexbox 进入按钮下方。 Sorry if that's a little too vague or I posted the code wrong, this is my first time.对不起,如果这有点太模糊或者我发布了错误的代码,这是我第一次。 Any pointers or tips for the future are appreciated.对未来的任何指示或提示表示赞赏。 Thanks.谢谢。

 /*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>

Try to add flex-direction: column;尝试添加flex-direction: column; in section在节

 /*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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM