html - 如何删除弹出式覆盖和链接中的额外空白
问题描述
我正在尝试创建一个相对于被单击的链接定位的弹出窗口。我的代码目前执行此操作,但触发弹出窗口的链接和覆盖本身的顶部/底部都有额外的空白。我想删除这个额外的空白。
我为链接和覆盖添加了边框,以帮助您可视化问题。
我尝试将链接和覆盖设置为内联块。
* {
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
margin-top: 200px;
}
.box {
border: 1px solid black;
}
.overlay {
position: relative;
top: -20px;
left: 20px;
border: 1px solid red;
visibility: hidden;
opacity: 0;
}
.overlay:target {
visibility: visible;
opacity: 1;
}
.popup {
margin: 70px auto;
padding: 20px;
background: #dff9fb;
border-radius: 5px;
width: 100%;
position: relative;
}
.close {
position: absolute;
top: 16px;
right: 30px;
}
<div class="box">
<a class="button" href="#popup1">Let me Pop up</a>
</div>
<div id="popup1" class="overlay">
<div class="popup">
<h2>Endling #1</h2>
<iframe width="100%" height="300" scrolling="no" frameborder="no" allow="autoplay" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/648742508&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true"></iframe>
<a class="close" href="#">×</a>
</div>
</div>
我想删除链接('box'类)和覆盖('overlay')类顶部/底部的额外空白。我希望叠加层的位置保持相对于被单击的链接。
解决方案
尝试将所有内容放在 html<table>
中。这应该保持两个框内联;
推荐阅读
- random - 如何获得真正的随机数据,而不是像 CSRNG 那样输入 PRNG 种子的随机数据?
- java - Java UI 项目的外观和感觉 FlatLaf
- python - pythonlinkedlist删除元组
- swiftui - 如何在 SwiftUI 中使用(不同的)尺寸约束视图屏蔽视图?
- python - 如何摆脱弃用警告?
- gnu-screen - 屏幕在 NetBSD 上失败,报告“poll: Invalid argument”
- javascript - 如何将子数组的内容转换为父数组
- javascript - 在 redux-saga-firebase 中获取集合参考
- javascript - 使用反应添加到购物车功能
- c# - ASP.NET SPA 中的 Azure AD 实现