css笔记-选择器 字体 文本 背景

  1. 引入方式
方式name
内部样式表一般放在页面head style里面(嵌入式)
行内样式表标签里面直接写
外部样式表引入外部css link rel href
  1. 选择器分类
选择器类型
标签(元素)选择器p {…}
类选择器class=“xx” .xx{…}
多类名选择器多个类选择器 空格隔开
id选择器#id {…}
通配符选择器所有标签
属性选择器xx[属性或者属性=xxxx]
复合选择器如下
复合选择器作用怎用举例
后代选择器用来选择元素后代选择器 空格 选择器ol li {…}
子代选择器选择最近一级元素只选亲儿子 父元素>子元素.nav>a
交集选择器选择两个标签交集的部分标签点classp.one
并集选择器选择某些相同样式的选择器符号是逗号.nav, .top
链接伪类选择器给链接更改状态a:xxa:link
focus伪类选择器获取焦点的input标签input:focus{xx}input:focus{xx}

注意声明顺序lvha

:link 未访问的链接
:visited 已访问的链接
:hover 鼠标移动到链接上
:active 选定的链接

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        /*标签选择器*/
        p {
            color: aqua;/*分号结尾*/
        }
        /*类选择器注意命名规范*/
        .lei {
            color: red;
        }
        .font {
            font-size: 18px;
        }
        #p_id {
            color: darksalmon;
        }
        * {
            color: red;
        }
    </style>
</head>
<body>
<p>
    css 由选择器与一条或者多条声明组成
    <br/>
    选择器{样式1,2,3,4}
</p>

<p class="lei">
    类选择器
</p>

<p class="lei font">
    多类名选择器空格隔开 公共选择器用得上
</p>
<p id="p_id">
    id 选择器
</p>
  1. 字体
属性备注
font-family字体系列
font-size字号大小 默认16
font-weight字体粗细 400 bold加粗,normal
font-style字体风格normal italic斜体
font复合 顺序 font: font-style font-weight font-size/line-height font-family
  1. 文本
属性备注常用
color文本颜色# 16进制
text-indent文本缩进单位 em /% /px
text-align对齐文本默认 left justify 两端对齐文本效果
text-decoration文本修饰underline 下划线 overline 上划线 line-through 中间,blink 闪烁的文本。
line-height行间距px em %包括上下间距 文本间距
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        p {
            /*字体系列*/
            font-family: "Microsoft YaHei UI","宋体";
            /*字号大小 默认16*/
            font-size: 18px;
            /*字体粗细*/
            font-weight: normal;
            /*font-weight: 400 bold加粗;*/
            /*字体风格normal italic斜体*/
            font-style: normal;
            /*复合:*/
           /* font: font-style font-weight font-size/line-height font-family*/
            font: italic 700 16px '宋体';
        }
        em {
            font-style: italic;
        }
       #color {
           color: red;
           text-align: center;
           text-decoration: underline;
           text-indent: 5em;
           line-height: 4em;
       }
    </style>
</head>
<body>
<p>
    dddd
    多个字体 第一个字体你电脑有没有装有第一个
    <br>
    找不到,用浏览器默认字体
</p>
<em>
    斜体不斜体
</em>
<p id="color">
    文本
</p>
元素常用特点设计宽高注意
块级元素h div ul ol li p等独占一行,
容器可以继续放块级元素和行内元素
可以直接设计wh,
默认宽度容器100%
容器可以继续放块级元素和行内元素,
文字元素里面不可放块级元素如p h内不可div
行内元素span a strong i em del等一行可以多个行内元素,不可直接,
默认宽度本身内容宽度
只能放行内元素或者其他文本元素,
特殊a 可以放块级元素
行内块元素td img input一行可以多个行内块元素可以设置,
默认宽度本身内容宽度

3者转换:

    <style>
        a {
            width: 40px;
            height: 40px;
            display: block;
            background-color: gold;
        }
        div {
            width: 30px;
            height:50px;
            background-color: aqua;
            display: inline;
        }
        span {
            width: 300px;
            height: 100px;
            background-color: aqua;
            display: inline-block;
        }
    </style>
<a href="#">行转块</a>
<div>cc</div>
<div>块转行</div>

<span> 行内——>行内块</span>

侧边栏案例

<head>
    <meta charset="UTF-8">
    <title>小米侧边栏案例</title>
    <style>
        a {
            display: block;
            width: 160px;
            height: 40px;
            background-color: #55585a;
            font-size: 14px;
            color: #ffffff;
            text-decoration: none;
            text-indent: 2em;
            line-height: 40px;
            /*文字垂直居中文字高度等于行高即可*/
        }
        a:hover{
            background-color: #ff6700;
        }
    </style>
</head>
<body>
案例
<a href="#">游戏手机</a>
<a href="#">5G手机</a>
<a href="#">拍照手机</a>
<a href="#">全面屏手机</a>
<a href="#">老人机</a>
<a href="#">对讲机</a>
<a href="#">以旧换新</a>
<a href="#">手机维修</a>
</body>

背景

属性备注常用
b-color背景颜色transparent 默认透明的,
1.有效的颜色名称 - 比如 “red”
2.十六进制值 - 比如 “#ff0000”
3.RGB 值 - 比如 "rgb(255,0,0)"
4.rgba(r,g,b,a)a透明度
opacity不透明度取值范围为 0.0 - 1.0。值越低,越透明
image背景图片url(“path”)
默认情况下,图像会重复,以覆盖整个元素。
repeat背景平铺repeat-x :水平方向重复
repeat-y 垂直方向
position指定背景图像的位置1.x y: LCR top C bottom
2.精确单位 x y px
3.混合单位 1,2 方式混合 如10px top
attachment背景图像是应该滚动还是固定fixed 固定
scroll 滚动的 默认
复合属性简写color-image-repeat-attachment-position

注意:背景图片与背景颜色可以同时设置背景颜色在底层
导航条案例

    <style>
        #nav a {
            display: inline-block;
            width: 120px;
            height: 30px;
            background-color: palegreen;
            /*background-image: url("love.png");*/
            line-height: 30px;
            color: #ffffff;
            text-align: center;
            text-decoration: none;
            background-position: left center;
        }
        #nav #bg1:hover{
            background-color: darkmagenta;
        }
    </style>
</head>
<body>
<div id="nav">
    <a href="#" id="bg1">导航1</a>
    <a href="#" id="bg2">导航2</a>
    <a href="#">导航3</a>
</div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值