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

时间:2013-05-19 11:15:43

标签: html css

将css置于html中是否有某种方式?我的意思是例如但选择器如“before:”和“after:”

<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);

}

2 个答案:

答案 0 :(得分:3)

您可以使用内联样式,因为您已经使用了div。但为什么你需要这样做?将css保存在单独的文件中总是更好的做法。

正如Zenith所说,你不能在内联风格中使用伪元素。 See this

答案 1 :(得分:0)

将代码编写在一个单独的文件中总是更好。你可以使用内联样式,但以后编辑或进行一些更改变得很困难。而且因为你非常渴望使用内联样式,所以你不要写将你的代码放在head tag中。这样你的代码就会更清晰,你可以在同一个页面中访问它。你已经在代码中提到了内联样式。所以你已经知道了你的问题的答案。