请参考下面我尝试过的代码
<div class="row">
<div class="center-block">First Div</div>
<div class="center-block">Second DIV </div>
</div>
输出:
First Div
SecondDiv
预期输出:
First Div Second Div
我想使用bootstrap css将两个div水平居中对齐到页面。我该怎么做呢?我不想使用简单的css和浮动概念来做这件事。因为我需要使用bootstrap css来处理所有类型的布局(即所有窗口大小和分辨率),而不是使用媒体查询。
发布于 2020-11-15 13:54:06
Make sure you wrap your "row" inside the class "container" . Also add reference to bootstrap in your html.
Something like this should work:
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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">
</head>
<body>
<p>lets learn!</p>
<div class="container">
<div class="row">
<div class="col-lg-6" style="background-color: red;">
ONE
</div>
<div class="col-lg-2" style="background-color: blue;">
TWO
</div>
<div class="col-lg-4" style="background-color: green;">
THREE
</div>
</div>
</div>
</body>
</html>
https://stackoverflow.com/questions/22150006
复制相似问题