CSS伪元素

时间:2020-08-19 19:19:47   收藏:0   阅读:80

CSS伪元素


:first-line 伪元素


<html>
<head>
<style type="text/css">
p:first-line 
{
color: #ff0000;
font-variant: small-caps
}
</style>
</head>
<body>
<p>
浏览器会根据 "first-line" 伪元素中的样式对 p 元素的第一行文本进行格式化:第一行文字设置样式为红色,第二行为默认样式
</p>
</body>
</html>
技术图片

注释:"first-line" 伪元素只能用于块级元素。

注释:下面的属性可应用于 "first-line" 伪元素:


:first-letter 伪元素


<html>
<head>
<style type="text/css">
p:first-letter 
{
color: #ff0000;
font-size:xx-large
}
</style>
</head>
<body>
<p>
第一个文字设置样式
</p>
</body>
</html>
技术图片

注释:"first-letter" 伪元素只能用于块级元素。

注释:下面的属性可应用于 "first-letter" 伪元素:


:before 伪元素


<html>
<head>
<style type="text/css">
h1:before {content:"///////";
           color:red;
           font-size:small;}
</style>
</head>
<body>
<h1>This is a heading</h1>
</body>
</html>
技术图片

:after 伪元素


<html>
<head>
<style type="text/css">
h1:after {content:".......";
           color:red;
           font-size:small;}
</style>
</head>
<body>
<h1>This is a heading</h1>
</body>
</html>
技术图片

伪元素与 CSS 类


<html>
<head>
<style type="text/css">
p.article:first-letter{color: red;}
</style>
</head>
<body>
<p class="article">This is a paragraph in an article。</p>
</body>
</html>
技术图片

多重伪元素


<html>
<head>
<style type="text/css">
p.article:first-line{color: blue;}
p.article:first-letter{color: red;}
p.article:after
  {
  content:".....";
  font-size:xx-large;
  }
</style>
</head>
<body>
<p class="article">This is a paragraph in an article。</p>
</body>
</html>
技术图片

<html>
<head>
<style type="text/css">
p.article:first-line{color: blue;}
p.article:first-letter{color: red;}
p.article:before
  {
  content:"/////";
  font-size:xx-large;
  }
</style>
</head>
<body>
<p class="article">This is a paragraph in an article。</p>
</body>
</html>
技术图片
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!