html - 无法将我的 div 放在页面中央

标签 html css

我有一个 div,我在 div 中放置了一张图片。我试图将该 div 定位在页面的中心,但我做不到。请帮我。谢谢 !

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <style>
        .bannerimage {
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <div class="bannerimage">
        <img src="images/mailer2.jpg">
    </div>
</body>

最佳答案

您可以为您的 bannerimage 类使用 display:flex 来轻松地将其居中。希望这有帮助

.bannerimage {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  height: -webkit-fill-available;
}

关于html - 无法将我的 div 放在页面中央,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56592142/

相关文章:

jquery - 如何更改文本区域中的单个字符颜色

php - 属性 &lt;input type ="email"> 在 HTML5 中未正确验证

jquery - CSS 链接在点击时不起作用

html - 固定位置菜单下带背景色的 anchor

html - Twitter Bootstrap : pull-right class only working in Firefox for input-group

html - 通过 css 调整图像大小

javascript - 如何在canvas html5中使用图像填充样式

javascript - 显示其下方文本框的值

php - Wordpress 背景不会从颜色变为平铺图像?

jquery - 当url有一些id时如何设置div显示属性 block ?