英文:
How can I add a badge to this Bootstrap website?
问题
我正在尝试学习前端。我从一个Bootstrap项目开始,但我卡在了这个问题上。我想要像我做的设计中那样添加徽章。尽管我尝试添加它,但对齐方式不正确,网站乱了。有人可以试一下吗?
<div class="d-flex flex-column flex-md-row p-4 gap-4 py-md-5 align-items-center justify-content-center">
<div class="list-group">
<label class="list-group-item d-flex gap-3">
<span class="pt-1 form-checked-content">
<strong>Title</strong>
<small class="d-block text-body-secondary">
<svg class="bi me-1" height="1em" width="1em"><use xlink:href="#calendar-event"></use></svg>
23 July
<svg class="bi me-1" height="1em" style="margin-left: 10px;" width="1em"><use
xlink:href="#alarm"></use></svg>
17:00
</small>
<small class="d-block text-body-secondary">
<svg class="bi me-1" height="1em" width="1em"><use xlink:href="#geo-alt"></use></svg>
1.5 km
<svg class="bi me-1" height="1em" style="margin-left: 10px;" width="1em"><use
xlink:href="#car"></use></svg>
19 min
</small>
</span>
<button class="btn btn-secondary position-absolute top-50 translate-middle text-body-secondary"
style="right: 0; background: none; border-color: #00000059;" type="button">
<svg class="bi m-1" height="1em" width="1em">
<use xlink:href="#edit"></use>
</svg>
</button>
</label>
</div>
</div>
我已经尝试过的事情:
我尝试添加按钮并对其进行样式设置,但结果不如我预期的那样。它被添加到了标签中,所以所有文本都向右移动,就像是水平网格一样。
英文:
I'm trying to learn front-end. I'm starting with a project in Bootstrap, but I'm stuck on this issue. I want to add badges like in this design I made. Although if I try to add it, the alignment is incorrect and the site is messed up. Can somebody give it a shot?
<div class="d-flex flex-column flex-md-row p-4 gap-4 py-md-5 align-items-center justify-content-center">
<div class="list-group">
<label class="list-group-item d-flex gap-3">
<span class="pt-1 form-checked-content">
<strong>Title</strong>
<small class="d-block text-body-secondary">
<svg class="bi me-1" height="1em" width="1em"><use xlink:href="#calendar-event"></use></svg>
23 July
<svg class="bi me-1" height="1em" style="margin-left: 10px;" width="1em"><use
xlink:href="#alarm"></use></svg>
17:00
</small>
<small class="d-block text-body-secondary">
<svg class="bi me-1" height="1em" width="1em"><use xlink:href="#geo-alt"></use></svg>
1,5 km
<svg class="bi me-1" height="1em" style="margin-left: 10px;" width="1em"><use
xlink:href="#car"></use></svg>
19 min
</small>
</span>
<button class="btn btn-secondary position-absolute top-50 translate-middle text-body-secondary"
style="right: 0; background: none; border-color: #00000059;" type="button">
<svg class="bi m-1" height="1em" width="1em">
<use xlink:href="#edit"></use>
</svg>
</button>
</label>
</div>
</div>
What I've already tried:
I tried to add buttons and style them, but the result wasn't what I was expecting. It was added into the label so all of the text was shifted to the right like it was a horizontal grid.
答案1
得分: 1
我在标签上添加了flex-wrap
类,以便新的flex项目可以换行,然后添加了一个具有flex-basis
为100%
的新div
,以便占据整行,然后在其中添加了徽章。此外,为了对齐顶部内容,我在span
上添加了一些边距。
英文:
I added the class flex-wrap
to the label so that new flex items can wrap and then added a new div with the flex-basis
for 100%
so that it takes the whole row and then added the badges inside of it. And also for the alignment of the top contents I added some margin to the span
.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<div class="d-flex flex-column flex-md-row p-4 gap-4 py-md-5 align-items-center justify-content-center">
<div class="list-group">
<label class="list-group-item d-flex flex-wrap gap-3">
<span class="pt-1 form-checked-content mt-3">
<strong>Title</strong>
<small class="d-block text-body-secondary">
<svg class="bi me-1" height="1em" width="1em"><use xlink:href="#calendar-event"></use></svg>
23 July
<svg class="bi me-1" height="1em" style="margin-left: 10px;" width="1em"><use
xlink:href="#alarm"></use></svg>
17:00
</small>
<small class="d-block text-body-secondary">
<svg class="bi me-1" height="1em" width="1em"><use xlink:href="#geo-alt"></use></svg>
1,5 km
<svg class="bi me-1" height="1em" style="margin-left: 10px;" width="1em"><use
xlink:href="#car"></use></svg>
19 min
</small>
</span>
<button class="btn btn-secondary position-absolute top-50 translate-middle text-body-secondary"
style="right: 0; background: none; border-color: #00000059;" type="button">
<svg class="bi m-1" height="1em" width="1em">
<use xlink:href="#edit"></use>
</svg>
</button>
<div style="flex-basis: 100%;">
<div class="d-inline-block rounded-circle bg-danger text-center" style="width: 25px; height: 25px;">S</div>
<div class="d-inline-block rounded-circle bg-success text-center" style="width: 25px; height: 25px;">A</div>
<div class="d-inline-block rounded-circle bg-primary text-center" style="width: 25px; height: 25px;">E</div>
</div>
</label>
</div>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论