html - CSS 在一行中获取 4 个列表项

标签 html css html-lists

我这里有这个页面 https://artendijen.com/product-category/medium/并且有 3 个无序列表,第一个列表有 2 个元素,第二个有 4 个元素,第三个有 1 个元素。我希望将第二个列表中的 4 个元素放在一行中,而不是 1 行中的 3 个元素和下一行中的 1 个元素。我不明白为什么会这样:

<ul class="products" style="text-align:center;">
<li id="124" class="post-124 product type-product status-publish hentry instock"></li>
<li id="121" class="post-121 product type-product status-publish hentry instock"></li>
<li id="125" class="post-125 product type-product status-publish hentry outofstock"></li>
<li id="122" class="post-122 product type-product status-publish hentry instock"></li>
</ul>

CSS:

.woocommerce .products ul, .woocommerce-page .products ul, .woocommerce ul.products, .woocommerce-page ul.products {
margin: 0 0 1em;
padding: 0;
list-style: none outside;
clear: both;
}

.woocommerce ul.products li.product, .woocommerce-page ul.products li.product {
float: left;
margin: 0 3.8% 2.992em 0;
padding: 0;
position: relative;
width: 22.05%;
margin-left: 0;
}

最佳答案

您也可以只更改图像的宽度:

宽度:21.05%;

这为边距留出了空间,但使四张图片保持在同一行。

关于html - CSS 在一行中获取 4 个列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20449826/

相关文章:

html - 为什么我的 IE6 条件样式表不工作?

html - 如何使用 CSS 显示空的 div 标签?

jquery - 在 ul 内的 ul 内选择 li

javascript - 将同级节点添加到嵌套列表

html - 如何用内部/外部 CSS 覆盖在线 CSS

html - 我可以让浏览器选择 UTF-8 来查看源代码吗?

html - 如何去除图像周围的边框?

jQuery 函数在运行前不等待整个页面加载

css - div 内 img+inline-block 的垂直对齐

html - 有序列表 - 双字母