英文:
Align bootstrap cards with filter forms on the left
问题
我正在尝试使用Bootstrap的row
和col-
类来对齐卡片。前三个按预期工作,但第四个不起作用。有人知道为什么会发生这种情况,还能提供解决方案吗?
这是我的代码:
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="form">
<i class="fa fa-search"></i>
<input type="text" class="form-control form-input" placeholder="搜索...">
<span class="left-pan"><i class="fa fa-microphone"></i></span>
</div>
</div>
<div id="mobile-filter">
<!-- 这里是移动设备的筛选器内容 -->
</div>
<section id="sidebar">
<!-- 这里是侧边栏内容 -->
</section>
<div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-3 col-xxl-3 boat" *ngFor="let boat of boats">
<div class="card">
<img src="/{{ boat.src }}" class="card-img-top" alt="{{ boat.name }}">
<div class="card-body">
<h5 class="card-title">{{ boat.name }}</h5>
<p class="card-text">{{ boat.description }}</p>
<p>{{ boat.city }}</p>
</div>
</div>
</div>
</div>
</div>
这是相应的SCSS文件:
.form {
position: relative;
/* 其他样式 */
}
.form .fa-search {
position: absolute;
top: 20px;
left: 20px;
color: #9ca3af;
/* 其他样式 */
}
.form span {
position: absolute;
right: 17px;
top: 13px;
padding: 2px;
border-left: 1px solid #d1d5db;
/* 其他样式 */
}
/* 其他样式 */
.card {
margin-top: $m;
width: 100%;
height: 350px;
border-radius: $br-100;
overflow: hidden;
/* 其他样式 */
}
.card img {
width: 100%;
height: 200px;
object-fit: cover;
object-position: 50% 50%;
/* 其他样式 */
}
#sidebar {
width: 20%;
padding: 10px;
margin: 0;
float: left;
/* 其他样式 */
}
/* 其他样式 */
.boat {
padding-left: $p-xs;
padding-right: $p-xs;
/* 其他样式 */
}
英文:
I am trying to align the cards using row
and col-
classes from bootstrap. The first three work as its supposed to but the fourth one doesnt do what i want it to do. Does anyone have an idea as to why this is happening and maybe also have a solution for me?
this is my code:
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="form">
<i class="fa fa-search"></i>
<input type="text" class="form-control form-input" placeholder="Search anything...">
<span class="left-pan"><i class="fa fa-microphone"></i></span>
</div>
</div>
<div id="mobile-filter">
<div>
<ul>
<li>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Default checkbox
</label>
</div>
</li>
<li>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Default checkbox
</label>
</div>
</li>
<li>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Default checkbox
</label>
</div>
</li>
<li>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Default checkbox
</label>
</div>
</li>
<li>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Default checkbox
</label>
</div>
</li>
</ul>
<div>
<div class="border-bottom"></div>
<ul class="list-group">
<label for="customRange1" class="form-label">Price per hour</label>
<input type="range" class="form-range" id="customRange1">
</ul>
</div>
<div>
<ul class="list-group">
<label for="customRange1" class="form-label">Price per hour</label>
<input type="range" class="form-range" id="customRange1">
</ul>
</div>
</div>
<div>
</div>
<div>
</div>
</div>
<section id="sidebar">
<div>
<ul>
<li>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Default checkbox
</label>
</div>
</li>
<li>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Default checkbox
</label>
</div>
</li>
<li>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Default checkbox
</label>
</div>
</li>
<li>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Default checkbox
</label>
</div>
</li>
<li>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Default checkbox
</label>
</div>
</li>
</ul>
</div>
<div>
<div class="border-bottom"></div>
<ul class="list-group">
<label for="customRange1" class="form-label">Price per hour</label>
<input type="range" class="form-range" id="customRange1">
</ul>
</div>
<div>
<ul class="list-group">
<label for="customRange1" class="form-label">Price per hour</label>
<input type="range" class="form-range" id="customRange1">
</ul>
</div>
</section>
<div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-3 col-xxl-3 boat" *ngFor="let boat of boats">
<div class="card">
<img src="/{{ boat.src }}" class="card-img-top" alt="{{ boat.name }}">
<div class="card-body">
<h5 class="card-title">{{ boat.name }}</h5>
<p class="card-text">{{ boat.description }}</p>
<p>{{ boat.city }}</p>
</div>
</div>
</div>
</div>
</div>
This is the scss file that goes with it:
.form {
position: relative;
}
.form .fa-search {
position: absolute;
top: 20px;
left: 20px;
color: #9ca3af;
}
.form span {
position: absolute;
right: 17px;
top: 13px;
padding: 2px;
border-left: 1px solid #d1d5db;
}
ul {
list-style: none;
}
li a {
text-decoration: none;
}
li a:hover {
text-decoration: none;
}
.left-pan {
padding-left: 7px;
}
.left-pan i {
padding-left: 10px;
}
.form-input {
height: 55px;
text-indent: 33px;
border-radius: $br-160;
}
.form-input:focus {
box-shadow: $shadow-black-lg;
border: $b-1 $b-solid $grey;
}
.card {
margin-top: $m;
width: 100%;
height: 350px;
border-radius: $br-100;
overflow: hidden;
}
.card img {
width: 100%;
height: 200px;
object-fit: cover;
object-position: 50% 50%;
}
#sidebar {
width: 20%;
padding: 10px;
margin: 0;
float: left;
}
ul {
padding: 5px;
}
li a {
color: $grey;
}
li a:hover {
color: $tertiary;
}
.navbar-nav {
margin-left: 35%;
}
.nav-item {
padding-left: 20px;
}
#mobile-filter {
display: none;
}
.boat {
padding-left: $p-xs;
padding-right: $p-xs;
}
All help is highly appreciated!
答案1
得分: 2
好的开始,你应该将整个宽度视为一行 - 然后将 col-4 与 col-8 分别设置为侧边栏和主内容或右侧。你的第四艘船正在滑动,因为... 嗯,那里有空间!如果你将它(所有船只)的容器设置为整个屏幕的 col-8,然后在内部创建 flex 或 grid,你可以随意布局,它不会让你的项目滑出定义的空间 - 它会将元素包装到下方的第一张卡片下方,或者允许你创建无限的水平滚动,所有的船只都在一行中可见。
英文:
Good start, you should treat the whole width as row - then set col-4 vs col-8 to sidebar and your main content or right respectively.
Your forth boat is sliding because... well, it has space there! If you set it's (all boats) container to be col-8 of the whole screen, you can then create flex or grids inside as you will and it won't let your items to slide outside of defined space - it will wrap element down, moving it below first card or allow you to make eg. infinite horizontal scroll with all boats being visible in one row.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论