CSS3动态伪类选择器是CSS3的一个重要功能,它可以根据元素的状态、属性或位置等特点为元素设置样式,实现页面的各种效果。/ :hover伪类选择器 / a:hover { color: red; /...
CSS3动态伪类选择器是CSS3的一个重要功能,它可以根据元素的状态、属性或位置等特点为元素设置样式,实现页面的各种效果。
/* :hover伪类选择器 */ a:hover { color: red; /* 鼠标悬浮时改变字体颜色 */ text-decoration: underline; /* 下划线 */ } /* :focus伪类选择器 */ input:focus { background-color: yellow; /* 获得焦点时改变输入框背景颜色 */ border: 2px solid blue; /* 边框样式 */ } /* :checked伪类选择器 */ input[type="checkbox"]:checked + label { color: green; /* 选中时改变label字体颜色 */ font-weight: bold; /* 加粗 */ } /* :nth-child伪类选择器 */ ul li:nth-child(odd) { background-color: lightgrey; /* 奇数行背景颜色 */ } /* :first-child伪类选择器 */ p:first-child { font-weight: bold; /* 加粗第一个段落 */ } /* :not伪类选择器 */ input:not([type="submit"]) { color: blue; /* 非提交按钮改变字体颜色 */ border: 1px solid grey; /* 边框样式 */ } 上述代码片段展示了几种常见的CSS3动态伪类选择器,通过它们的结合使用,我们可以轻松地实现各种样式效果,提高页面的交互性和美观性。