<li>在页面中心

时间:2015-04-25 21:48:12

标签: html css

我有这个HTML代码:

<div id="site">
<ul>
<li><a href="http://roblox.com/Orinthian-Soldier-item?id=111514918&rbxp=61629949">Orinthian Soldier</a></li>
<li><a href="http://roblox.com/Sk8r-Boi-item?id=16101707&rbxp=61629949">Sk8r Boi</a></li>
<li><a href="http://roblox.com/Tokyokhaos-Super-Happy-Fun-Monkey-Companion-item?id=15857967&rbxp=61629949">Tokyokhaos Super Happy Fun Monkey Companion</a></li>
<li><a href="http://web.roblox.com/Dangerface-item?id=44561190&rbxp=61629949">Dangerface</a></li>
<li><a href="http://web.roblox.com/Captain-of-the-Pikemen-item?id=52556526&rbxp=61629949">Captain of the Pikemen</a></li>
</ul>
</div>

这是我的CSS:

#site {
 background: #fff;
 max-width: 1075px;
 margin-left: 120px;
 margin-right: 120px;
 box-shadow: 0px 0px 15px 0px #000;
 padding: 2px;
 -moz-box-shadow: 0 0 15px 0px #000;
 -webkit-box-shadow: 0 0 15px 0px #000;
}

#site p {
 text-align: left;
 margin-right: 30px;
 margin-left: 30px;
}

#site h1 {
 text-align: center;
}

#site h2 {
 text-align: left;
 margin-right: 30px;
 margin-left: 30px;
}

#site h3 {
 margin-right: 30px;
 margin-left: 30px;
 text-align: left;
}

问题是<li>标签中的文字位于页面的中心;我该如何解决这个问题? http://prntscr.com/6y5c3j

非常感谢。

2 个答案:

答案 0 :(得分:1)

我已经测试了您的代码,代码中没有任何错误。 http://tinypic.com/r/4uyvwk/8

也许中心<li>标签是因为你的其他CSS?

答案 1 :(得分:1)

我在三个主流浏览器中尝试了您的代码,列表项目都在左侧正确显示,而不是中心。尝试在CSS文件的开头使用CSS重置。这可以解决问题。以下是Eric Myers提供的。这里是链接以供参考 CSS Reset

  /* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}