如何去除文本区域的白色背景(Bootstrap 5环境)
解决Bootstrap 5中文本区域白色背景覆盖背景图的问题
问题原因
你遇到的白色背景并非来自<main>元素,而是Bootstrap默认给<body>标签设置了background-color: #fff;,这个白色背景会覆盖<html>上的背景图,导致你给.main设置background-color: transparent;没有效果。
解决方案
给<body>添加透明背景样式即可:
body { background-color: transparent; }
将这段代码加入你的CSS中,就能让<html>的背景图正常显示,同时文本区域保留在背景图上方。
完整修改后的CSS示例
* { padding: 0; margin: 0; font-family: "Roboto", sans-serif; } html { background: url(http://ndquiz.epizy.com/img/worldPersonalProject.png) no-repeat center fixed; background-size: cover; } /* 添加该行解决白色背景问题 */ body { background-color: transparent; } .btn-select { background-color: #008cba; border-radius: 10px; text-align: center; } .main { margin-top: 100px; background-color: transparent !important; } .big { font-size: 60px; }
内容的提问来源于stack exchange,提问作者nd03
相关产品推荐
相关产品推荐

