【问题标题】:creating three dots vertically with span and align them使用 span 垂直创建三个点并将它们对齐
【发布时间】:2020-12-18 22:21:41
【问题描述】:
我正在尝试创建三个垂直点并将容器的左下角与 css 和 bootstrap 5 对齐。就像下图一样:
我的 HTML 和 CSS:
.dot {
border-radius: 50%;
height: 12px;
width: 12px;
background: linear-gradient(90deg, #76b3fe, #8680e4);
}
.selected-dot {
height: 20px;
width: 20px;
background: #97cdfe;
}
<section class="slider-bg-1 d-flex align-items-end">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-5 d-flex flex-column justify-content-center pt-4 pt-lg-0 order-2 order-lg-1">
<h1 class="head-font-size">Choose a powerful design for your Start-up</h1>
<h6 claas="caption-text-color">Get your freebie template now</h6>
<div class="d-lg-flex">
<div class="mt-5"><button class="my-btn" type="submit">Discover</button></div>
</div>
</div>
<div class="col-lg-5 col-md-12 col-sm-12 order-1 order-lg-2 d-flex justify-content-center">
<img src="Assets/home-slider/slider-m-1.png" class="img-fluid img-slider" alt="">
</div>
</div>
</div>
<span class="dot selected-dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</section>
这是我的输出
如何垂直对齐并将它们移动到容器的左下角?因为当我使用 div 进行包装时,它们会消失
【问题讨论】:
标签:
html
css
alignment
bootstrap-5
【解决方案1】:
第一个:将点包裹在一个容器中。我在课堂上使用了一个部分:.dot-wrapper。
第二:给包装器一个width: min-content;。这样,它只会与选定的点一样宽。
3rd:为了使点居中,给它们一个 auto 左右的边距;
.dot {
border-radius: 50%;
height: 12px;
width: 12px;
background: linear-gradient(90deg, #76b3fe, #8680e4);
margin: 5px auto;
}
.selected-dot {
height: 20px;
width: 20px;
background: #97cdfe;
}
.dot-wrapper {
width: min-content;
}
<section class="slider-bg-1 d-flex align-items-end">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-5 d-flex flex-column justify-content-center pt-4 pt-lg-0 order-2 order-lg-1">
<h1 class="head-font-size">Choose a powerful design for your Start-up</h1>
<h6 claas="caption-text-color">Get your freebie template now</h6>
<div class="d-lg-flex">
<div class="mt-5"><button class="my-btn" type="submit">Discover</button></div>
</div>
</div>
<div class="col-lg-5 col-md-12 col-sm-12 order-1 order-lg-2 d-flex justify-content-center">
<img src="Assets/home-slider/slider-m-1.png" class="img-fluid img-slider" alt="">
</div>
</div>
</div>
<section class="dot-wrapper">
<div class="dot selected-dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</section>
</section>
【解决方案2】:
这很简单,你可以像这样用div container 包裹点
<!--Column Dots -->
<div class="dot-container">
<span class="dot selected-dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
并为容器设置如下样式
.dot-container{
width: 15px;
display: flex;
flex-direction:column;
align-items:center;
}
为了更好的造型。给dot 类一些amrgin,比如margin: 3px 0;
这是一个密码笔:https://codepen.io/shammlo/pen/QWKggNX?editors=1100