2012-07-05 121 views
0

我有一段文字。我想在左側留出20%的餘量,並在右側留出30%的餘量。我如何使用CSS實現這一目標?用左右邊距對齊文本塊

下面是我的代碼:

.style4 { 
    float: left; 
    margin-left: 20%; 
    background-color: #e5e0dd; 
    width: 68.1%; 
    margin-right: 30%; 
    border-left:30%; 

    text-align: center; 
    font-family: Calibri; 
    font-size: small; 
} 

<div class="style4"> 
    This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test.This is a test. 
</div> 
+0

您已經擁有'margin-left:20%'和'margin-right:30%'。什麼不適合你的? – 2012-07-05 21:58:32

+0

此文本位於塊的頂部,該邊距爲20%,30%爲該塊。該區塊剩餘20%剩餘和30%右邊距。該塊上的文本不顯示該邊距。 – 2012-07-05 22:00:18

回答

1

我想你可能會希望做填充,而不是利潤率在這裏。

padding-left: 20%; padding-right: 30%; 
+1

謝謝!填充左側和填充右側工作正常! – 2012-07-06 14:35:51