gpt4 book ai didi

html - 位置 "list-group"在右侧,而 "cards"在左侧,Bootstrap

转载 作者:太空宇宙 更新时间:2023-11-04 01:16:15 24 4
gpt4 key购买 nike

在学习和使用 Bootstrap 网格系统构建网站时,我有点困惑。我正在制作一个由 3 个 block 组成的菜单 - “卡片”和一个固定的(当你滚动时跟随)“列表组”。一直在尝试使用 float:right 等,但是当我更改将“列表组”拉到右边的内容时,一切都会中断。

enter image description here

HTML:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container">

<div class="side">
<div class="row">
<div class="col-sm-3" style="background:red">
<div class="list-group">
<a href="#" class="list-group-item list-group-item-action">Dapibus ac</a>
<a href="#" class="list-group-item list-group-item-action">Morbi leo risus</a>
</div>
</div>
</div>
</div>

<div class="content">
<div class="row">
<div class="col-sm-3" style="background:cyan">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Text.</p>
</div>
</div>
</div>

<div class="col-sm-3" style="background:yellow">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Text.</p>
</div>
</div>
</div>

<div class="col-sm-3" style="background:orange">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Text.</p>
</div>
</div>
</div>

<div class="w-100"></div>

<div class="col-sm-3" style="background:red">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Text.</p>
</div>
</div>
</div>

</div>
</div>

</div>

感谢我得到的每一个有用的答案!

最佳答案

试试这段代码

.container {
position: relative;
}
.side {
position: absolute;
right: 0;
top:0;
bottom: 0;
width: 250px;
z-index: 1;
background-color: #fff;
}

.content {
margin-right: 250px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container">

<div class="side">
<div class="list-group">
<a href="#" class="list-group-item list-group-item-action">Dapibus ac</a>
<a href="#" class="list-group-item list-group-item-action">Morbi leo risus</a>
</div>
</div>

<div class="content">
<div class="row">
<div class="col-sm-3" style="background:cyan">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Text.</p>
</div>
</div>
</div>

<div class="col-sm-3" style="background:yellow">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Text.</p>
</div>
</div>
</div>

<div class="col-sm-3" style="background:orange">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Text.</p>
</div>
</div>
</div>

<div class="col-sm-3" style="background:red">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Text.</p>
</div>
</div>
</div>

</div>
</div>

</div>

使用 Bootstrap

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container">
<div class="row no-gutters">
<div class="col-lg-9 col-sm-8">
<div class="content">
<div class="row">
<div class="col-sm-6" style="background:cyan">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Text.</p>
</div>
</div>
</div>

<div class="col-sm-6" style="background:yellow">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Text.</p>
</div>
</div>
</div>

<div class="col-sm-6" style="background:orange">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Text.</p>
</div>
</div>
</div>

<div class="col-sm-6" style="background:red">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Text.</p>
</div>
</div>
</div>

</div>
</div>
</div>
<div class="col-lg-3 col-sm-4">
<div class="side">
<div class="list-group">
<a href="#" class="list-group-item list-group-item-action">Dapibus ac</a>
<a href="#" class="list-group-item list-group-item-action">Morbi leo risus</a>
</div>
</div>

</div>
<div>





</div>

关于html - 位置 "list-group"在右侧,而 "cards"在左侧,Bootstrap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50075038/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com