html - 我将如何实现这种 CSS 效果(居中内容和填充)?

标签 html css

enter image description here

我想知道如何实现这种效果。首先,内容当前位于名为“contentDiv”的 div 中。我有以下所有内容 float:right of the div。我想要实现的是内容无法跨越的假想边界(查看图片)。 然后我希望内容居中。 我将如何使用 CSS 实现这一目标?或者我可以使用哪些元素来复制这种效果。 我已经研究过将内容居中,这段代码对我有用 -

margin-left: auto;
margin-right: auto;

最佳答案

#contentDivParent {
    /*It will define the imaginary border*/
    padding-left:30%;
    width:70%;
}

#contentDiv {
  /*remove the float*/
  float:none;
  /*center*/
  margin:0px auto;
  /*force line-break*/
  max-width:100%;
}

关于html - 我将如何实现这种 CSS 效果(居中内容和填充)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7411390/

相关文章:

javascript - 动态分配 img'src

javascript - 帮助用 javascript 和 jQuery 技能打动面试官

javascript - 将带有字符串的换行符存储在变量中

javascript - 克服 !important 标签,使对话框可定位

javascript - 如何渲染对象而不混合 webgl 中启用的透明度

html - CSS div 在另一个 div 中的位置

html - Angular <ng-content> 和 Shadow DOM 之间有什么关系

html - Div 仅在调试面板中选择元素时才可滚动

html - 如何对齐下拉列表中两个单词之间的缩进空间?

css - 带有列的表格和表格全长的 div