首页 > 其他分享 >CSS选择器

CSS选择器

时间:2023-11-06 20:25:18浏览次数:33  
标签:bold weight color 元素 font 选择器 CSS

元素选择器

/* 使用元素选择器为所有段落元素应用样式 */
p {
  color: blue;
  font-size: 16px;
  text-align: center;
  margin: 10px;
  padding: 5px;
  background-color: #f0f0f0;
}

类选择器

/* 使用类选择器为具有类名 "important" 的元素应用样式 */
.important {
  font-weight: bold;
  color: red;
  background-color: yellow;
}

ID选择器

/* 使用ID选择器为具有ID "special-paragraph" 的元素应用样式 */
#special-paragraph {
  font-weight: bold;
  color: blue;
  background-color: yellow;
}

后代选择器

/* 使用后代选择器为容器内的段落应用样式 */
.container p {
  font-weight: bold;
  color: blue;
}

/* 使用后代选择器为容器内的列表项应用样式 */
.container ul li {
  list-style-type: square;
}

子选择器

/* 使用子选择器为父元素内的直接子列表项应用样式 */
.parent > li {
  font-weight: bold;
  color: blue;
}

/* 使用子选择器为子元素内的直接子列表项应用样式 */
.child > li {
  list-style-type: square;
}

通配符选择器

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

属性选择器

a[href="https://www.example.com"] {
  text-decoration: none;
  color: #0077b5;
}

伪类选择器

  1. :hover 伪类选择器:选择鼠标悬停在元素上的状态。
a:hover {
  color: red;
  text-decoration: underline;
}
  1. :visited 伪类选择器:选择已访问过的链接。
a:visited {
  color: purple;
}
  1. :first-child 伪类选择器:选择元素的第一个子元素。
li:first-child {
  font-weight: bold;
}

伪元素选择器

  1. ::before 伪元素选择器:在元素的前面插入内容。
p::before {
  content: ">>";
  color: blue;
}
  1. ::after 伪元素选择器:在元素的后面插入内容。
button::after {
  content: " (Click me)";
  color: green;
}
  1. ::first-line 伪元素选择器:选择元素的第一行文本。
p::first-line {
  font-weight: bold;
}

标签:bold,weight,color,元素,font,选择器,CSS
From: https://www.cnblogs.com/shuangyou99/p/css-xuan-ze-qi.html

相关文章

  • CSS让子元素div的高度填满父容器的剩余空间的方法
    原帖:https://pythonjishu.com/unbayyjtzdjeewe/以下是详细讲解CSS让子元素div的高度填满父容器的剩余空间的方法的完整攻略。方法一:FlexboxFlexbox是一种强大的布局方式,使用起来非常方便。可以通过设置父元素的display属性为flex来开启flexbox布局,然后设置子元素的......
  • celery flower通过nginx部署 静态文件css js
    nginx添加以下配置  location/flower{proxy_passhttp://127.0.0.1:5555;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded......
  • 搜索文档树,bs4其它用法,css选择器,selenium基本使用,selenium其它用法
    1搜索文档树......
  • Css 一个选择器实现带你实现高级搜索的展开收起
    在表格页面中,我们经常用到带有展开收起功能的过滤表单,看似很简单的功能,但是实现起来通常不那么优雅。我们使用grid布局来实现这个就非常简单:.search-form{display:grid;grid-template-columns:repeat(4,1fr);grid-gap:10px;&:not(.expend){......
  • css盒子模型: 标准盒子模型和IE盒子模型(怪异盒子模型)
    CSS盒模型(boxmodel),它是包含了内容(content)、内边距(padding)、边框(border)、外边距(margin)属性的一个盒子模型。 而盒模型又分为两类标准:标准盒子模型和IE盒子模型(怪异盒子模型) 在标准盒子模型中,盒子的width是指content的宽高, 而IE盒子模型中就比较怪异了,它包含了......
  • css:元素居中整理水平居中、垂直居中、水平垂直居中
    目录1、水平居中1.1、行内元素1.2、块级元素2、垂直居中2.1、单行文字2.2、多行文字2.3、图片垂直居中3、水平垂直居中参考文章1、水平居中1.1、行内元素行内元素(比如文字,span,图片等)的水平居中,其父元素中设置text-align:center;示例<style>body{background-color:#e......
  • css:transform实现平移、旋转、缩放、倾斜元素
    目录文档语法示例旋转元素transform-rotate旋转过渡旋转动画参考文章文档https://developer.mozilla.org/zh-CN/docs/Web/CSS/transform语法/*Keywordvalues*/transform:none;/*Functionvalues*/transform:matrix(1,2,3,4,5,6);transform:translate(12px,50......
  • css常见的居中操作(一)
    原创声明:本文所有图片和代码皆由本人制作和编写。目录目标当前html毛坯房方法一纯CSS2第0步排版之前的一些css基本设置第1步图标与文字对齐第2步把li居于ul的垂直中部且均匀分布第3步li的子内容水平居中于li方法二使用CSS3的flex第0步排版之前的一些css基本设置第1步图......
  • [CSS]关于<img>标签距离底部盒子5px的问题
     问题描述:在某个盒子内部放入一个<img>标签,不写样式的情况下,<img>总是和父盒子有5px空隙。<!DOCTYPEhtml><html><head><metacharset="utf-8"><title>清除图片多5px问题</title><linkrel="stylesheet"......
  • CSS必学:元素之间的空白与行内块的幽灵空白问题
    作者:WangMin格言:努力做好自己喜欢的每一件事CSDN原创文章博客地址......