css - 为什么这个 CSS 位置规则对 P 元素没有任何影响
问题描述
我正在尝试自学 CSS 布局,但我不明白为什么这个 CSS 规则不会影响段落元素的位置。
HTML
<body>
<p>Liza likes to call me first thing in the morning at 6am, it is very funny.</p>
<p class"relative">I drove a Lithuanian girl home this week and she told me about the clubs that she likes to go to like Raduga and Roka club.</p>
<p>I was sleeping all day yesterday and all night last night, I just woke up and I want to get a coffee now</p>
</body>
css
p { background-color: pink;
border-style: solid;
border-radius: 5px;
padding: 10px;
border-color:red;
margin:20px;}
.relative { position: relative;
left: 20px;
top: 20px;}
解决方案
如您所见,您缺少的class="relative"
应该是介于两者之间的。还有一个建议。请不要在您的班级中使用任何职位名称。 检查如何命名类
p {
background-color: pink;
border-style: solid;
border-radius: 5px;
padding: 10px;
border-color: red;
margin: 20px;
}
p.relative {
position: relative;
left: 20px;
top: 20px;
}
<body>
<p>Liza likes to call me first thing in the morning at 6am, it is very funny.</p>
<p class="relative">I drove a Lithuanian girl home this week and she told me about the clubs that she likes to go to like Raduga and Roka club.</p>
<p>I was sleeping all day yesterday and all night last night, I just woke up and I want to get a coffee now</p>
</body>
推荐阅读
- c - 如何从C中的链表中删除特定节点?
- objective-c - Xcode 错误:无法创建目录“/[PATH_TO_APP]/[APP_NAME].app”(在项目“[PROJECT]”的目标“[TARGET]”中)
- python - PyQt5 中的标签自动换行不占用空间
- azure-data-factory-2 - 将多个文件加载到 ADLS 时如何执行数据块笔记本
- pandas - Pandas:DataFrame op DataFrame 结果为 NaN
- r - 通过控制组为几个子组中的每一个划分整个数据帧
- json - 仅在字符串周围添加引号,而不是数字或列表
- spring-boot - 使用 RewritePath 刷新 Spring Cloud Gateway 失败
- android-studio - 在 TabLayout 中的选项卡之间添加空格
- c# - 我想进入类的表单对象类型的构造函数