我正在尝试在内容的左侧和右侧均匀地留有空白空间。我尝试使用证明,但在不同长度的内容上却造成了问题。

问题:无论内容的长度如何,如何在内容的左右添加偶数的空白空间?我绝对需要在内容左侧添加15px填充。

看到代码:

<div class="pop">
    Over the weekend, I went to a sunset picnic on a rooftop in Brooklyn.
    The evening couldn’t have been more picturesque — a group of stylish women
    chatting and lounging on blankets, framed against a lavender and glittering
    cityscape.
</div>

<div class="pop">
    This is just one sentence as an example.
</div>


CSS:

.pop {
    border: 1px solid #999;
    margin-top: 10px;
    padding-left: 15px;
    padding-top: 10px;
    padding-bottom: 10px;
    text-align: justify;
    padding-right: 15px;
}


http://jsfiddle.net/dbGeX/

更新:

我希望内容看起来不居中,但看起来应该在左侧和右侧具有相等的填充量。所以左侧应该有padding-left:15px;并且右侧的内容应调整为具有与左侧相同的白色间距。我希望这更清楚。

最佳答案

您可以使用width:80%;(将80替换为所需的值),并结合min-width和max-width`属性来实现所需的效果,同时保持布局。

如果只希望内容居中且边框位于外部元素上,请参见此JSFIDDLE ONE

或者,如果您希望内容带有边框,请参见此JSFIDDLE TWO

希望这会有所帮助。

09-11 19:02
查看更多