У меня есть изображение стрелки в каждом заголовке моей аккордеонной карты Bootstrap 4. Моя цель состоит в том, чтобы все они выстроились друг над другом на правом краю (но все еще внутри) границы карты. Все, что я пробовал до сих пор, либо выталкивает стрелки из карты, либо заставляет их опускаться ниже остальной части заголовка.
Я пробовал justify-content, align-content и align-items, но ни один из них еще не работал. Буду признателен за любые советы о том, как этого добиться. Ниже показано, как это выглядит в настоящее время.
<div class = "card">
<h3> FAQ </h3>
<div class = "card-header" id = "headingOne">
<h5 class = "mb-0">
<button class = "btn" data-toggle = "collapse" data-target = "#collapseOne" aria-expanded = "true" aria-controls = "collapseOne">
How many team members can I invite? <img src = "images/icon-arrow-down.svg" class = "arrow">
</button>
</h5>
</div>
<div id = "collapseOne" class = "collapse show" aria-labelledby = "headingOne" data-parent = "#accordion">
<div class = "card-body">
You can invite up to 2 additional users on the Free plan. There is no limit on
team members for the Premium plan.
</div>
</div>
</div>
#accordion{
width:30%;
float: right;
position:relative;
top: 300px;
right: 900px;
align-content: center;
font-family: 'Kumbh Sans', sans-serif;
}
.card-header{
background-color: white;
clear: both;
}
.arrow{
}
button{
position:relative;
left:-32px;
}
Я создаю образец, чтобы получить такое же поведение с Bootstrap 4, и я перемещаю вашу стрелку <img>
внутрь тега <h5>
. После этого атрибут float:right
сдвигает элемент вправо.
.xl {
width:100%;
border: solid 1px #333;
}
#accordion{
margin-left:30px;
width:60%;
}
.arrow{
width:36px;
height: auto;
float:right;
}
<script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel = "stylesheet"/>
<div class='xl'>
<h3>Some Header</h3>
<div id = "accordion">
<div class = "card">
<div class = "card-header" id = "headingOne">
<h5 class = "mb-0">
<button class = "btn btn-link" data-toggle = "collapse" data-target = "#collapseOne" aria-expanded = "true" aria-controls = "collapseOne">Collapsible Group Item #1
</button>
<img src='https://upload.wikimedia.org/wikipedia/en/f/f1/Down_Arrow_Icon.png' class='arrow'>
</h5>
</div>
<div id = "collapseOne" class = "collapse show" aria-labelledby = "headingOne" data-parent = "#accordion">
<div class = "card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
<div class = "card">
<div class = "card-header" id = "headingTwo">
<h5 class = "mb-0">
<button class = "btn btn-link collapsed" data-toggle = "collapse" data-target = "#collapseTwo" aria-expanded = "false" aria-controls = "collapseTwo">
Collapsible Group Item #2
</button>
<img src='https://upload.wikimedia.org/wikipedia/en/f/f1/Down_Arrow_Icon.png' class='arrow'>
</h5>
</div>
<div id = "collapseTwo" class = "collapse" aria-labelledby = "headingTwo" data-parent = "#accordion">
<div class = "card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
<div class = "card">
<div class = "card-header" id = "headingThree">
<h5 class = "mb-0">
<button class = "btn btn-link collapsed" data-toggle = "collapse" data-target = "#collapseThree" aria-expanded = "false" aria-controls = "collapseThree">
Collapsible Group Item #3
</button>
<img src='https://upload.wikimedia.org/wikipedia/en/f/f1/Down_Arrow_Icon.png' class='arrow'>
</h5>
</div>
<div id = "collapseThree" class = "collapse" aria-labelledby = "headingThree" data-parent = "#accordion">
<div class = "card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
</div>
</div>
Вы можете сделать это, превратив свой элемент <h5>
во гибкую строку и используя свойство justify-content
с space-between
.
Пример
HTML:
<div class = "card">
<h3> FAQ </h3>
<div class = "card-header" id = "headingOne">
<h5 class = "mb-0">
<button class = "btn" data-toggle = "collapse" data-target = "#collapseOne" aria-expanded = "true" aria-controls = "collapseOne">
How many team members can I invite?
</button>
v
</h5>
</div>
<div id = "collapseOne" class = "collapse show" aria-labelledby = "headingOne" data-parent = "#accordion">
<div class = "card-body">
You can invite up to 2 additional users on the Free plan. There is no limit on
team members for the Premium plan.
</div>
</div>
</div>
CSS:
#accordion {
width:30%;
float: right;
position:relative;
top: 300px;
right: 900px;
align-content: center;
font-family: 'Kumbh Sans', sans-serif;
}
.card-header {
background-color: white;
clear: both;
}
.card-header h5 {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
}
button{
position:relative;
left:-32px;
}
Я использую V
вместо вашего изображения, чтобы визуализировать эффект, но результат тот же.
Фрагмент:
#accordion {
width:30%;
float: right;
position:relative;
top: 300px;
right: 900px;
align-content: center;
font-family: 'Kumbh Sans', sans-serif;
}
.card-header {
background-color: white;
clear: both;
}
.card-header h5 {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
}
button{
position:relative;
left:-32px;
}
<link href = "https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel = "stylesheet"/>
<div class = "card">
<h3> FAQ </h3>
<div class = "card-header" id = "headingOne">
<h5 class = "mb-0">
<button class = "btn" data-toggle = "collapse" data-target = "#collapseOne" aria-expanded = "true" aria-controls = "collapseOne">
How many team members can I invite?
</button>
v
</h5>
</div>
<div id = "collapseOne" class = "collapse show" aria-labelledby = "headingOne" data-parent = "#accordion">
<div class = "card-body">
You can invite up to 2 additional users on the Free plan. There is no limit on
team members for the Premium plan.
</div>
</div>
</div>
Пример Codepen здесь.
Я бы также посоветовал ознакомиться с этим очень простым руководством на Flexbox.
То, что вы ищете, это превратить ваш элемент h5 в гибкий элемент и использовать
justify-content: space-between
.