gpt4 book ai didi

jquery - 为什么
即使是 "text-align:center"也不居中?

转载 作者:行者123 更新时间:2023-11-28 15:11:28 25 4
gpt4 key购买 nike

看看这段代码。我是编码新手,所以我可能犯了一些错误,所以我在这里寻求帮助。我不明白如何将“#input-group”div 放在页面中间:它应该居中,因为它属于已经设置为“text-align:center”但不起作用的超大屏幕。知道为什么吗?

非常感谢!

<html lang="en">

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<title>Bootstrap project</title>

<style type="text/css">

body {
position:relative;
}

.jumbotron {

height:500px;
text-align:center;
background-image: url(photo-1439209306665-700c9bca794c.jpg)

}

#title {
margin-top:70px;
}

hr {
border-top: 1px solid grey;
margin-top: 20px;

}

#subtitle {
font-size: 100%;
font-weight: bold;
margin-top:50px;
}

.input-group {

width:300px;



}




</style>

</head>

<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">MyApp</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Download</a></li>
</ul>
<form class="navbar-form navbar-right" action="/action_page.php">
<div class="form-group">
<input type="email" class="form-control" placeholder="Email" name="email">
<input type="password" class="form-control" placeholder="Password" name="password">
</div>
<button type="submit" class="btn btn-primary">Login</button>
</form>
</div>
</nav>

<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-4" id="title">My Awesome App!</h1>
<p class="lead">This is why YOU should download this fantastic app!</p>
<hr>
<p id="subtitle">Want to know more? Join our mailing list!</p>

<div class="input-group">
<span class="input-group-addon" id="basic-addon1">@</span>
<input type="email" class="form-control" placeholder="Username" aria-describedby="basic-addon1">
</div>
</div>
</div>
</body>

</html>

最佳答案

text align 仅对齐 div 内的文本。您需要将 margin left 和 right 设置为 auto。请注意,如果 div 上设置了 float ,这将不起作用。

       .input-group {
margin-left:auto;
margin-right:auto;
width:300px;
}

关于jquery - 为什么 <div> 即使是 "text-align:center"也不居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48309168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com