【问题标题】:How to center images如何使图像居中
【发布时间】:2014-02-28 04:17:34
【问题描述】:

我已将页面正文放入容器中。然后我把我的图像放在一个 div 中,并给它们类“grid_12”和 id 'gallery'。这是我为那个 id 写的 CSS。

#gallery img{

border: 8px solid;
color: #0000FF;
margin: 0 0 20px 0;

}

我需要什么代码来使图像居中?我已经尝试过浮动中心/文本对齐中心,但没有成功。

【问题讨论】:

  • 您可以尝试margin: 0 auto; 并将内边距设置为 20px 而不是边距。

标签: image containers margin center


【解决方案1】:

使用这个:

img.center {
display: block;
margin-left: auto;
margin-right: auto;

}

来自here

【讨论】:

    【解决方案2】:

    首先您需要给出 div 的大小(宽度和高度),然后尝试您的 css 代码...

    【讨论】:

      猜你喜欢
      • 2016-04-23
      • 2021-03-25
      • 2020-11-04
      • 1970-01-01
      • 1970-01-01
      • 2015-04-04
      • 1970-01-01
      • 2017-05-27
      相关资源
      最近更新 更多