html - 可以将html列表项(li)设置为显示:网格吗?
问题描述
例如,我正在尝试使用以下代码创建一个具有 4 个均匀分布的链接的页脚
footer{
margin-top: 20px;
border-top: 1px solid #eeeeee;
border-radius: 2px;
}
#footer_list{
display:inline-grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
list-style-type: none;
}
.footer_list_item{
color: #001f3f !important;
}
<footer>
<ul id="footer_list">
<li class="footer_list_item">A Blah Blah Production</li>
<li class="footer_list_item">Phone: xxx-xxx-xxxx</li>
<li class="footer_list_item">Email: support@company.com</li>
<li class="footer_list_item" href="#">Career Info</li>
</ul>
</footer>
http://jsfiddle.net/vq9b7c0e/3/
设置alist
无效display:grid
吗?因为所有的项目似乎都是随机间隔的
解决方案
将 HTML 元素设置为display: grid
(或inline-grid
) 是完全有效的。
根据 W3C 定义,该display
属性适用于所有元素。
display
但是,某些元素在属性更改后无法在某些浏览器中正常播放。请参阅这篇文章(适用于 flex 和 grid):Flexbox not working on button or fieldset elements
你写了:
将列表设置为
display: grid
无效吗?因为所有的项目似乎是随机间隔的。
您的物品不是随机分布的。网格有四个等宽的列,就像您指定的那样:
你的代码:
#footer_list{
display: inline-grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
}
您的布局(如 Chrome、Firefox 和 Edge 中所示):
所以我不确定你的意思。但这是您的代码的简化版本。既然您已经在使用footer
提供有意义语义的 HTML5 元素,为什么要使用ul
?
footer {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-template-rows: 40px;
grid-column-gap: 5px;
}
a {
color: #001f3f !important;
text-decoration: none;
border: 1px solid lightgray;
background-color: lightgreen;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
font-size: .9em;
}
<footer>
<a href="#">A Blah Blah Production</a>
<a href="#">Phone: xxx-xxx-xxxx</a>
<a href="#">Email: support@company.com</a>
<a href="#">Career Info</a>
</footer>
jsFiddle 演示
推荐阅读
- eclipse - 如何获取 Eclipse 无头构建的工具 ID
- python - 为什么 numpy 超越数对大于 2^64-1 的整数参数给出“无属性”错误?
- python-3.x - 转向卷积层的零填充输入问题
- c++11 - 何时使用完美转发,何时明确?
- android - Android App Project 停止编译,grade.build 出错
- angularjs - 使用angularjs提供日期时获取一个月的所有日期
- android - Google Maps API 安装警告
- typescript - 如何迭代泛型类型的属性?
- c# - 在 Service Fabric 应用程序中禁用 TLS 握手客户端证书请求
- r - 保留类但不在 R 函数的输出中显示它