css - 将文本 block 与左右边距对齐

标签 css

我有一段文字。我想在左侧放置 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>

最佳答案

我认为您可能希望在此处进行填充而不是边距。

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

关于css - 将文本 block 与左右边距对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11353106/

相关文章:

css - 在 Less 中使用未知值作为选择器

html - 使html的一部分可滚动

css - .less 文件中的 Angular 4 导入不会在更改时更新

html - 你可以在 ul 列表中跳过一行吗?

javascript - 为什么这张...div 画的左上角有方形聚集

html - float div 未按预期在 IE 中清除

css - HTML/CSS 中的垂直对齐 Div

html - 如何使用CSS更改iframe src

html - 映射元素的 Css 问题

html - 垂直对齐表格单元格中的视频