html - 当元素具有不同宽度时,中间 li 元素直接居中

标签 html css

我有一个无序列表,中心列表项中有一个 Logo 图像。 Logo 两侧的每个列表项都具有不同的宽度。

ul 为 100%,应用了居中对齐。

我正在尝试找到一种方法,使 Logo li 完美地位于页面的中央,最好只使用 CSS。

有人知道如何实现吗?

<ul>
    <li>Dummy</li>
    <li>Dummy</li>
    <li>Dummy</li>
    <li><img src="logo.jpg" />
    <li>Dummy</li>
    <li>Dummy</li>
    <li>Dummy</li>  
</ul>

这将是它的输出方式:

enter image description here

最佳答案

这其实并不难。看一下 CSS:

ul {
    width: 100%;
    list-style-type: none;
    margin: 0;
    padding: 0;
}
li {
    float: left;
    width: 14.285714286%;
    line-height: 150px;
    text-align: center;
    margin: 0;
    padding: 0;
}

这是指向 codepen 的链接.

关于html - 当元素具有不同宽度时,中间 li 元素直接居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31850340/

相关文章:

xhtml - &lt;script&gt; 标签不能自闭吗?

javascript - 如何规范跨浏览器的 CSS3 过渡结束事件?

html - 在 CSS 中设置最大字符长度

CSS :before and :first-child combined

html - 如何更改颜色 Bootstrap 的仅选择标签箭头或文本?

html - 响应式图片库

javascript - 如何在 Phantomjs 中使用 jQuery 选择 html 元素?

php - 如何获取数据库中存储的较大时间来扣除较小时间

css - 如何在 HTML 中的图像标签中包含一个分区?

html - 默认 CSS 覆盖 HTML 中应用的样式