html - 宽度不会从 Div 中删除
问题描述
我正在尝试创建按钮,并且我有一个父 div 将所有其他 div 放在一起。但是,与父 div 的东西,它正在创建自己的宽度,它不会在其他 div 周围创建自动宽度。
我只想将所有按钮/div 完美居中,而父 div 的宽度阻止了我。
任何帮助都会很棒,谢谢!!
<style>
h1.helph1 {
text-align: center;
font-family: Montserrat, sans-serif;
font-weight: 100;
padding-bottom: 40px;
padding-top: 20px;
border-bottom: #e3e3e3 solid 1px;
}
.toplinks div, .middlelinks div, .bottomlinks div {
float: left;
width: 250px !important;
}
.helpparent .toplinks div, .middlelinks div, .bottomlinks div{
background: #2fb796;
padding: 10px;
margin: 10px;
color: white;
font-family: Montserrat;
text-align: center;
}
.helpparent {
width: 66.1%;
margin: 0 auto;
}
</style>
<html>
<h1 class="helph1">Forum Help Center</h1>
<div class="helpparent">
<div class="toplinks">
<a href="https://www.youtube.com/"><div class="announcementhelp">Announcements</div></a>
<a href="https://www.youtube.com/"><div class="gettingstartedhelp">Getting Started</div></a>
<a href="https://www.youtube.com/"><div class="gasrhelp">GASR 101</div></a>
</div>
<div class="seperator" style="clear:both;"></div>
<div class="middlelinks">
<a href="https://www.youtube.com/"><div class="forumshophelp">Forums and Shops</div></a>
<a href="https://www.youtube.com/"><div class="rulesdmcahelp">Community & DMCA Guidelines</div></a>
<a href="https://www.youtube.com/"><div class="sandrhelp">Support & Report System</div></a>
</div>
<div class="seperator" style="clear:both;"></div>
<div class="bottomlinks">
<a href="https://www.youtube.com/"><div class="eventhelp">Forum Events</div></a>
<a href="https://www.youtube.com/"><div class="storehelp">GASR Store</div></a>
<a href="https://www.youtube.com/"><div class="profilehelp">Your Profile & Settings</div></a>
</div>
<div class="seperator" style="clear:both;"></div>
</div>
</html>
解决方案
您可以摆脱.help-parent
类的宽度并添加display: flex;
flex-direction: column;
align-items: center;
到中心的 div。但是,您必须删除float
on.toplinks div, .middlelinks div, .bottomlinks div
才能使其正常工作。同样由于删除float
,text-decoration
链接上的 似乎又回来了,所以我添加text-decoration: none;
到您的<a>
标签中。
<style>h1.helph1 {
text-align: center;
font-family: Montserrat, sans-serif;
font-weight: 100;
padding-bottom: 40px;
padding-top: 20px;
border-bottom: #e3e3e3 solid 1px;
}
.toplinks div,
.middlelinks div,
.bottomlinks div {
width: 250px !important;
}
a {
text-decoration: none;
}
.helpparent .toplinks div,
.middlelinks div,
.bottomlinks div {
background: #2fb796;
padding: 10px;
margin: 10px;
color: white;
font-family: Montserrat;
text-align: center;
}
.helpparent {
display: flex;
flex-direction: column;
align-items: center;
}
</style>
<html>
<h1 class="helph1">GASR Help Center</h1>
<div class="helpparent">
<div class="toplinks">
<a href="https://www.youtube.com/">
<div class="announcementhelp">Announcements</div>
</a>
<a href="https://www.youtube.com/">
<div class="gettingstartedhelp">Getting Started</div>
</a>
<a href="https://www.youtube.com/">
<div class="gasrhelp">GASR 101</div>
</a>
</div>
<div class="seperator" style="clear:both;"></div>
<div class="middlelinks">
<a href="https://www.youtube.com/">
<div class="forumshophelp">Forums and Shops</div>
</a>
<a href="https://www.youtube.com/">
<div class="rulesdmcahelp">Community & DMCA Guidelines</div>
</a>
<a href="https://www.youtube.com/">
<div class="sandrhelp">Support & Report System</div>
</a>
</div>
<div class="seperator" style="clear:both;"></div>
<div class="bottomlinks">
<a href="https://www.youtube.com/">
<div class="eventhelp">Forum Events</div>
</a>
<a href="https://www.youtube.com/">
<div class="storehelp">GASR Store</div>
</a>
<a href="https://www.youtube.com/">
<div class="profilehelp">Your Profile & Settings</div>
</a>
</div>
<div class="seperator" style="clear:both;"></div>
</div>
</html>
推荐阅读
- wpf - 如何在运行时在 Prism 中注入新实例?
- java - 构造函数 (java.awt.Polygon) 未定义
- angular - 如何在 Angular 中包含库项目
- c++ - 尽管其他 find 语句有效,但没有对 std::find() 的匹配调用,并且包括
- regex - vim-highlight:无法匹配正则表达式lookbehind
- youtube-api - YouTube 数据 API v3,403 使用限制访问未配置
- python - 服务帐户拒绝 Firestore
- django - 将 __init__ 用于动态 Radio 字段时,我的 Django 表单未验证
- php - 在 PHP Zkteco 中的 CardNo 更新后插入不起作用
- java - 如何匹配`<`和`>`之间的所有字符,除了`/`?