如何使<li>项目彼此相邻?

时间:2015-07-23 21:27:06

标签: html css

几个小时以来,我一直试图将li列表放在一起,但仍然无法实现。

JsFiddle:https://jsfiddle.net/rsp3gsg3/

body {
    background-image: url("http://images.virtualworldsland.com/blog/2322/796.jpg");
    background-attachment: fixed;
}
img {
    box-shadow: 0px 3px 12px 2px #000;
    -webkit-transition: all 0.5s ease-out;
    -moz-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
}
img:hover {
    -webkit-transform: rotate(-7deg);
    -moz-transform: rotate(-7deg);
    -o-transform: rotate(-7deg);
}
#menu {
    width: 200px;
    height: 200px;
    background: white;
    box-shadow: 0px 3px 12px 2px #000;
}
.ulinlineblock {
    display: inline-block;
    list-style-type: none;
}
<div align="center">
    <img src="Header.png" />
    <div id="menu">
        <ul class="ulinlineblock">
            <li>Home</li>
            <li>Blog</li>
            <li>Wiki</li>
            <li>Trivia</li>
        </ul>
    </div>
</div>

1 个答案:

答案 0 :(得分:3)

您应该将li设置为内嵌块。

.ulinlineblock {
    text-align: center;
    list-style: none;
    padding: 0;
}
.ulinlineblock li {
    display: inline-block;
    vertical-align: top;
}

https://jsfiddle.net/rsp3gsg3/4/

body {
    background-image: url("http://images.virtualworldsland.com/blog/2322/796.jpg");
    background-attachment: fixed;
}
img {
    box-shadow: 0px 3px 12px 2px #000;
    -webkit-transition: all 0.5s ease-out;
    -moz-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
}
img:hover {
    -webkit-transform: rotate(-7deg);
    -moz-transform: rotate(-7deg);
    -o-transform: rotate(-7deg);
}
#menu {
    width: 200px;
    height: 200px;
    background: white;
    box-shadow: 0px 3px 12px 2px #000;
}
.ulinlineblock {
    text-align: center;
    list-style: none;
    padding: 0;
}
.ulinlineblock li {
    display: inline-block;
    vertical-align: top;
}
<div align="center">
    <img src="Header.png" />
    <div id="menu">
        <ul class="ulinlineblock">
            <li>Home</li>
            <li>Blog</li>
            <li>Wiki</li>
            <li>Trivia</li>
        </ul>
    </div>
</div>