css的应用

一、初入css

行内式:直接在div中加入样式

<div style="width:100px; height:100px; background:red"> hello</div>

内嵌式:在<head>标签中加入<style>标签,在<style>中编写css代码

<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <style type="text/css">
        h3{
        color:red;
        }
    </style>
</head>

外链式:将css代码单独写在.css中,在<head>标签中使用<link>标签引入该文件到页面,可重用性高

<link rel="stylesheet" type="text/css" href="main.css">

二、css选择器

  1. 标签选择器:根据标签去

h1{
  color: blue;
}

2.类选择器:以.开头,点后有类名

<style type="text/css">
         .blue{color:blue}
</style>
 <div class="blue">这是一个div</div>
​

3.层级选择器:根据层级关系去找css样式 div p{} 或者div .span{}

div p {color:red
}
.con span{color:red}
<div>
    <p>
        hello
    </p>
</div>
<div class="con">
    <span>哈哈</span>
</div>
​
层级表达式的嵌套
div .span{
    color:blue
}

4.id选择器:其实和类选择器差不多,但是id是唯一的,只能被使用一次

  #box1{
    color: red;
  }
 <div id="box1"> 美女 </div>

5.组选择器:多个选择器之间共有的放在一起,然后往下增加新的内容

.box1,.box2,.bo3{width:100px,height:100px}
.box1{background}

6.伪类选择器:可以给选择器添加特殊效果,类选择器:伪类名字{}

div{
width: 100px;height: 100px;
}
div:hover{
color:red
width: 200px;height: 200px;
}
<div> haha </div>

三、css布局常用样式属性

  • width

  • height

  • background

    background:url("result@2.png") no-repeat;设置背景图片

  • border:设置边框,border:1px solid black 一像素的实体黑色边框

  • border-top:边框顶部,border-top:10px solid red

  • border-left

  • border-right

  • border-bottorn

  • padding:设置元素包含的内容和元素边框的距离,也叫内边距,如padding:20px;

  • margin:设置元素和外界的距离,外边框

  • float:元素浮动,可以让块元素排列在一行。可以往左浮动,也可以右浮动

div>div*2在div中创建两个子div
​

文本常用样式属性

  • color

  • font-size:字体大小

  • font-family 设置文字的字体

  • font-height 设置文字行高

  • font-weight 设置文字加粗

  • text-align 设置对齐方式

  • text-indent 设置首行缩进

  • text-decoration 设置下划线

四、css元素溢出

overflow(元素溢出)需要在父标签的选择器上进行设置

五、盒子模型

除了设置外边距,其他的都会对盒子大小产生影响。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值