正如您在代碼中看到的,我正在嘗試將項目符號與文本對齊,而不是文本與文本對齊。CSS中的「ul」元素和「p」元素之間的匹配縮進
<html>
<head>
<style type="text/css">
body
{
width: 6.5in;
padding-left: 1in;
padding-right: 1in;
}
.indent
{
padding-left: 50px;
}
</style>
<head>
<body>
<p class="indent">As You can see, the indents match</p>
<ul class="indent">
<li>Unfortunately, this only works for for the text, not the bullets</li>
<li>Of course, this isn't necessarily bad since this may be what somebody wants out of their indents and it is the default behavior</li>
<li>Obviously, this isn't what I want, or else I wouldn't be posting to SO</li>
<li>You've probably already figured this out by now, but I'll say it anyway: I'm trying to get the bullet of the unordered list element to match the alignment of the paragraph, not just the text</li>
<li>If it still doesn't make sense, copy & paste this code, view it in your favorite browser and then compare it to how the indents work in LibreOffice (I'm pretty sure MS Word works the same way as LO with indents & bullets; Google Docs works more like the default behavior)</li>
</ul>
</body>
</html>
當然,人們可以總是「眼球」,或在視覺上估計,它通過創建「UL」元件一個單獨的類和改變「填充左」的值,然後比較中的結果5個主要的瀏覽器,但我想找到一種方法來使用比人眼更精確的語言機制。
如果'list-style-position'是'inside',則不必做任何事情。有了'list-style-position:outside',雖然,我不確定... – BoltClock
嗯,有趣的建議。我在JSFiddle上回顧了freezethrower的解決方案(下面),它主要滿足所期望的意圖,只是它很醜陋,至少在列表是多行的時候。只是我的意見,沒有更多;我並不是不信任你們兩個,因爲解決方案肯定會起作用,我只是一個挑剔的人^^; – Stisfa