簡體   English   中英

CSS Ordered Lists,有沒有一種方法可以設置數字背景的樣式?

[英]CSS Ordered Lists, is there a way to style the background of the number?

我正在設計1、2、3、4等的有序列表...

有沒有辦法在每個數字后面放置圖像,以便在其頂部顯示1、2、3、4?

例如:

image[1.] List Item 1

image[2.] List Item 2

image[3.] List Item 3

image[4.] List Item 4

是。 您可以使用ol .li:before將圖像移動到數字后面。 您還可以list-style-position: inside;使用list-style-position: inside; 將編號移到列表項本身的內部,然后在li元素上具有背景。

嗯,另一種方法是將圖像添加到每個列表項,然后移動其位置。 小提琴 我使用div而不是圖像,因為它更容易。 但是,應該在不同的瀏覽器上測試此方法,以確保它看起來不奇怪。

<ol>
    <li> 
        <div class="list-image"></div>
        foo
    </li>    
    <li>
        <div class="list-image"></div>
        bar 
    </li>
</ol>​

CSS:

ol{
   list-style-type:decimal;
   padding:50px 50px;
}

.list-image{
   width:20px;
   height:20px;
   position:relative;
   background-color:lightgray;
   top:20px;
   left:-25px;    
   z-index:-1;
}
​

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM