В приведенном ниже коде Bootstrap 5 есть div с идентификатором «div-in-right-div», который находится внутри div с идентификатором «right-div». «div-in-right-div» выравнивается по верхнему краю «right-div».
Какие изменения нужно сделать, чтобы внутренний div «div-in-right-div» был выровнен по вертикали с нижним краем внешнего div «right-div»?
Я думал, что класс "align-bottom", который я добавил в div с id="right-div" должен сделать трюк, но это не так. Я также добавил класс «align-self-end» в div «div-in-right-div» в дополнение к вышесказанному, и это также не дало того, что я хотел.
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "UTF-8">
<meta name = "viewport" content = "width=device-width, initial-scale=1.0">
<link rel = "stylesheet" href = "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel = "stylesheet" href = "https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<style>
.custom-header {
max-width: 1200px;
margin: 0 auto;
background-color: yellow;
}
.right-block ul.nav {
display: flex;
align-items: center;
list-style: none;
padding: 0;
}
.right-block ul.nav li {
margin-left: 20px;
}
.right-block ul.nav li a {
text-decoration: none;
display: flex;
align-items: center;
position: relative;
}
.right-block ul.nav li .icon {
font-size: 20px;
margin-right: 5px;
}
/* Mobile-specific styling */
@media (max-width: 767px) {
/* ... Mobile styles ... */
}
/* Large screen specific styling */
@media (min-width: 992px) {
.right-block ul.nav li a::before {
content: "";
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 0;
height: 2px;
background-color: black;
transition: all 0.3s ease;
}
.right-block ul.nav li a:hover::before {
width: 100%;
}
}
</style>
<title>Bootstrap 5 Header Example</title>
</head>
<body>
<header class = "custom-header">
<div class = "container">
<div class = "row">
<div class = "col-md-4">
<div class = "left-block">
<!-- Content for the left block -->
<h3>Left Block</h3>
</div>
</div>
<div class = "col-md-4">
<div class = "central-block text-center">
<!-- Content for the center block -->
<h3>Central Block</h3>
</div>
</div>
<div class = "col-md-4 align-bottom" id = "right-div">
<div class = "right-block align-self-end" id = "div-in-right-div">
<!-- Content for the right block -->
<ul class = "nav justify-content-end">
<li>
<a href = "#">
<i class = "bi bi-house icon"></i>
<span>Add</span>
</a>
</li>
<li>
<a href = "#">
<i class = "bi bi-person icon"></i>
<span>Login</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</header>
<script src = "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>Многие объявления в вашем пользовательском CSS можно применить с помощью соответствующих классов Bootstrap.
Как сказал TimR, вам следует взглянуть на это: getbootstrap.com/docs/5.3/utilities/flex @j08691 Я только что увидел ваш комментарий. Это именно то, что я ответил.






Добавьте стиль display: inline-grid; или display: grid; к #right-div.
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "UTF-8">
<meta name = "viewport" content = "width=device-width, initial-scale=1.0">
<link rel = "stylesheet" href = "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel = "stylesheet" href = "https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<style>
.custom-header {
max-width: 1200px;
margin: 0 auto;
background-color: yellow;
}
.right-block ul.nav {
display: flex;
align-items: center;
list-style: none;
padding: 0;
}
.right-block ul.nav li {
margin-left: 20px;
}
.right-block ul.nav li a {
text-decoration: none;
display: flex;
align-items: center;
position: relative;
}
.right-block ul.nav li .icon {
font-size: 20px;
margin-right: 5px;
}
/* Mobile-specific styling */
@media (max-width: 767px) {
/* ... Mobile styles ... */
}
/* Large screen specific styling */
@media (min-width: 992px) {
.right-block ul.nav li a::before {
content: "";
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 0;
height: 2px;
background-color: black;
transition: all 0.3s ease;
}
.right-block ul.nav li a:hover::before {
width: 100%;
}
}
#right-div{
display: inline-grid;
}
</style>
<title>Bootstrap 5 Header Example</title>
</head>
<body>
<header class = "custom-header">
<div class = "container">
<div class = "row">
<div class = "col-md-4">
<div class = "left-block">
<!-- Content for the left block -->
<h3>Left Block</h3>
</div>
</div>
<div class = "col-md-4">
<div class = "central-block text-center">
<!-- Content for the center block -->
<h3>Central Block</h3>
</div>
</div>
<div class = "col-md-4 align-bottom" id = "right-div">
<div class = "right-block align-self-end" id = "div-in-right-div">
<!-- Content for the right block -->
<ul class = "nav justify-content-end">
<li>
<a href = "#">
<i class = "bi bi-house icon"></i>
<span>Add</span>
</a>
</li>
<li>
<a href = "#">
<i class = "bi bi-person icon"></i>
<span>Login</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</header>
<script src = "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html><!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "UTF-8">
<meta name = "viewport" content = "width=device-width, initial-scale=1.0">
<link rel = "stylesheet" href = "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel = "stylesheet" href = "https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<style>
.custom-header {
max-width: 1200px;
margin: 0 auto;
background-color: yellow;
}
.right-block ul.nav {
display: flex;
align-items: center;
list-style: none;
padding: 0;
}
.right-block ul.nav li {
margin-left: 20px;
}
.right-block ul.nav li a {
text-decoration: none;
display: flex;
align-items: center;
position: relative;
}
.right-block ul.nav li .icon {
font-size: 20px;
margin-right: 5px;
}
/* Mobile-specific styling */
@media (max-width: 767px) {
/* ... Mobile styles ... */
}
/* Large screen specific styling */
@media (min-width: 992px) {
.right-block ul.nav li a::before {
content: "";
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 0;
height: 2px;
background-color: black;
transition: all 0.3s ease;
}
.right-block ul.nav li a:hover::before {
width: 100%;
}
}
</style>
<title>Bootstrap 5 Header Example</title>
</head>
<body>
<header class = "custom-header">
<div class = "container">
<div class = "row">
<div class = "col-md-4">
<div class = "left-block">
<!-- Content for the left block -->
<h3>Left Block</h3>
</div>
</div>
<div class = "col-md-4">
<div class = "central-block text-center">
<!-- Content for the center block -->
<h3>Central Block</h3>
</div>
</div>
<div class = "col-md-4 align-bottom" id = "right-div">
<div class = "right-block align-self-end" id = "div-in-right-div">
<!-- Content for the right block -->
<ul class = "nav justify-content-end">
<li>
<a href = "#">
<i class = "bi bi-house icon"></i>
<span>Add</span>
</a>
</li>
<li>
<a href = "#">
<i class = "bi bi-person icon"></i>
<span>Login</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</header>
<script src = "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>Объясните свой ответ, пожалуйста. Не просто выбрасывайте код и ожидайте, что все поймут, что вы сделали.
@ j08691 Этот ответ даже не работает.
Ваш ответ может быть улучшен с помощью дополнительной вспомогательной информации. Пожалуйста, отредактируйте , чтобы добавить дополнительные сведения, такие как цитаты или документация, чтобы другие могли подтвердить правильность вашего ответа. Вы можете найти больше информации о том, как писать хорошие ответы в справочном центре.
Вы можете выровнять #div-in-right-div внизу, добавив классы "d-flex align-items-baseline" в #right-div. Я также добавил «ширина: 100%;» к #div-in-right-div, поэтому он не прилипает к левому из-за гибкости дисплея с помощью бутстрапа.
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "UTF-8">
<meta name = "viewport" content = "width=device-width, initial-scale=1.0">
<link rel = "stylesheet" href = "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel = "stylesheet" href = "https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<style>
/* new */
#div-in-right-div {
width: 100%;
}
/* new end */
.custom-header {
max-width: 1200px;
margin: 0 auto;
background-color: yellow;
}
.right-block ul.nav {
display: flex;
align-items: center;
list-style: none;
padding: 0;
}
.right-block ul.nav li {
margin-left: 20px;
}
.right-block ul.nav li a {
text-decoration: none;
display: flex;
align-items: center;
position: relative;
}
.right-block ul.nav li .icon {
font-size: 20px;
margin-right: 5px;
}
/* Mobile-specific styling */
@media (max-width: 767px) {
/* ... Mobile styles ... */
}
/* Large screen specific styling */
@media (min-width: 992px) {
.right-block ul.nav li a::before {
content: "";
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 0;
height: 2px;
background-color: black;
transition: all 0.3s ease;
}
.right-block ul.nav li a:hover::before {
width: 100%;
}
}
</style>
<title>Bootstrap 5 Header Example</title>
</head>
<body>
<header class = "custom-header">
<div class = "container">
<div class = "row">
<div class = "col-md-4">
<div class = "left-block">
<!-- Content for the left block -->
<h3>Left Block</h3>
</div>
</div>
<div class = "col-md-4">
<div class = "central-block text-center">
<!-- Content for the center block -->
<h3>Central Block</h3>
</div>
</div>
<div class = "col-md-4 d-flex align-items-baseline" id = "right-div">
<div class = "right-block align-self-end" id = "div-in-right-div">
<!-- Content for the right block -->
<ul class = "nav justify-content-end">
<li>
<a href = "#">
<i class = "bi bi-house icon"></i>
<span>Add</span>
</a>
</li>
<li>
<a href = "#">
<i class = "bi bi-person icon"></i>
<span>Login</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</header>
<script src = "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
d-flex align-items-basline justify-content-endв #right-div — это то, что вы ищете?