【发布时间】:2019-11-11 23:47:33
【问题描述】:
我正在学习 HTML5、CSS3 和 Bootstrap4,并创建了一个虚拟项目。
我正在尝试创建一个将我的图标和文本(公司名称)并排放置的行,并使用display:inline 来实现相同的目的。这之后是一个标语行。
但是,我无法在中心获取整行的内容。我试过text-center 或text-xs-center 但无济于事。我什至创建了一个自定义 css 类
.text-center-custom{
text-align: center !important;
}
但这也没用。
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Project1</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Karla&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=B612:700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Frank+Ruhl+Libre&display=swap" rel="stylesheet">
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<div class="container">
<div class="row" id="topSection">
<div class="col-xs-12 text-center">
<img src="icons/icon.png" class="inline">
<h1 class="inline">Test Project</h1>
<br><br>
<h3>This is my first test project</h3>
<h3>BOOTSTRAP</h3>
<a href="" class="btn btn-danger">Sign-Up</a>
<br>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"></script>
</body>
</html>
main.css
#topSection{
background: url(images/background.jpg);
background-position: center;
background-size: 100%;
color: bisque;
}
.inline{
display: inline;
font-family: 'B612', sans-serif;
}
.text-center-custom{
text-align: center !important;
}
【问题讨论】:
-
尝试使用bootstrap的类...like试试这个
row d-flex justify-content-center您的代码中有一些更正。在 Bootstrap 4 中,col-xs已被删除。所以使用col-12而不是col-xs-12。我在下面做了一个工作的sn-p,请看一下
标签: html css bootstrap-4