html - 有没有办法让每个锚点/按钮在调整网络屏幕大小时不改变/移动它的位置?
问题描述
正如您在提供的图片中看到的,如果我尝试调整网页大小,“阅读更多”锚点/按钮也会移动。有没有办法让他们各自的地方在调整网页屏幕大小时保持不变?我也试过固定位置。
这是与该问题有关的唯一代码,我正在使用带有少量 css 的引导程序。
<section class="second-section">
<div class="container-fluid">
<div class="row text-center">
<div class="col-md bg-white border">
<div class="card-1 text-left ">
<h1>Business <span>Mentoring</span></h1>
<p>Our mentors are leading professional and experts in their field with a passion....</p>
<a href="#" class="readMore-anchor">Read more</a>
</div>
</div>
<div class="col-md bg-white border">
<div class="card-2 text-left">
<h1>Business <span>Coaching</span></h1>
<p>Our coaches are successful professional and leaders in their field, who ....</p>
<a href="#" class="readMore-anchor">Read more</a>
</div>
</div>
<div class="col-md bg-white border">
<div class="card-3 text-left">
<h1>Personal <span>Mentoring</span> and coaching</h1>
<p>is where have professionals ready to work with a family,...</p>
<a href="#" class="readMore-anchor">Read more</a>
</div>
</div>
<div class="col-md bg-white border">
<div class="card-4 text-left">
<h1>Career <span>exploration</span></h1>
<p>Career advice and exploration is vital if you want to maximise your potential in today's....</p>
<a href="#" class="readMore-anchor">Read more</a>
</div>
</div>
</div>
</div>
</section>
.card-1 .card-2 .card-3 .card-4 h1{
width: 100%;
font-size: 40px;
line-height: 50px;
font-family: "Montserrat Bold";
}
.card-1 h1 span{
display: block;
}
.card-1 .card-2 .card-3 .card-4 p{
width: 100%;
max-width: 325px;
font-size: 16px;
color: #232020;
line-height: 28px;;
font-family: "Montserrat Regular";
}
.second-section p{
margin: 0;
}
.readMore-anchor{
width: 100%;
height: 47px;
font-size: 16px;
max-width: 161px;
line-height: 50px;
padding: 15px 38px;
background-color: #8cd9f9; ;
}
解决方案
不久前有同样的问题,这就是我解决它的方法(尽管可能有其他方法):
- 添加相对于四个容器卡片的位置(注意这不是针对卡片,而是针对按钮)。在您的示例中,这将是具有通用类 bg-white 的 div。还要在容器卡片的底部添加一个填充,以便在我们定位按钮时为按钮浮动创建空间。
.bg-white {
position: relative;
padding-bottom: 60px;
}
- 在我们刚刚创建的空间内绝对定位按钮。
.bg-white > .text-left > .readMore-anchor {
position: absolute;
right: 10px;
bottom: 10px;
}
你应该得到这样的结果,文本和按钮之间的空白将自动调整以匹配具有最多文本的卡片,保持统一。(我没有完成让我的和你的一样漂亮,但我相信它具有你正在寻找的功能)。
.card-1 .card-2 .card-3 .card-4 h1{
width: 100%;
font-size: 40px;
line-height: 50px;
font-family: "Montserrat Bold";
}
.card-1 h1 span{
display: block;
}
.card-1 .card-2 .card-3 .card-4 p{
width: 100%;
max-width: 325px;
font-size: 16px;
color: #232020;
line-height: 28px;;
font-family: "Montserrat Regular";
}
.second-section p{
margin: 0;
}
.readMore-anchor{
width: 100%;
height: 47px;
font-size: 16px;
max-width: 161px;
line-height: 50px;
padding: 15px 38px;
background-color: #8cd9f9; ;
}
.bg-white {
position: relative;
padding-bottom: 60px;
}
.bg-white > .text-left > .readMore-anchor {
position: absolute;
right: 10px;
bottom: 10px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<section class="second-section">
<div class="container-fluid">
<div class="row text-center">
<div class="col-md bg-white border">
<div class="card-1 text-left ">
<h1>Business <span>Mentoring</span></h1>
<p>Our mentors are leading professional and experts in their field with a passion....</p>
<a href="#" class="readMore-anchor">Read more</a>
</div>
</div>
<div class="col-md bg-white border">
<div class="card-2 text-left">
<h1>Business <span>Coaching</span></h1>
<p>Our coaches are successful professional and leaders in their field, who ....</p>
<a href="#" class="readMore-anchor">Read more</a>
</div>
</div>
<div class="col-md bg-white border">
<div class="card-3 text-left">
<h1>Personal <span>Mentoring</span> and coaching</h1>
<p>is where have professionals ready to work with a family,...</p>
<a href="#" class="readMore-anchor">Read more</a>
</div>
</div>
<div class="col-md bg-white border">
<div class="card-4 text-left">
<h1>Career <span>exploration</span></h1>
<p>Career advice and exploration is vital if you want to maximise your potential in today's....</p>
<a href="#" class="readMore-anchor">Read more</a>
</div>
</div>
</div>
</div>
</section>
推荐阅读
- redis - Kubernetes 上的 Redis json
- python-3.x - 是否有任何 python 函数来检查列表理解中的 nan 值而不更改它
- firebase - 如何使用firebase在flutter中实现电话号码验证?(非认证)
- bash - Bash:如何在 Bash 中用省略号截断“ls”的长输出?
- java - 为什么 Float.parseFloat() 同时抛出 NumberFormatException 和 NullPointerException 而 Integer.parseInt() 只抛出 NumberFormatException?
- c# - 如何以编程方式从 Window.Resources 向 x:Array 添加新项目
- python - 如果没有收到输入,如何监控客户端输入并每 5 秒从服务器发送输入请求?
- laravel - Laravel Pivot 3张表之间的表关系
- delphi - 是否有可能以点击它的方式操作 TCustomButton 的后代,而不会窃取另一个控件的焦点?
- java - 无法扩展 CDT CEditor:“类型 '' 的层次结构不一致”