css基础

2021-09-09  本文已影响0人  键盘已附魔

类选择器改样式,

<style>

        p {
            color: burlywood;
            font-size: 100px;
        }
        
        .bian {
            color: blue;
        }
        
        .se {
            color: brown;
        }
        
        .long {
            color: chartreuse;
        }
    </style>

</head>

<body>
    <ul >
        <li class="bian">asdfasdf</li>
        <li class="se">asdfasdfasfd</li>
        <li class="long">asdfafa</li>
    </ul>
</body>

类选择器画盒子

 <style>
        .red {
            width: 100px;
            height: 100px;
            background-color: crimson;
        }
        
        .green {
            width: 100px;
            height: 100px;
            background-color: darkgreen;
        }
    </style>
</head>

<body>
    <div class="red">红色</div>
    <div class="green">绿色</div>
    <div class="red">红色</div>

</body>

多类名

给一个标签取多个类名,修改类属性,所有同名标签一起改变,节省代码量

<style>
        .xingqi {
            color: blue;
        }
        
        .zhoumo {
            font-size: 50px;
        }
    </style>

</head>

<body>
    <div class="xingqi">星期一</div>
    <div class="xingqi">星期二</div>
    <div class="xingqi">星期三</div>
    <div class="xingqi">星期四</div>
    <div class="xingqi">星期五</div>
    <div class="xingqi zhoumo">星期六</div>
    <div class="xingqi zhoumo">星期天</div>


</body>

id选择器

类选择器class好比人名,可以和别人重名,可以拥有多名称
ID是身份证号,只能一个人用一个,只能调用一次。

 #yizhou {
            color: chartreuse;
        }
<div id="yizhou">一周</div>

通配符选择器

css字体属性

<style>
        p {
            /* 修改字体 */
            font-family: 'Times New Roman', Times, serif;
            /* 修改文字大小 */
            font-size: 50px;
            /* 字体粗细 */
            /* font-weight: bold; */
            /* 400等于normal,700等于bold */
            font-weight: 700;
            /* 文字样式  斜体*/
            font-style: italic;
            /* 文字不倾斜 */
            font-style: normal;
        }
        /* 组合属性 大小和字体必须有,顺序不能乱 */
        
        div {
            font: italic 700 20px "microsoft yahei";
        }
    </style>
</head>

<body>
    <p>阿斯顿斯蒂芬</p>
    <div>阿斯顿发生发大水</div>
</body>

css 文本属性

<style>
        h1 {
            /* 水平居中 */
            text-align: center;
            /* 装饰文本 */
            text-decoration: underline;
        }
        
        h2 {
            /* 下划线 */
            text-decoration: line-through;
        }
        
        a {
            /* 取消超链接下划线 */
            text-decoration: none;
            color: #333;
        }
        
        p {
            /* 文本缩进,em就是当前文字大小 */
            text-indent: 2em;
            /* 行高 */
            line-height: normal;
        }
    </style>

css引入方式

 <!-- 引用外部样式表 -->
    <link rel="stylesheet" href="引入方式.css">

emmet语法

快速生成html结构语法

输入div,然后tab,生成<div></div>
div3生成三个div
ul>li生成父子标签
dib+p生成一个div一个p标签
带有类名或者id名字的输入.demo和#two,tab键
生成有顺序的div用自增符号,div
5
div内部带有文字,div{有蚊子}

快速生成css样式语法

w200生成weidth:200px;
lh20生成line-height:20px;

后代选择器

<style>
        /* 父元素空格子元素:属性,修改后代属性 */
        
        ol li {
            color: blue;
        }
        
        ol li a {
            color: brown;
        }
    </style>
</head>

<body>
    <ol>
        <li>我是ol的小李</li>
        <li>我是ol的小李</li>
        <li>我是ol的小李</li>
        <li><a href="#">谁是ol的小李</a></li>
    </ol>

子选择器

只能选某元素最近一级子元素

 <style>
        /* 子选择器,只选择亲儿子 */
        
        div>a {
            color: red;
        }
    </style>
</head>

<body>
    <div>
        <a href="#">我是儿子</a>
        <a href="#">我是二儿子</a>
        <p>
            <a href="#">我是孙子</a>
        </p>
    </div>
</body>

并集选择器

 <style>
        div,
        p,
        .pigs li {
            color: red;
            /* 逗号隔开,换行可以一下设置几个不用的标签 */
        }
    </style>
</head>

<body>
    <div>熊大</div>
    <p>熊二</p>
    <span>光头强</span>
    <ul class="pigs">
        <li>佩奇</li>
        <li>乔治</li>
        <li>猪妈妈</li>
        <li>猪爸爸</li>
    </ul>

</body>

伪类选择器

<style>
        a:link {
            /* 未访问的链接是红色 */
            color: brown;
        }
        
        a:visited {
            /* 访问过的链接是黄色 */
            color: burlywood;
        }
        
        a:hover {
            /* 鼠标经过的链接是绿色 */
            color: chartreuse;
        }
        
        a:active {
            /* 鼠标按下还没有弹起的链接 */
            color: cornflowerblue;
        }
    </style>
</head>

<body>
    <a href="#">我是中国人</a>

</body>

focus伪类选择器

<style>
        /* 针对表单元素,选中发生什么变化 */
        input:focus {
            background-color: cyan;
        }
    </style>
</head>

<body>
    <input type="text">
    <input type="text">
    <input type="text">
</body>

css元素显示模式

css背景颜色

 div {
            width: 500px;
            height: 500px;
            /* 背景颜色 */
            background-color: rgb(175, 69, 69);
            /* 背景图片 */
            background-image: url(https://p0.ssl.qhimgs1.com/sdr/400__/t013ff0809aec190204.jpg);
            /* 平铺 */
            background-repeat: no-repeat;
            /* background-repeat: repeat-x; */
            /* background-repeat: repeat-y; */
            /* 背景方位 */
            background-position: center top;
            /* background-position: center right; */
            /* 精确位置 */
            background-position: 20px 50px;
            /* 背景固定还是滚动 */
            background-attachment: fixed;
            /* 复合写法 */
            background: transparent url() repeat-x fixed;
            /* 背景透明度 */
            background: rgba(0, 0, 0, 0.2);
        }

css特性

层叠性
继承性
优先级
选择器权重

<style>
        div {
            color: rgb(231, 41, 41);
        }
        
        p {
            color: rgb(207, 226, 30);
        }
        
        .quan {
            color: rgb(22, 195, 115);
        }
        
        #zhong {
            color: rgb(15, 119, 238) !important;
        }
    </style>
</head>

<body>
    <div>
        <p class="quan" id="zhong" style="color: coral;">
            选择器权重
        </p>
    </div>

</body>

盒子边框属性

div {
            width: 300px;
            height: 200px;
            border-width: 5px;
            /* 虚线边框 */
            border-style: dashed;
            /* 实现边框 */
            border-style: solid;
            /* 点线边框 */
            border-style: dotted;
            /* 边框颜色 */
            border-color: aqua;
            /* 复合写法 */
            border: 5px solid aqua;
            /* 边框可以分开写 */
            border-top: aqua;
            border-right: bisque;
            border-left: #000;
            border-bottom: chartreuse;
            /* 相邻表格边框合并 */
            border-collapse: collapse;
            /* 内边距 padding后面写一个值5,上下左右都是5
            后面写5 10,上下是5,左右是10
            后面写5 10 15,上是5,左右是10,下是15
            后面写5 10 15 20,上右下左*/
            padding-top: 10px;
            padding-left: 12px;
        }
 /* 清除内外边距 */
            * {
                padding: 0;
                margin: 0;
            }
行内元素尽量只设置左右内外边距

圆角矩形

<style>
        .yuanxing {
            height: 200px;
            width: 200px;
            background-color: rgb(44, 224, 215);
            /* 这样就是圆形,半径或者百分比 */
            /* border-radius: 100px; */
            border-radius: 50%;
        }
        
        .yuanjiaojuxing {
            height: 100px;
            width: 300px;
            background-color: rgb(14, 206, 56);
            /* 圆角矩形 */
            border-radius: 50px;
        }
        
        .qita {
            width: 200px;
            height: 200px;
            background-color: rgb(21, 214, 198);
            /* 可以分别设置四个角 */
            border-radius: 10px 20px 30px 40px;
        }
    </style>

盒子影子

<style>
        div {
            width: 200px;
            height: 200px;
            background-color: rgb(24, 175, 24);
            margin: 200px auto;
        }
        /* 鼠标经过添加阴影 */
        
        div:hover {
            /* 水平,垂直,模糊距离,阴影尺寸,阴影颜色, */
            box-shadow: 10px 10px 10px 10px rgba(0, 0, 0, .3);
        }
    </style>

文字阴影

<style>
        div {
            font-size: 1000px;
            color: rgb(56, 197, 51);
            /* 水平阴影,垂直,模糊距离,颜色 */
            text-shadow: 10px 20px 10px rgb(230, 190, 12);
        }
    </style>

浮动

网页布局准则

浮动特性

注意点

清除浮动
给父元素添加属性:
over-flow:hidden
auto,scroll

.box:after {

}

<style>
        .clearfix:after {
            content: "";
            display: block;
            height: 0;
            clear: both;
            visibility: hidden;
        }
        .clearfix {
            /* ie67 */
            *zoom: 1;
        }
    </style>
 .clearfix:before,
        .clearfix:after {
            content: "";
            display: table;
        }
        
        .clearfix:after {
            clear: both;
        }
        
        .clearfix {
            *zoom: 1;
        }

产品类图片用jpg,小动画用gif,透明背景图用png

PS切图

定位

static静态定位,不脱标,不用边偏移
relative相对定位,跟自己原来位置来移动,位置保留,
absolute绝对定位,移动位置相对于祖先元素,没有父元素或者父元素没有定位,则以浏览器为准
不占原来位置
sticky粘性定位,不脱标,浏览器可视区

子绝父相

上一篇 下一篇

猜你喜欢

热点阅读