【发布时间】:2019-12-14 16:20:13
【问题描述】:
我需要将一个 img 居中(带有 class=“key”的那个,但浮动元素会阻止它。 我应该使用什么技术来居中?
谢谢!
GitHub 仓库:https://github.com/CalogerN/beta-sign-up-split-layout
实时预览:https://calogern.github.io/beta-sign-up-split-layout/
body {
margin: 0px;
padding: 0px;
font-size: 16px;
}
header {
background-image: url(../img/bg-intro.svg);
background-size: cover;
background-position: center;
background-repeat: no-repeat;
height: 643px;
}
.logo {
float: left;
}
.wlogo {
fill: white;
}
.key {
height: 234px;
position: relative;
top: 200px;
}
.key-wrapper {
display: block;
margin: auto;
}
<section class="section-a">
<header>
<svg width="120" height="35" class="logo" *numbers* </svg>
<div class="key-wrapper">
<img src="img/illustration-main.svg" alt="a man with a key" class="key">
</div>
</header>
【问题讨论】:
-
header {text-align:center;} 试试这段代码
-
也不行。
-
svg {margin:0 auto;} 试试这个