HTML中嵌入css的三种方式

首先需要明确以下几个问题:

1 什么是css?
  Cascadeing style sheet
  层叠样式表
  不属于编程语言
2 css作用是什么?
   css是html的化妆品,可以让html变得更漂亮
   专门用来修饰html的
3 css在哪里编写?
  css代码专门嵌入的html代码中的
  没有html代码,css没有作用
4 当前我们学习的是css2版本,css3将成为主流。
 【css+html5可以完成很多特效】

不多说,先来看第一中方式的代码

<html>
 <head>
  <title>在HTML中嵌入css的第一种方式:内联定义方式</title>
 </head>
 <body>
  <!--
    在html中大部分标签都有style属性,在该属性中设置css的样式
  -->
 <!--
   使用style属性来设置超链接标签的样式,让其有下划线,有鼠标悬停效果手型
 -->
 <!--
   语法格式:<标签 style="样式名:样式值;样式名:样式值;样式名:样式值;"></标签>
 --->
 <a style="text-decoration:underline;color:red;cursor:pointer;">百度</a>
 <!--
    style="cursor:hand; 在IE浏览器中管用,在FF中无效cursor:pointer;表现更好的,兼容性更强"
 -->
 </body>
</html>


       第二种方式:

<html>
 <head>
  <title>在HTML中嵌入css的第二种方式:定义内部样式块对象</title>
  <!--
   在head标签中使用style标签,在style标签中编写css样式
  -->
   
  <style type="text/css">
  /*
    这是css注释
  */
  /*
     标签选择器定义样式
  */
  a{
     cursor:pointer;
	 color:blue;
	 text-decoration:underline;
  }
  /*
   id选择器
  */
   #sina{
     cursor:pointer;
	 color:red;
	 text-decoration:underline;
  } 
  #guge{
     cursor:pointer;
	 color:green;
	 text-decoration:underline;
  }
  .myclass{
		 cursor:pointer;
		 color:yellow;
		 text-decoration:underline;
     }
  /*
   类选择器,样式作用于一类
  */
  </style>
 </head>
 <body>
    <a class=myclass>百度</a>
	<a id="guge">搜狐</a>
	<a class=myclass>邮箱</a>
	<a id="sina">新浪</a>
	<a class=myclass>腾讯</a>
	<a class="myclass">暴风</a>
 </body>
</html>


第三种方式:

<html>
 <head>
  <title>在HTML中嵌入css的第三种方式:嵌入外部样式表文件</title>
  <link rel="stylesheet" href="1.css" type="text/css"/>
  </style>
 </head>
 <body>
    <ul>
	  <li>中国</li>
	  <li>美国</li>
	  <li>英国</li>
	  <li>得国</li>
	</ul>
	<div id=mydiv>
	   我是一个div图层,我是一个独立的单元
	</div>
	<div id=mydiv2>
	   我是一个div图层,我是一个独立的单元
	</div>
 </body>
</html>


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值