2015-11-12 180 views
0

我想創建一個左對齊的列表,但我希望塊在頁面中居中。
由於我沒有寬度,因爲在iPhone的Safari上觀看時尺寸不同,所以很難做到這一點,我不知道如何... 謝謝!文本左對齊但div中心

<center> 
<div style="width:;text-align:center;margin:0 auto 1em auto;border:1px solid white;padding:0cm 0.5cm 0cm 12%"> 
    <p style="text-align:left;"> 
    <b>1.</b> text one<br> 
     <font size="1"> &nbsp; &nbsp; small sub</font><br><br> 
    <b>2.</b> text two is longer because he think it's very cool to stand out but hey everything is alright<br><br> 
    <b>3.</b> three is a tree<br><br> 
    <b>4.</b> four means nothing<br><br> 
    <b>5.</b> short<br><br> 
     <center>fake center text with padding</center> 
    </p> 
</div><br><br> 
    real center text 
</center> 
+0

阻斷你到底要爲中心? –

+0

該div,但我放棄了。剛剛使用了另一種時間方法 – myspider

回答

0

既然你想打表,我會先用一堆破標籤使用ol tag(有序列表),而不是p標籤。然後,如果列表包含在一個div或block元素中(塊元素跨越窗口的整個寬度),可以通過給它一個寬度並在css中給它一個寬度來居中塊元素:0 auto; 。這意味着你要告訴計算機在左邊和右邊給它平等的利潤。確保給予你居中的元素寬度,否則margin:0 auto不起作用。

如果您不確定寬度,請決定您希望中心元素需要多少屏幕(即:50%,90%等)。希望有所幫助!

<div id="center"> 
<ol> 
    <li>text one</li> 
    <li>text two</li> 
    <li>three is a tree</li> 
    <li>four means nothing</li> 
    <li>short</li> 
</ol> 
</div> 

CSS

#centered{ 
    width: 50%; 
    margin: 0 auto; 
} 
+0

謝謝,但我必須改變一切,並編寫代碼以獲得數字大膽。現在我去了另一個選擇。 – myspider

0
<style>head,body{font-family:ubuntu,Arial,sans-serif;color:white;background-color:black} a{color:white;} 
.mobile{width:635px;margin:0 auto;text-align:left;padding:0.3cm 0cm 0.5cm 2%;} 
.mobiles{width:65%;text-align:center;margin:0 auto 1em auto;border:1px solid white;padding:0.1cm 0.3cm 0cm 3%;} 
@media only screen and (min-device-width:320px) and (max-device-width:568px) 
    {.mobile{width:100%;padding:0.5cm 0cm 0.5cm 2% 
    .mobiles{width:auto;text-align:center;margin:0 auto 1em auto;border:1px solid white;padding:0cm 0.5cm;} 
    ;}</style> 

<div class="mobiles"><p class="mobile">