html - 为什么span元素的上半部分覆盖了文字而下半部分不覆盖
问题描述
以下代码说明了我的问题。
span {
margin: 20px;
padding: 20px;
width: 80px;
height: 50px;
background-color: lightblue;
border: 2px solid blue;
}
p {
width: 300px;
}
<p>
I am a paragraph and this is a <span>span</span> inside that paragraph. A span is an inline element and so does not respect width and height.
</p>
'paragraph'
我们可以看到 span 元素的上半部分覆盖了文本,而下半部分'span is an'
没有
解决方案
这是因为文件的逐行执行。position:relative
为它设置span
将在其他元素之上。
span {
margin: 20px;
padding: 20px;
width: 80px;
height: 50px;
background-color: red;
border: 2px solid blue;
position: relative;
}
p{
width:300px;
}
<p>
I am a paragraph and this is a <span>span</span> inside that paragraph. A span is an inline element and so does not respect width and height.
</p>
推荐阅读
- javascript - 将初始化对象传递给 setState React
- java - Array.copyOfRange 方法无法按预期运行并返回一个奇怪的字符串
- python - 如何在 python 中将叶图 html 读回叶图对象?
- node.js - Angular 应用程序无法连接到 NodeJS/SocketIO 后端 cors 问题?
- pine-script - 某些股票代码的 PineScript?
- laravel - 在 laravel 中更改迁移值
- prolog - 自动重新运行 prolog 应用程序
- javascript - 如何使用 Here API 构建带有标记的交互式或动态地图
- python - 如何在pytorch对象检测中添加转换
- maxima - 千里马 CAS;如何在块中本地使用 simp 标志