我已经将内部的div
设置为style=“margin:auto;”
,但主页图标没有居中。
null
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
color: white;
background-color: #1E1B1B;
border-color: grey;
}
.nav-col {
background-color: transparent;
margin: 10px;
padding: 10px;
font-size: 30px;
border: 1px solid grey;
height: 700px;
width: 150px;
}
</style>
</head>
<body>
<div class="nav-col">
<div style="margin:auto;"><i class="fa fa-home"></i></div>
</div>
</body>
</html>
null
这就是我所看到的:
如果确实要使用margin:auto;
,则需要设置宽度。宽度:min-content;
应该足够了。
null
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
color: white;
background-color: #1E1B1B;
border-color: grey;
}
.nav-col {
background-color: transparent;
margin: 10px;
padding: 10px;
font-size: 30px;
border: 1px solid grey;
height: 700px;
width: 150px;
}
</style>
</head>
<body>
<div class="nav-col">
<div style="margin:auto; width: min-content;"><i class="fa fa-home"></i></div>
</div>
</body>
</html>