html - 如何在不改变卡片高度或干扰其他元素位置的情况下添加元素
问题描述
如何在不改变卡片高度的情况下在末尾添加元素(图像),卡片高度设置为自动
有没有办法解决这个问题?任何帮助表示赞赏,谢谢!
.card {
width: 540px;
height: auto;
border: 1px solid #707070;
}
.field2 {
font-family: inherit;
padding-top: 20px;
padding-bottom: 25px;
display: flex;
justify-content: space-between;
}
.log_in_instead {
padding-left: 60px;
}
.create {
padding-right: 70px;
}
#img101 {
position: relative;
left: 490px;
top: -150px;
}
<div class="card">
<div class="field2">
<span class="log_in_instead"> <a href="#">Log in instead</a> </span>
<span class="create"><button id="create_button" type="submit">Create</button></span>
</div>
<span><img src="{% static 'main/images/img101.svg' %}" id="img101"></span>
</div>
它应该是这样的:[1]:https ://i.stack.imgur.com/jkPg2.png
这就是它的样子:[2]:https ://i.stack.imgur.com/w1ROu.png
解决方案
尝试给卡片位置:相对和图像位置:绝对。并删除图像周围的跨度。我认为这样定位会更容易。所以你可以给它一个底部:-50px,对:-50px(取决于你的图像的大小)。
并检查您的 / 按钮,您没有关闭它。
您的代码应如下所示:
HTML:
<div class="card">
<div class="field2">
<span class="log_in_instead"> <a href="#">Log in instead</a</span>
<span class="create"><button id="create_button" type="submit">Create</button></span>
</div>
<img src="{% static 'main/images/img101.svg' %}" id="img101"></>
</div>
CSS:
.card {
position: relative;
width: 540px;
height: auto;
border: 1px solid #707070;
}
.field2 {
font-family: inherit;
padding-top: 20px;
padding-bottom: 25px;
display: flex;
justify-content: space-between;
}
.log_in_instead {
padding-left: 60px;
}
.create {
padding-right: 70px;
}
#img101 {
position: absolute;
width: 100px; /*use your custom size*/
height: 100px; /*use your custom size*/
background-color: #000; /*only for visualization*/
right: -50px; /*use your custom size*/
bottom: -50px; /*use your custom size*/
}
在codepen中检查:https ://codepen.io/flpfar/pen/vYNJGNr
希望能帮助到你 :)
推荐阅读
- elasticsearch - Elasticsearch 中数组字段的最大大小是多少?
- bash - 循环覆盖文件
- javascript - 使用 IFrame Player API 重新打开模态后,Youtube iframe 不显示
- android - 选择文件资源管理器后未初始化 lateinit 属性
- javascript - 如何修复ajax中的[OBJECT OBJECT]来查看数据
- parse-platform - 多个表之间的复杂搜索在 Parse Server 中不起作用?
- c# - Unity - 替换为空
- vue.js - NUXT 中间件存储状态为空,即使开发工具中的 Vuex 显示数据
- jquery - 如何使用 jquery 循环响应
- function - 错误:在项目中运行任何脚本时出现“找不到服务:加上 v1”。如何解决?