首页 > 其他分享 >HTML-学习笔记02

HTML-学习笔记02

时间:2022-12-06 12:12:14浏览次数:59  
标签:02 color text 笔记 height HTML background font 选择器

HTML

13、样式器+标签选择器

内部样式表

<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<!-- 内部样式表 -->
		<style>
			/* 标签选择器 */
			h1 {
				width: 960px;
				height: 40px;
				margin: 0 auto;
			}
			/* 类选择器 */	
			.a {
				background-color: red;
			}
			.b {
				background-color: orange;
			}
			.c {
				background-color: yellow;
			}
			.d {
				background-color: green;
			}
			.e {
				background-color: cyan;
			}
			.f {
				background-color: blue;
			}
			.g {
				background-color: purple;
			}
			/* 文本类*/
			.h {
				color: blue;
				text-align: center;
				width: 100px;
				height: 38px;
				overflow: hidden;
			}
			.big{
				font-size: 32px;
			}
			.normal{
				font-size: 24px;
			}
			.small{
				font-size: 12px;
			}
			/* ID 选择器,不同的ID使用相同属性,逗号隔开*/
			/* ID 选择器只给唯一的ID值使用*/
			#header,#footer{
				width: 800px;
				height: 120px;
				border: 1px solid red;
				margin: 10px auto;
			}
			/*通配符选择器*/
			* {
				margin: 0;
				padding: 0;
			}
		</style>
	</head>
	<body>
		<div id='header'>勇往直前</div>
		<h1 class="a"></h1>
		<h1 class="b"></h1>
		<h1 class="c"></h1>
		<h1 class="d"></h1>
		<h1 class="e"></h1>
		<h1 class="f"></h1>
		<h1 class="g"></h1>
		<p class="c h big">相信自己</p>
		<!-- 就近选择最后的 -->
		<p class="d f big">相信自己</p>
		<div id='footer'>回归本真</div>
	</body>
</html>

外部样式表

将所有样式写入style.css文件,

			/* 标签选择器 */
			h1 {
				width: 960px;
				height: 40px;
				margin: 0 auto;
			}
			/* 类选择器 */	
			.a {
				background-color: red;
			}
			.b {
				background-color: orange;
			}
			.c {
				background-color: yellow;
			}
			.d {
				background-color: green;
			}
			.e {
				background-color: cyan;
			}
			.f {
				background-color: blue;
			}
			.g {
				background-color: purple;
			}
			/* 文本类*/
			.h {
				color: blue;
				text-align: center;
				width: 100px;
				height: 38px;
				overflow: hidden;
			}
			.big{
				font-size: 32px;
			}
			.normal{
				font-size: 24px;
			}
			.small{
				font-size: 12px;
			}
			/* ID 选择器,不同的ID使用相同属性,逗号隔开*/
			/* ID 选择器只给唯一的ID值使用*/
			#header,#footer{
				width: 800px;
				height: 120px;
				border: 1px solid red;
				margin: 10px auto;
			}
			/*通配符选择器*/
			* {
				margin: 0;
				padding: 0;
			}

然后在html文件中引用,可以多个地方引用。

	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" href="css/style.css">
	</head>
	<body>
		<h1 class="a big">Hello, World</h1>
	</body>

​ 网页先加载内容,再加载样式表

​ 页面加载一次样式,页面将其缓存,可以重复使用,降低流量消耗

​ 页面风格统一

一般情况,网站首页会使用内部样式表,其他页面可共享一个或多个外部样式表,减少对传输带宽的使用。

内嵌样式表

	<body>
		<!-- 内嵌样式表 / 行内样式表 -->
		<h1 class="a big" style="background-color: green; font-family: 'Courier';text-align: center;">Hello, World</h1>
		<h1 class="a big" style="background-color: rgba(255, 25, 50, 0.5); font-family: 'Courier';text-align: center;">welcome back</h1>
        <h1 class="a big" style="background-color: #ffff00; font-family: 'Courier';text-align: center;">You are the one</h1>
	</body>

样式覆盖规则

不冲突的样式会叠加,冲突的样式遵循一下三原则:

就近原则:同一类型的选择就近

具体原则: ID > class > label

重要原则:!important 比具体更强

	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			#h1{color: blue;}
			.h1{ color: green !important;}
			h1{color: red;}
		</style>
	</head>
	<body>
		<h1 class="h1" id="h1">Awesome</h1>
	</body>

14、文本和字体属性

参考:https://www.runoob.com/cssref/pr-font-font.html

	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			.ms{
				width: 320px;
				height: 100px;
				border: 5px dotted gray;
				line-height: 100px;
				text-align: center;
				margin: 10px auto;
				text-decoration: underline;
				text-shadow: 2px 2px gray;
				font-family: Arial;
				font-size: 300%;
			}
			.h3{
				text-transform: uppercase;
				font: italic bolder 2cm/60px Ariel;
			}
		</style>
	</head>
	<body>
		<h1 class="ms">Test beautiful</h1>
		<h1 class="h3">测试字体</h1>
	</body>

15、边框和轮廓

		<style>
			/* 属性选择器:标签带上属性 */
			/* form input后代选择器,在input前加form,表示只有表单下的标签才使用该属性 */
			/* form>input:儿子选择器 */
			form input[type="text"],form input[type="password"]{
				border: none;
				outline: none;
				border-bottom: 2px dotted darkgray;
			}
			/* form+input相邻兄弟选择器,form~input兄弟选择器 */
			form+input[type="text"]{
				outline: none;
				border: 1px solid lightgray;
			}
			<!-- focus 表示焦点,鼠标选中时使用该样式-->
			form+input[type="text"]:focus{
				outline: none;
				border: 1px solid #00FFFF;
			}
		</style>

16、定位属性

<style>
			.adv{
				width: 200px;
				height: 200px;
				color: red;
				background-color: blue;
				position: fixed;
				right: 50px;
				top: 20px;
			}
            /* position定位:static 静态定位,正常的文档流 */
            /* position定位:fixed 固定定位,相对于浏览器窗口,内容悬浮在固定位置 */
            /* position定位:relative 相对定位,相对于原来正常的位置,移动对应的距离 */
            /* position定位:abusolute 绝对定位,相比于父级元素,移动对应的距离 */
			.p2{
				position: fixed;
				left: 50px;
				top:20px;
			}
</style>

17、表格边框

		<style>
			table{
				border-collapse: collapse;
			}
			td,th{
				border: 1px solid black;
			}
		</style>

标签:02,color,text,笔记,height,HTML,background,font,选择器
From: https://www.cnblogs.com/orange2016/p/16954853.html

相关文章

  • 2020-王谱三套卷-数学一
    2020-王谱3-1T2可以画图解决,\(\displaystyleN=a^2\max_{0<x<a}\{|f^{'}(x)|\}\Rightarrow|f^{'}(x)|\leqslant\dfracN{a^2}\),故\(f(x)\)图像夹在两直线之间,\(M\leqs......
  • 2022年RHCE最新认证
    RHCE认证重要配置信息在考试期间,除了您就坐位置的台式机之外,还将使用多个虚拟系统。您不具有台式机系统的root访问权,但具有对虚拟系统的完整root访问权。系统信息......
  • ES6笔记 - 函数参数扩展 与 箭头函数
    函数的扩展目录函数的扩展1.函数的默认值1.1解构赋值默认值与函数默认值1.2参数默认值的位置2.rest参数3.箭头函数3.1基础用法3.2箭头函数中的this3.3用途1.函......
  • 目前各移动操作系统HTML5支持一览大图
    目前各移动操作系统HTML5支持一览大图,很详细说明小结了目前各移动操作系统对HTML5支持的情况,值得学习:[img]http://dl.iteye.com/upload/attachme......
  • [c++11新特性]02-自动类型推导
    自动类型推导在c++11中,关于类型推导的关键字有using,decltype,auto,typeid。在c++11之前我们要声明一个类型的别名往往使用的是typedef,但是该关键字在模板类型推导中存在一......
  • (转)java爬虫 httpclient htmlunit selenium 比较
    原文链接:https://blog.csdn.net/qq_34661726/article/details/80585659简单介绍。1httpclienthttpclient是HttpClient是ApacheJakartaCommon下的子项目,支持常......
  • 2022【xm格式转不了mp3】教你正确下载喜马拉雅mp3,并优雅获取音频
    喜马拉雅Windows和Mac客户端下载缓存的音频是xm格式,而且限制只可使用该喜马拉雅软件才能打开,而且经过加密的,因此对于电脑小白来说就不要想着解密xm格式的文件了,而且网上基......
  • 2022最新喜马拉雅付费音频下载器,支持专辑批量下载
    喜马拉雅会员FM专辑下载器它可以根据专辑ID批量解析音频列表,并且可以实现免登录一键下载。喜马拉雅VIP专辑下载器1、支持下载免费音频、VIP音频、付费音频。2、VIP音频......
  • 【2022最新教学】喜马拉雅音频提取导出mp3格式并保存到本地
    如何把喜马拉雅下载的音频声音导出来?手机上使用喜马拉雅app收听作品,听到喜欢的作品后,可能想要下载下来,这里介绍下下载方法。喜马拉雅会员FM专辑导出器它可以根据专辑ID......
  • 2022年12月工作资料
    Kafka万亿级消息实战https://mp.weixin.qq.com/s/E7Rq-r7NczlJ7K7ApJDi8g密码学系列之:在线证书状态协议OCSP详解https://blog.csdn.net/superfjj/article/details/1256......