CSS:样式

news/2024/10/18 2:40:18/

1. 引入方式

<!--

        方式一:行内式

            通过元素的style属性引入样式

            语法:style="样式1:值; 样式2:值; ... "

            缺点:1.代码复用率低,不利于维护。比如:定义多个相同的按钮要重复书写

                  2.css和html的代码交织一起,不利于阅读,影响文件大小,影响性能

    -->

<input type="button" value="按钮" style="width: 200px;height: 100px;background-color: aqua;font-size: 50px;font-family: 宋体;border: 2px solid greenyellow;" />

 <!--

        方式二:内嵌式

            通过在head标签中的style标签定义本页面的共用元素的样式

            通过选择器选择作用的元素(即在哪些元素有效)

    -->

<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><!--在head标签中定义--><style>/*元素选择器,通过标签名确定在哪些元素上生效*/input{width: 100px;height: 100px;font-size: 500;font-family: 微软雅黑;border: 5px solid red;background-color: rgb(0, 255, 179);border-radius: 5px;}</style>
</head><body><input type="button" value="小按钮" /><input type="button" value="小按钮" /><input type="button" value="小按钮" /><input type="button" value="小按钮" />
</body>

<!--

        方式三:外部引入

            将css代码放到一个文件中,哪个html文件需要用到就在头标签中使用link引用

                href:从哪个资源文件中引入

                rel: 相关参数(如:stylesheet)

    -->

<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><!--在当前页面引入其他文件的css代码,href哪个资源 rel=引入style的代码需要stylesheet--><link href="css/引入方式.css" rel="stylesheet"> 
</head>

 2. 选择器

<!--

            选择器一:标签名定义选择器

                语法:标签名{}

                缺点:某个按钮不想要里面的某个功能却不能修改,只能重新定义,代码冗余

    -->

<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>input{/*字体、颜色、大小*/font-size: 30px;font-family: '宋体';color: rgb(18, 222, 100);background-color: aqua;border: 2px solid red;width: 100px;height: 100px;}</style>
</head>
<body><input type="button" value="按钮" /><input type="button" value="按钮" />
</body>

<!--

        选择器二:根据标签的id名定义选择器

            语法:#id名

            缺点:id一般唯一,根据id定义只能有一个元素符合

    -->

<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>#niubi{/*字体、颜色、大小*/font-size: 30px;font-family: '宋体';color: blueviolet;background-color: blanchedalmond;border: 3px solid red;width: 100px;height: 100px;}</style>
</head>
<body><input type="button" id="niubi" value="方式二" />
</body>

<!--

        选择器三:根据元素的属性值确定class的样式

                一个元素可以有多个class值, 一个class样式可以被多个元素使用

            语法:.class{}

    -->

<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.fontClass{font-size: 50px;font-family: '楷书';}.colorClass{color: black;background-color: blue;}.sizeClass{width: 300px;height: 200px;}</style></head>
<body><input type="button" id="but1" class="fontClass colorClass sizeClass" value="方式三" /></body>

3. 浮动、定位

 <!--

        浮动:float(浮动直接移动到框边界最左、右、上、下侧,无法精确定位)

        定位:

        position

            static   默认

            absolute 绝对:相对于浏览器界面进行位置定位

            relative 相对:相对于元素原本的位置进行定位

            fixed    相对:相对于浏览器窗口进行位置定位

                (如:position: fixed;

                     top:30px; left:30px;

                此时滑动浏览器界面但是该区域块仍保持在当前界面离顶部30,左边30像素的位置)

        left

        right

        top

        bottom

    -->

<head><style>.but1{border: 3px solid rebeccapurple;background-color: aqua;//定位方式为:fixedposition: fixed;//距离浏览器窗口顶部的边界30个像素top: 30px;//距离浏览器窗口最左侧的边界30个像素left: 30px;}</style>
</head>

 4. 盒子模型

<!--设置一个界面,里面包含三个小界面-->

    <!--

        设置外边距:margin

        设置内边距:padding

        边距的设置不会影响盒子的空间大小。如:设置一个盒子的外边距为10px,则盒子界限外的10个像素的空间

        内外边距的距离会以盒子的边界为线向内或者向外扩张

    -->

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style> .outDiv {width: 500px;height: 500px;background-color: antiquewhite;}.inDiv {float: left;}.font {font-size: 30px;font-family: '宋体';}.size {width: 100px;height: 100px;}.d1 {border: 2px solid;background-color: aqua;/*设置外边距的距离*/margin-right: 10px;margin-left: 20px;margin-top: 30px;padding-left: 10px;padding-top: 40px;}.d2 {border: 2px solid green;background-color: rgb(205, 123, 23);/*设置外边距的距离*/margin-left: 10px;}.d3 {border: 2px solid blue;background-color: blueviolet;/*若不指定方向则默认上下左右边距为10个像素*/margin: 10px;}</style>
</head>
<body><div class="outDiv"><div class="inDiv font size d1">div1</div><div class="inDiv font size d2">div2</div><div class="inDiv font size d3">div3</div></div>
</body>


http://www.ppmy.cn/news/1401887.html

相关文章

http 超全状态码

HTTP&#xff08;超文本传输协议&#xff09;是一种用于传输超文本的应用层协议。在进行HTTP通信时&#xff0c;服务器会向客户端返回一个状态码&#xff0c;用于表示请求的处理结果。 状态码由3位数字组成&#xff0c;使用第1个数字表示响应的类别&#xff0c;一共5种&#x…

pytest--python的一种测试框架--request请求加入headers

一、request headers中的cookie和session机制的作用与区别 Cookie 和 Session 是两种在客户端和服务器之间保持状态的技术。HTTP 协议本身是无状态的&#xff0c;这意味着服务器无法从上一次的请求中保留任何信息到下一次请求。Cookie 和 Session 机制就是为了解决这个问题。 …

uniapp微信小程序消息订阅详解

一、微信公众平台申请订阅模板 注意&#xff1a;订阅信息 这个事件 是 当用户 点击的时候触发 或者 是 支付成功后触发&#xff0c; 用户勾选 “总是保持以上选择&#xff0c;不再询问” 之后或长期订阅&#xff0c;下次订阅调用 wx.requestSubscribeMessage 不会弹窗&#xf…

CrossOver软件2024免费 最新版本详细介绍 CrossOver软件好用吗 Mac电脑玩Windows游戏

CrossOver是一款由CodeWeavers公司开发的软件&#xff0c;它可以在Mac和Linux等操作系统上运行Windows软件&#xff0c;而无需在计算机上安装Windows操作系统。这款软件的核心技术是Wine&#xff0c;它是一种在Linux和macOS等操作系统上运行Windows应用程序的开源软件。 Cross…

牛角工具箱源码 轻松打造个性化在线工具箱

&#x1f389; Whats this&#xff1f; 这是一款在线工具箱程序&#xff0c;您可以通过安装扩展增强她的功能 通过插件模板的功能&#xff0c;您也可以把她当做网页导航来使用~ 觉得该项目不错的可以给个Star~ &#x1f63a; 演示地址 https://tool.aoaostar.com &#x1f…

GET 与 POST(计算机网络)

GET &#xff1a;从服务器获取指定的资源。 POST &#xff1a;根据请求负荷&#xff08;报文body&#xff09;对指定的资源做出处理。 GET 和 POST 方法都是安全和幂等的吗&#xff1f; 在 HTTP 协议里安全和幂等的概念&#xff1a; 「安全」&#xff1a;请求方法不会「破坏」…

acwing算法提高之图论--单源最短路的扩展应用

目录 1 介绍2 训练 1 介绍 本专题用来记录使用。。。。 2 训练 题目1&#xff1a;1137选择最佳线路 C代码如下&#xff0c; #include <iostream> #include <cstring> #include <algorithm> #include <queue>using namespace std;const int N 101…

FPGA之状态机学习

作为一名逻辑工程师&#xff0c;掌握和应用状态机设计是必不可少的。能够灵活的应用状态机是对逻辑工程师最基本的要求&#xff0c;状态机设计的好坏能够直接影响到设计系统的稳定性&#xff0c;所以学会状态机是非常的重要。 1.状态机的概念 状态机通过不同的状态迁移来完成特…