首页 > 其他分享 >css08 How To Add CSS

css08 How To Add CSS

时间:2024-05-29 21:43:44浏览次数:24  
标签:style sheet color css08 element How Add external CSS

https://www.w3schools.com/css/css_howto.asp

When a browser reads a style sheet, it will format the HTML document according to the information in the style sheet.


Three Ways to Insert CSS

There are three ways of inserting a style sheet:

  • External CSS
  • Internal CSS
  • Inline CSS

External CSS

With an external style sheet, you can change the look of an entire website by changing just one file!

Each HTML page must include a reference to the external style sheet file inside the <link> element, inside the head section.

Example

External styles are defined within the <link> element, inside the <head> section of an HTML page:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="mystyle.css">
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html> 

 


An external style sheet can be written in any text editor, and must be saved with a .css extension.

The external .css file should not contain any HTML tags.

Here is how the "mystyle.css" file looks:

"mystyle.css"

body {
  background-color: lightblue;
}

h1 {
  color: navy;
  margin-left: 20px;
} 

 

Note: Do not add a space between the property value (20) and the unit (px):
Incorrect (space): margin-left: 20 px;
Correct (no space): margin-left: 20px;


   

Internal CSS

An internal style sheet may be used if one single HTML page has a unique style.

The internal style is defined inside the <style> element, inside the head section.

Example

Internal styles are defined within the <style> element, inside the <head> section of an HTML page:

<!DOCTYPE html>
<html>
<head>
<style>
body {
  background-color: linen;
}

h1 {
  color: maroon;
  margin-left: 40px;
}
</style>
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html> 

 



Inline CSS

An inline style may be used to apply a unique style for a single element.

To use inline styles, add the style attribute to the relevant element. The style attribute can contain any CSS property.

Example

Inline styles are defined within the "style" attribute of the relevant element:

<!DOCTYPE html>
<html>
<body>

<h1 style="color:blue;text-align:center;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>

</body>
</html> 

 


Tip: An inline style loses many of the advantages of a style sheet (by mixing content with presentation). Use this method sparingly.


Multiple Style Sheets

If some properties have been defined for the same selector (element) in different style sheets, the value from the last read style sheet will be used. 

Assume that an external style sheet has the following style for the <h1> element:

h1 {
  color: navy;
}

Then, assume that an internal style sheet also has the following style for the <h1> element:

h1 {
  color: orange;   
}

Example

If the internal style is defined after the link to the external style sheet, the <h1> elements will be "orange":

<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<style>
h1 {
  color: orange;
}
</style>
</head> 

 


Example

However, if the internal style is defined before the link to the external style sheet, the <h1> elements will be "navy": 

<head>
<style>
h1 {
  color: orange;
}
</style>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head> 

 



Cascading Order

What style will be used when there is more than one style specified for an HTML element?

All the styles in a page will "cascade" into a new "virtual" style sheet by the following rules, where number one has the highest priority:

  1. Inline style (inside an HTML element)
  2. External and internal style sheets (in the head section)
  3. Browser default

So, an inline style has the highest priority, and will override external and internal styles and browser defaults.

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<style>
body {background-color: linen;}
</style>
</head>
<body style="background-color: lavender">

<h1>Multiple Styles Will Cascade into One</h1>
<p>Here, the background color of the page is set with inline CSS, and also with an internal CSS, and also with an external CSS.</p>
<p>Try experimenting by removing styles to see how the cascading stylesheets work (try removing the inline CSS first, then the internal, then the external).</p>

</body>
</html>

 

标签:style,sheet,color,css08,element,How,Add,external,CSS
From: https://www.cnblogs.com/emanlee/p/18221141

相关文章

  • filebeat配置参数add_kubernetes_metadata
    在Kubernetes集群中,我们可以使用Filebeat来从容器中收集日志,并为每个日志事件添加Kubernetes相关的元数据信息,例如Pod名称、命名空间、标签等。这样我们就可以更好地分析和理解日志数据。filebeat.inputs:-type:containerpaths:-/var/log/containers/*.log......
  • 【CTF Web】CTFShow web13 Writeup(RCE+PHP+通配符)
    web131阿呆彻底呆了,阿呆拿起谷姐搜索好久,终于找到更狠的方法。解法可知flag在config.php。<?php#flaginconfig.phpinclude("config.php");if(isset($_GET['c'])){$c=$_GET['c'];if(!preg_match("/system|exec|highlight|cat|\.|......
  • C# 证件照替换底色与设置背景图---PaddleSegSharp
    PaddleSegSharp 是一个基于百度飞桨PaddleSeg项目的人像分割模块而开发的.NET的工具类库。PaddleSegSharp 中PaddleSeg.dll文件是基于开源项目最新发布版本PaddleSeg PaddleSeg的版本修改而成的C++动态库,基于opencv的x64编译而成的。PaddleSeg是基于飞桨PaddlePaddle的端到端......
  • linux环境开发过程中遇到的问题以及解决办法 how to
    1.装好开发机后上网检查网口是否开通,网线是否正常一般桌面上多个网口可能只开通一个,需要联系IT联系之前可以先找一个正常的网线连到PC看看是否能够提供网络一般从公司内网连接外网需要连接代理检查proxy的可访问性curl-x<proxy_address>:<proxy_port>http://www.example......
  • 提速15%,PaddleOCRSharp新版v4.3发布
    PaddleOCRSharpv4.3版本,已经于5月23日发布。该版本的发布,在不影响识别精度的同时,带来了10%~15%速度的提升。项目地址:https://gitee.com/raoyutian/PaddleOCRSharp项目简介PaddleOCRSharp 作者是广州英田信息科技有限公司的创始人明月心(raoyutian) ,是一个基于百度飞桨Padd......
  • objcopy change-address参数
    在`objcopy`这个GNUBinutils工具中,`--change-address`(或简写为`-R`)参数用于修改输出文件中各个段的起始地址。这在处理二进制镜像(例如U-BootSPL,即SecondaryProgramLoader)时特别有用,因为你可能需要将这些镜像加载到特定的内存地址。具体来说,`--change-address=ADDRESS`参数......
  • 3.1 内存中自动存储—3.4 mov、add、sub 指令
     第3章寄存器(内存访问)在第2章中,我们主要从CPU如何执行指令的角度讲解了8086CPU的逻辑结构、形成物理地址的方法、相关的寄存器以及一些指令。读者应在通过了前一章所有的检测点,并完成了实验任务之后,再开始学习当前的课程。本章中,我们将从访问内存的角度继续学习几个寄......
  • ctfshow web 月饼杯II
    web签到<?php//Author:H3h3QAQinclude"flag.php";highlight_file(__FILE__);error_reporting(0);if(isset($_GET["YBB"])){if(hash("md5",$_GET["YBB"])==$_GET["YBB"]){echo"小伙子不错嘛!!......
  • 宏景eHR showmedia.jsp SQL注入漏洞复现
    0x01产品简介宏景eHR人力资源管理软件是一款人力资源管理与数字化应用相融合,满足动态化、协同化、流程化、战略化需求的软件。0x02漏洞概述宏景eHRshowmedia.jsp接口处存在SQL注入漏洞,未经过身份认证的远程攻击者可利用此漏洞执行任意SQL指令,从而窃取数据库敏感信息。0......
  • 【动手学PaddleX】谁都能学会的基于迁移学习的老人摔倒目标检测
    本项目使用PaddleX搭建目标检测模块,在一个精选的数据集上进行初步训练,并在另一个老年人跌倒检测的数据集上进行参数微调,实现了迁移学习的目标检测项目。1.项目介绍迁移学习是非常有用的方法,在实际生活中由于场景多样,环境复杂,一些场景复杂或者人体姿态不一的数据集较少,因此直......