#html #css #bootstrap-5
Вопрос:
В Bootstrap5 я хочу добиться (в основном) того же эффекта, что и:
margin: 0 auto;
width:60%;
в CSS. Приведенный выше код не работает в начальной загрузке — он выравнивает элементы слева от страницы.
Как ограничить ширину до середины 60%, а затем сделать так, чтобы содержимое занимало эти 60% в 2 столбцах?
Редактировать: HTML-код (style.css содержит только выравнивание текста и цвета):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-KyZXEAg3QhqLMpG8r 8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
<title>Bootstrap</title>
</head>
<body>
<div class="container-fluid">
<header class="row">
<div class="col-12" id="header_id"></div> <!--header_id is just for a background image-->
</header>
<section class="row">
<article class="col-4">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Voluptates animi ratione esse, aut
vel iusto voluptas voluptatum illo suscipit veniam, laudantium qui, quidem nihil eaque repellendus
ducimus facilis velit sequi.</article>
<article class="col-4">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Voluptates animi ratione esse, aut
vel iusto voluptas voluptatum illo suscipit veniam, laudantium qui, quidem nihil eaque repellendus
ducimus facilis velit sequi.</article>
<article class="col-4">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Voluptates animi ratione esse, aut
vel iusto voluptas voluptatum illo suscipit veniam, laudantium qui, quidem nihil eaque repellendus
ducimus facilis velit sequi.</article>
<article class="col-4">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Voluptates animi ratione esse, aut
vel iusto voluptas voluptatum illo suscipit veniam, laudantium qui, quidem nihil eaque repellendus
ducimus facilis velit sequi.</article>
<article class="col-4">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Voluptates animi ratione esse, aut
vel iusto voluptas voluptatum illo suscipit veniam, laudantium qui, quidem nihil eaque repellendus
ducimus facilis velit sequi.</article>
</section>
<footer class="row">
<div class="col-12 align-center static-bottom">LICENCE</div> <!-- align-center is just for aligning text -->
</footer>
</div>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"
integrity="sha384-eMNCOe7tC1doHpGoWe/6oMVemdAVTMs2xqW4mwXrXsW0L84Iytr2wi5v2QjrP/xp"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.min.js"
integrity="sha384-cn7l7gDp0eyniUwwAZgrzD06kc/tftFf19TOAs2zVinnD/C7E91j9yyk5//jjpt/"
crossorigin="anonymous"></script>
</body>
</html>
Комментарии:
1. Пожалуйста, включите HTML-код, чтобы повторить проблему
Ответ №1:
Я предполагаю, что вы пробовали автокласс.
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u LWgxfKTRIcfu0JTxR EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
<div class="col-md-auto mb-4 text-center">
<div class="card bg-light mb-3 shadow-sm h-100 mx-auto" style="max-width: 18rem;">
<div class="card-header"><span class="reportTitle">Test</span></div>
<div class="card-body">
<p class="card-text">Look I'm Centered</p>
</div>
<div class="card-footer">
<div class="d-flex justify-content-between align-items-center">
<div class="btn-group">
<a href="#" type="button" class="btn btn-sm btn-outline-primary" target="_blank">App</a>
</div>
</div>
</div>
</div>
</div>