2012-07-05 119 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