如何修复Django中多个锚点指向同一链接的错误?
问题解决:两个锚点链接被覆盖的问题
你的问题出在绝对定位和宽度设置上:两个<a>标签都使用了position: absolute,且宽度设为100%,第二个链接的right: -80px让它的覆盖范围完全包含了第一个链接——点击第一个链接的区域时,实际触发的是第二个链接的跳转,和Django环境无关。
解决方案1:改用Flex布局(推荐)
放弃绝对定位,用Flex实现并排排列,避免元素重叠:
<div style="position: relative; bottom: 30px; display: flex; justify-content: center; gap: 160px;"> <a href="https://www.w3schools.com/tryit/" id="1">Something1</a> <a href="https://stackoverflow.com/questions/25345392/how-to-add-url-parameters-to-django-template-url-tag" id="2">Something2</a> </div>
解决方案2:调整绝对定位参数
如果必须保留绝对定位,需要修改宽度和位置,避免重叠:
<div style="position: relative;"> <a href="https://www.w3schools.com/tryit/" style="position: absolute; bottom: 30px; right: 160px; width: auto;" id="1">Something1</a> <a href="https://stackoverflow.com/questions/25345392/how-to-add-url-parameters-to-django-template-url-tag" style="position: absolute; bottom: 30px; right: 0; width: auto;" id="2">Something2</a> </div>
说明:给父元素添加position: relative,让子元素的绝对定位基于父元素;将链接宽度改为auto,避免100%宽度导致的覆盖,再调整right值让两个链接分开。
内容的提问来源于stack exchange,提问作者GeneticallyAugmentedChair
相关产品推荐
相关产品推荐

