首页 > 其他分享 >HTML 13 - Style Sheet

HTML 13 - Style Sheet

时间:2024-05-18 15:42:14浏览次数:23  
标签:13 Sheet rules Style style HTML sheet CSS

 

CSS, or Cascading Style Sheets, is a tool that defines how web documents look on screens or in print. Since its introduction in 1994, the W3C has encouraged the use of style sheets for web design. CSS lets you control the presentation of your content, whether it's on a screen, in print, or for accessibility, making web design more flexible and efficient.

Cascading Style Sheets (CSS) provide easy and effective alternatives to specify various attributes for the HTML tags. Using CSS, you can specify a number of style properties for a given HTML element.

Each property has a name and a value, separated by a colon (:). Each property declaration is separated by a semi-colon (;).

Example

First, let's consider an example of an HTML document that makes use of <font> tag and associated attributes to specify text color and font size −

<!DOCTYPE html>
<html>
<head>
   <title>HTML CSS</title>
</head>
<body>
   <p>
      <font color="green" size="5">Hello, World!</font>
   </p>
</body>
</html>

 

We can re-write the above example with the help of Style Sheet as follows −

<!DOCTYPE html>
<html>
<head>
   <title>HTML CSS</title>
</head>
<body>
   <p style="color:green;font-size:24px;">Hello, World!</p>
</body>
</html>

 

You can use CSS in three ways in your HTML document −

  • External Style Sheet − Define style sheet rules in a separate .css file and then include that file in your HTML document using HTML <link> tag.

  • Internal Style Sheet − Define style sheet rules in the header section of the HTML document using <style> tag.

  • Inline Style Sheet − Define style sheet rules directly along-with the HTML elements using style attribute.

Let's see all three cases one by one with the help of suitable examples.

External Style Sheet

If you need to use your style sheet to various pages, then it’s always recommended to define a common style sheet in a separate file. A cascading style sheet file will have extension as .css and it will be included in HTML files using <link> tag.

Example

Consider we define a style sheet file style.css which has following rules −

.red{
   color: red;
}
.thick{
   font-size:20px;
}
.green{
   color:green;
}

 

Here we defined three CSS rules that will be applicable to three different classes defined for the HTML tags. I suggest you should not bother about how these rules are being defined because you will learn them while studying CSS. Now let's make use of the above external CSS file in our following HTML document −

<!DOCTYPE html>
<html>
<head>
   <title>HTML External CSS</title>
   <link rel="stylesheet" type="text/css" href="/html/style.css">
</head>
<body>
   <p class="red">This is red</p>
   <p class="thick">This is thick</p>
   <p class="green">This is green</p>
   <p class="thick green">This is thick and green</p>
</body>
</html>

 

 

 


 

 

 

Internal Style Sheet

If you want to apply Style Sheet rules to a single document only, then you can include those rules in the header section of the HTML document using <style> tag.

Rules defined in the internal style sheet override the rules defined in an external CSS file.

Example

Let's re-write the above example once again, but here we will write style sheet rules in the same HTML document using <style> tag −

<!DOCTYPE html>
<html>
<head>
   <title>HTML Internal CSS</title>
   <style type="text/css">
      .red {
         color: red;
      }
      .thick {
         font-size: 20px;
      }
      .green {
         color: green;
      }
   </style>
</head>
<body>
   <p class="red">This is red</p>
   <p class="thick">This is thick</p>
   <p class="green">This is green</p>
   <p class="thick green">This is thick and green</p>
</body>
</html>

 

Inline Style Sheet

You can apply style sheet rules directly to any HTML element using the style attribute of the relevant tag. This should be done only when you are interested in making a particular change in any HTML element.

Rules defined inline with the element override the rules defined in an external CSS file as well as the rules defined in <style> element.

Example

Let's re-write the above example once again, but here we will write style sheet rules along with the HTML elements using style attribute of those elements.

<!DOCTYPE html>
<html>
<head>
   <title>HTML Inline CSS</title>
</head>
<body>
   <p style="color:red;">This is red</p>
   <p style="font-size:20px;">This is thick</p>
   <p style="color:green;">This is green</p>
   <p style="color:green;font-size:20px;">This is thick and green</p>
</body>
</html>

 

 

标签:13,Sheet,rules,Style,style,HTML,sheet,CSS
From: https://www.cnblogs.com/emanlee/p/18190423

相关文章

  • HTML 12 - Meta Tags
     HTMLletsyouspecifymetadata,whichisadditionalimportantinformationaboutadocument,inavarietyofways.TheMETAelementscanbeusedtoincludename/valuepairsdescribingpropertiesoftheHTMLdocument,suchasauthor,expirydate,alisto......
  • HTML 11 - Phrase Tags
     Thephrasetagshavebeendesignedforspecificpurposes,thoughtheyaredisplayedinasimilarwayasotherbasictagslike<b>,<i>,<pre>,and<tt>,asyouhaveseeninthepreviouschapter.Thischapterwilltakeyouthrough......
  • HTML 10 - Comments
    HTMLCommentsareusedtocommentinHTMLcodes,sothedevelopercanunderstandthepurposeofthatcodesectionanditishelpfullfordebuggingalso.Ifwearefacingsomeissuebecouseofanyparticularelementwecahcheckitbycommentingoutthate......
  • HTML 09 - Quotations
     QuotationsinHTMLallowyoutoincludeandformatquotedtextwithinyourwebcontent.HTMLprovidestagssuchas<blockquote>,<q>,<cite>,<address>,<bdo>and<abbr>tostructureandstylequotes.Thesetagshelp......
  • PhpSpreadsheet中文文档 | Spreadsheet操作教程实例
    参考:https://blog.csdn.net/jackbon8/article/details/1079406381.导出表格<?phpnamespaceapp#给类文件的命名空间起个别名usePhpOffice\PhpSpreadsheet\Spreadsheet;#Xlsx类将电子表格保存到文件usePhpOffice\PhpSpreadsheet\Writer\Xlsx;......
  • LeetCode 1353. Maximum Number of Events That Can Be Attended
    原题链接在这里:https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended/description/题目:Youaregivenanarrayof events where events[i]=[startDayi,endDayi].Everyevent i startsat startDayi andendsat endDayi.Youcanattend......
  • Codeforces 1113B Sasha and Magnetic Machines 题解
    题目简述有一个长度为$n$的正整数序列。你可以对这个数列进行最多$1$次的如下操作:选择两个数$i$和$j$,其中$1\leqi,j\leqn$并且$i\neqj$,并选择一个可以整除$a_i$的正整数$x$,然后将$a_i$变为$\frac{a_i}{x}$,将$a_j$变为$a_j\cdotx$。问你操作后,该序......
  • 5/13 死神永生服周报创刊号
    目录1.死神永生新用户必读2.死神永生周刊说明死神永生新用户必读你好,欢迎来到死神永生服,也欢迎来看我们服的周报,感谢对我服的支持!如果你是新手,请你抽出一分钟看看我们服务器的基本介绍和一些规则,谢谢。在伟大的Bloxd社区中,有不少中国人创建的服务器,但其中用户很多的......
  • 5/13 死神永生服周报创刊号
    目录1.死神永生新用户必读2.死神永生周刊说明死神永生新用户必读你好,欢迎来到死神永生服,也欢迎来看我们服的周报,感谢对我服的支持!如果你是新手,请你抽出一分钟看看我们服务器的基本介绍和一些规则,谢谢。在伟大的Bloxd社区中,有不少中国人创建的服务器,但其中用户很多的......
  • 139. 单词拆分
    给你一个字符串s和一个字符串列表wordDict作为字典。如果可以利用字典中出现的一个或多个单词拼接出s则返回true。注意:不要求字典中出现的单词全部都使用,并且字典中的单词可以重复使用。示例1:输入:s="leetcode",wordDict=["leet","code"]输出:true解释:返回......