html - 有什么方法可以将 css 放入 html 中吗?

标签 html css

<分区>

是否有一些方法可以将 css 放入 html 中?我的意思是例如选择器,例如“之前:”和“之后:”

<div id="foto" style="position: relative; margin: 20px auto: with: 500px;heght:200px......">
<img src="imgt/big.jpg" width="500px" height="200px">
</div>

这是css文件

#foto{
position: relative;
margin: 20px auto;
width: 500px;
height: 200px;
padding: 10px;
border: 1px solid #ccc;
background: #eee;
}
#foto:before{
content: "";
position: absolute;
z-index: -1;
left: 10px;
bottom: 15px;
width: 50%;
height: 20%;
box-shadow: 0 15px 10px rgba(0,0,0,0.7);
-webkit-transform: rotate(-3deg);
}
#foto:after{
content: "";
position: absolute;
z-index: -1;
left: 250px;
bottom: 15px;
width: 50%;
height: 20%;
box-shadow: 0px 15px 10px rgba(0,0,0,0.7);
-webkit-transform: rotate(5deg);

最佳答案

您可以像在 div 中使用的那样使用内联样式。但是为什么你需要这样做呢?将 css 保存在单独的文件中始终是更好的做法。

正如 Zenith 所说,您不能在内联样式中使用伪元素。 See this

关于html - 有什么方法可以将 css 放入 html 中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16634051/

上一篇:css - 使用固定宽度的 CSS 获取两个旁边部分以向左浮动

下一篇:html - 将 <div> 移动到内页

相关文章:

html - 确保 div 占据整个视口(viewport)

css - 防止 100vw 创建水平滚动

html - 使图片适合CSS圆圈

html - 如何更改 anchor 标记内 title 属性的样式?

html - 如何设置带边框的 100% 高度的 Div?

html - 如何删除 Bootstrap div 之间的空间

javascript - 如何使 li (事件)并在单击其父 li 时可见

HTML:在选择标签处插入图像

html - Canvas 顶部 <div> 中的文本 - bootstrap

javascript - 如何阻止 iFrame 中的特定代码行?