HTML(网页设计)必用的设计模式---------CSS网页编程

之前介绍了基本的网页设计,但是之前的那个只是一个框框,完全没有美观可言,现在介绍如何修饰以及玩出花样,之前的简单介绍点击打开链接

目录

CSS的基本介绍

CSS的相关语法:

选择器:

1、选择器 一般三种:

2、选择器的优先级  :

多样的伪元素选择器

CSS的盒子模型1

CSS的盒子模型2

CSS的盒子模型3


CSS的基本介绍

简介:CSS是层叠样式表(Cascading Style Sheets)用来定义网页的显示效果。可以解决html代码对样式定义的重复,提高了后期样式代码的可维护性,并增强了网页的显示效果功能。简单一句话:CSS将网页内容和显示样式进行分离,提高了显示功能。那么CSS和HTML是如何在网页代码中相结合的呢?通过四种方式:style属性 、style标签、导入和链接。
1,直接采用style属性:
<!--   html与css相结合的第1种方式:给html标签添加style属性 -->
  	<p style="color: #1f3 ;border:#1ff solid; ">这是我做css网页技术</p>
  2,style标签方式 :
<!-- 	css与html的连接第二种方式     style标签方式  -->
	<style type="text/css">
		p{
		color: #0ff;
		border: 10px solid;
		}	
		
	</style>
3,导入方式 
<style type="text/css">
	/*css和html的连接第三种方式  导入css文件
	*/
		@import url(mycss1.css);
</style>
4,链接方式
<link rel="stylesheet" type="text/css" href="css_3.css" media="screen" />

CSS的相关语法:

CSS代码格式 :
选择器名称 { 属性名:属性值;属性名:属性值;…….}
属性与属性之间用 分号 隔开
属性与属性值直接按用 冒号 连接
如果一个属性有多个值的话,那么多个值用 空格 隔开。

选择器:

就是指定CSS要作用的标签,那个标签的名称就是选择器。意为:选择哪个容器(标签本身就是封装数据的容器)。

1,选择器 一般三种:

1) html标签名选择器。使用的就是html的标签名。
2) class选择器。其实使用的是标签中的class属性。
3) id选择器。其实使用的是标签的中的id属性。
每一个标签都定义了class属性和id属性。用于对标签进行标识,方便对标签进行操作。
在定义的中,多个标签的class属性值可以相同,而id值要唯一,因为JavaScript中经常用。
1, html标签选择器
<style>
			div{
				background: #FF5151;
				font-size: 12px;
			}
</style>
2, class选择器:<在style中以“.”开头的为class选择器,使用时候只需要 class="mm"即可使用>
.mm{
  			color:#00AEAE;
  			font-size: 18px;
}

3, id选择器:<在style中以“#”,开头是的id选择器,使用的时候只需要 id="pid"就可以使用>
#pid{ 
 font-size: 50px;
 color: #2828FF;
 }

2选择器的优先级  :

标签名选择器(远距离统一设置)  <   class选择器(单个设置)  <  id选择器 (单个设置) < style属性(最近距离设置) 
前面介绍的都是简单的,基本的介绍,下面是扩展的:
扩展
关联选择器 :
标签是可以嵌套的,要让相同标签中的不同标签显示不同样式,就可以用此选择器。例如:
p { color:#00FF00;}
p b { color:#FF000;}
<p>P标签<b>湖南城市学院</b>段落样式</p>
<p>P标签段落</p>
组合选择器
对多个选择器进行相同样式的定义。例如,我们想对“div中的<b>标签”和“类名为cc”的区域设置相同的样式,则可以定义如下的组合选择器:  
span b,.cc{
				color: #9F35FF;
				font-style: italic;
			}

多样的伪元素选择器

 

你想 点击 超链接的时候出现不一样的状况吗??你想修饰一下黑白颜色吗?? 伪元素可以帮到你;
简介:
其实就在html中预先定义好的一些选择器,称为伪元素。
格式:标签名:伪元素。类名 标签名。类名:伪元素
超链接a标签中的伪元素:
a:link  超链接未点击状态。
a:visited 被访问后的状态。
a:hover 光标移到超链接上的状态(未点击)。
a:active 点击超链接时的状态。
使用顺序: L – V – H – A
简单的使用:
<!DOCTYPE html>
<html>
  <head>
    <title>lvha.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
	<style>
		div {
			color: #750000;
}
		div f{
			color:#00A600;
		}
		.cc{
			
		}
		
/* 		超链接未点击状态。 */
		<span style="color:#ff0000;">a:LINK </span>{
			color:#00A6ff;
			font-size:18px;
		}
		
		<span style="color:#ff0000;">a:VISITED</span> {
			color: #5B5B5B;
			font-size: 80px;
		}
		/*
		当鼠标移动这里适合,发生相应的反应,光标移到超链接上的状态(未点击)
		*/
		<span style="color:#ff0000;">a:HOVER</span> {
			color: #00DB00;
			font-size:50%;
	}
		/*点击超链接时的状态*/
		<span style="color:#ff0000;">a:ACTIVE</span> {
			color:#FFBD9D;
			background: #00EC00;
			font-size: 80px;
}
		
		
	</style>
  </head>
  <body>
  <a href="http://www.baidu.com" target="new">你好,这是演示</a>
  <div>这是div<f>部</f>>分</div>
  </body>
</html>
效果图:
1.点击前:a:link
2,移到该位置:a:hover
3,点击时候:a:active 点击超链接时的状态
特殊的伪元素:
段落p标签中的伪元素:
p:first-line 段落的第一行文本。
p:first-letter 段落中的第一个字母。
自定义伪元素:
:focus 具有焦点的元素
 div:hover{
    background-color:#f00;
    color:#fff;
 } 

CSS的盒子模型1

边框(border)
上 border-top
下 border-bottom
左 border-left
右 border-right
内补丁(Paddings):内边距
上  padding-top
下  padding-bottom
左  padding-left
右  padding-right
◇外补丁(Margins):外边距
上  margin-top
下  margin-bottom
左  margin-left
右  margin-right

CSS的盒子模型2

☆CSS布局——漂浮 
◇ float : none | left | right
none : 默认值。对象不飘浮
left : 文本流向对象的右边
right : 文本流向对象的左边
◇ clear : none | left | right | both
none :  默认值。允许两边都可以有浮动对象 
left :  不允许左边有浮动对象 
right :  不允许右边有浮动对象 
both :  不允许有浮动对象
<!DOCTYPE html>
<html>
  <head>
    <title>1.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
	<style>
		div{
		width: 300px;
		height: 300px;
		color: #FF44FF;
		background-color: #d3a4ff;
		/*border-style:dotted ; /*整个框都是虚线*/
		border-bottom-style: solid ;
		}
		#div_1{
			margin-bottom: 20px;
			margin-top:30px;
			width: 80px;
		}
		.aa{
			padding-top: 30px;
			padding-bottom: 30px;
			padding-left: 30px;
			background-color: #00A600;
			border-bottom: ridge;
		}
	</style>
  </head>
  
  <body>
   <div>这是第一个div</div>
   <div id="div_1">这是第二个,多加点多检点</div>
   <div class="aa">这是第三个</div>
  </body>
</html>
简单地border使用:padding和Margins
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">
 <img src="https://img-blog.csdn.net/20150924211926055?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
</span>
<html>
  <head>
    <title>cssdemo.html</title>
	<style type="text/css">
		div{
		   border:#09f solid 1px;
		   height: 100px;
		   width: 200px;
		}
		#div_1{
		  border-bottom: #f60 2px dashed;
		}
		
		#div_2{
		  /* margin:20px;   四个方向*/
		  /* margin:20px 100px; 上下20 和 左右100 */
		 /* margin:20px 100px  200px;  上20  , 左右100 ,下200 */
		  margin-left: 30px;
		  margin-top: 25px;
		  padding:20px 50px;
		}
		
		
	</style>
  </head>
  
  <body>
  	<div id="div_1">这是一个div中的文字1</div>
  	<div id="div_2">这是一个div中的文字2多加几个文字多加几个文字多加几个文字多加几个文字多加几个文字........................</div>
  	<div id="div_3">这是一个div中的文字3</div>
  	
  </body>
</html>
<html>
  <head>
    <title>cssdemo.html</title>
	<style type="text/css">
		div{
		   border:#09f solid 1px;
		   height: 100px;
		   width: 200px;
		}
		#div_1{
		    background-color: #f90;
		    float:left;
		}
		
		#div_2{
		background-color: #0cf;
		   float:left;
		}
		
		#div_3{
		   background-color: #3f0;
		   float:left;
		   clear: left;
		}
		
	</style>
  </head>
  
  <body>
  	<div id="div_1">这是一个div中的文字1</div>
  	<div id="div_2">这是一个div中的文字2多加几个文字多加几个文字多加几个文字多加几个文字多加几个文字........................</div>
  	<div id="div_3">这是一个div中的文字3</div>
  	
  </body>
</html>
<html>
  <head>
    <title>cssdemo.html</title>
	<style type="text/css">
		div{
		   border:#09f solid 1px;
		   height: 100px;
		   width: 200px;
		}
		#div_1{
		    background-color: #f90;
		    float:left;
		    position: absolute;
		    top:120px;
		    left:120px;
		}
		
		#div_2{
		background-color: #0cf;
		   float:left;
		   width:300px;
		}
		
		#div_3{
		   background-color: #3f0;
		   float:left;
		   clear: left;
		}
		
		
		#div_4{
		   background-color: #3f0;
		   clear:both;
		   background-color: #f90;
		   position: relative ;
		   top:20px;
		}
		#div_5{
		background-color: #0cf;
		   float:left;
		   width:300px;
		}
		#div_6{
		   background-color: #3f0;
		   float:left;
		   clear: left;
		}
		#div0{
			position: absolute;
		    top:200px;
		    left:200px;
		}
		
	</style>
  </head>
  
  <body>
  	<div id="div_1">这是一个div中的文字1</div>
  	<div id="div_2">这是一个div中的文字2多加几个文字多加几个文字多加几个文字多加几个文字多加几个文字........................</div>
  	<div id="div_3">这是一个div中的文字3</div>
  	<hr>
  	<div id="div0">
	  	<div id="div_4">这是一个div中的文字4</div>
	  	<div id="div_5">这是一个div中的文字5多加几个文字多加几个文字多加几个文字多加几个文字多加几个文字........................</div>
	  	<div id="div_6">这是一个div中的文字6</div>
  	</div>
  	
  	
  </body>
</html>

CSS的盒子模型3

CSS布局——定位
◇ position : static | absolute | fixed | relative 
static :  默认值。无特殊定位,对象遵循HTML定位规则。 
absolute : 将对象从文档流中拖出,使用 left , right , top , bottom 等属性相对于其最接近的一个最有定位设置的父对象进行绝对定位。如果不存在这样的父对象,则依据 body 对象。而其层叠通过 z-index 属性定义。
fixed :  未支持。对象定位遵从绝对(absolute)方式。但是要遵守一些规范。 
relative : 对象不可层叠,但将依据 left , right , top , bottom 等属性在正常文档流中偏移位置。
 
 
 
 
 
 
 
 
 
 
 
 
 
css标签,网页模板/* Author: W3layout Author URL: http://w3layouts.com License: Creative Commons Attribution 3.0 Unported License URL: http://creativecommons.org/licenses/by/3.0/ */ /* reset */ html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,dl,dt,dd,ol,nav ul,nav li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline;} article, aside, details, figcaption, figure,footer, header, hgroup, menu, nav, section {display: block;} ol,ul{list-style:none;margin:0;padding:0;} blockquote,q{quotes:none;} blockquote:before,blockquote:after,q:before,q:after{content:'';content:none;} table{border-collapse:collapse;border-spacing:0;} /* start editing from here */ a{text-decoration:none;} .txt-rt{text-align:right;}/* text align right */ .txt-lt{text-align:left;}/* text align left */ .txt-center{text-align:center;}/* text align center */ .float-rt{float:right;}/* float right */ .float-lt{float:left;}/* float left */ .clear{clear:both;}/* clear float */ .pos-relative{position:relative;}/* Position Relative */ .pos-absolute{position:absolute;}/* Position Absolute */ .vertical-base{ vertical-align:baseline;}/* vertical align baseline */ .vertical-top{ vertical-align:top;}/* vertical align top */ .underline{ padding-bottom:5px; border-bottom: 1px solid #eee; margin:0 0 20px 0;}/* Add 5px bottom padding and a underline */ nav.vertical ul li{ display:block;}/* vertical menu */ nav.horizontal ul li{ display: inline-block;}/* horizontal menu */ img{max-width:100%;} /*end reset*/ body, html { font-size: 100%; height: 100%; } body { font-family:Arial, Helvetica, sans-serif; background:url(../images/bg2.jpg)no-repeat; background-color:#FFF; -webkit-background-size: cover; -moz-background-size: cover; background-size: cover; background-attachment: fixed; background-position:100% center; } .wrap{ width:95%; margin:0 auto; } /***** Header ****/ .header{ border-top:5px solid #111; } .logo{ text-align:center; margin:10px 0; } .menu { text-align:center } .menu li a{ font-size:0.8em; padding:10px; display:block; color:#FFF; text-transform: uppercase; background-color:rgba(70, 70, 70, 0.47); border-bottom: 1px solid rgba(255, 255, 255, 0.08); margin-bottom: 5px; } .menu li a:hover{ background:#222; } .bl-content{ background:rgba(0, 0, 0, 0.58); } .bl-main > section { display:inline-block; width:24%; } .bl-box { position: relative; width: 100%; height: 100%; cursor: pointer; } .bl-box h2 a{ font-family:Verdana, Geneva, Arial, Helvetica, sans-serif; color:#FFF; text-align: center; margin: 0; padding:15px 0; width: 100%; font-size:0.8em; display: block; text-transform: uppercase; background-color:rgba(70, 70, 70, 0.45); } .bl-box h2:hover { background:#222; color:#FFF; } /* Custom content */ .works > ul { list-style: none; padding: 0; margin: 0; } .works > ul li { display: inline-block; width:48.5%; padding:0%; } .works > ul li a { display: block; padding: 0; border:3px solid #FFF; } .works > ul li a img { display: block; max-width: 100%; width:100%; } .works p{ font-size:0.8em; color:#FFF; line-height:1.6em; padding:5px 0; } /* Panel Items */ div.bl-panel-items, div.bl-panel-items > div { width: 100%; height: 100%; } div.bl-panel-items > div > div { margin: 0 auto; opacity: 1; padding:0 10px; } div.bl-panel-items > div > div h3 { font-size:1.2em; color:#000; margin: 0 0 5px 0; } div.bl-panel-items > div > div p { font-size:0.8em; color:#5A5A5C; line-height:1.6em; } div.bl-panel-items > div > div img { float:none; margin:20px 0px 5px 0; max-width: 100%; } div.bl-panel-items { top: 100%; z-index: 9999; } div.bl-panel-items > div { background:rgba(252, 252, 252, 0.760784); } /**** About ***/ .bl-content h2 { font-size:1.2em; color:#FFF; padding: 5px 0; margin-top:20px; text-transform:uppercase; } .about_img img{ padding:2px; background:#FFF; border:1px solid #DBDBDB; margin:5px 0; width:98%; } .about_data p{ font-size:0.9em; color:#FFF; line-height:1.6em; padding:5px 0; } .content_bottom_right { margin-top:80px; padding-bottom:20px; } .posts{ padding:10px 0 20px; border-bottom: 1px dashed #EEE; } .date{ float:left; width:40px; } .posts figure{ font-weight:bold; font-size:10px; color: #FFF; text-align:center; border-right:1px solid #EEE; padding:0 10px 2px 0; } .posts figure span{ font-size:3em; line-height: 52px; color:#F18D05; display:block; margin-bottom:-10px; letter-spacing:-1px; } .post_desc{ float:left; padding-left:4%; width:77%; } .post_desc p{ color:#FFF; font-size:0.9em; line-height:1.6em; } /***** Blog*****/ .image { clear: both; padding: 0px; margin: 0px; padding:10px 0; } .group:before, .group:after { content:""; display:table; } .group:after { clear:both; } .group { zoom:1; } .grid { display: block; float:none; margin: 0% 0 0% 0%; } .grid:first-child { margin-left: 0; } .images_3_of_1 { width:100%; position:relative; margin-bottom:10px; } .blog-leftgrids{ padding-top:10px; } .blog-desc{ width:100%; } .images_3_of_1 img { max-width:100%; display:block; padding:2px; background:#FFF; border:1px solid #FFF; width:98%; } .blog-desc h3{ padding-bottom:5px; } .blog-desc h3 a{ color:#FFF; font-size:0.9em; font-weight:bold; } .blog-desc p { color:#FFF; font-size:0.823em; line-height:1.6em; } /*** Buttons ****/ .button { float:right; font-size:0.9em; text-transform:uppercase; margin-top: 15px; display: inline-block; font-weight: bold; line-height: 18px; padding:8px 10px; background-color: #f18d05; border-color: #bf7004; color: white; } .button:hover { background-color: #f18d05; } .button:active { background: #d8891e; color: #8d5303; } /*----artical-links---*/ .artical-links{ padding: 10px 0px; border: 1px solid rgba(255, 255, 255, 0.19); border-left: none; margin-top: 5px; border-right: none; } .artical-links ul li{ display:inline-block; } .artical-links ul li img{ vertical-align:middle; padding-right:10px; } .artical-links ul li a{ font: 400 14px/22px Arial; color:#F18D05; padding-right: 20px; } .artical-links ul li a:hover{ color:#FFF; } /*** Page numbers ***/ .content-pagenation{ padding:35px 0; } .content-pagenation li { display: inline-block; } .content-pagenation li a { color:#F18D05; font-size: 0.8em; font-family:Verdana, Geneva, Arial, Helvetica, sans-serif; background:#FFF; padding:8px 10px; } .content-pagenation li a:hover{ background:#F18D05; color:#FFF; } /* Contact Form ============================================================================= */ .section { clear: both; padding: 0px; margin: 0px; } .group:before, .group:after { content:""; display:table; } .group:after { clear:both; } .group { zoom:1; } .col{ display: block; float:left; margin: 2% 0 2% 0%; } .col:first-child{ margin-left:0; } .span_2_of_3 { width:100%; padding:0%; } .span_1_of_3 { width:100%; padding:0%; margin-top:10px; } .span_2_of_3 h3, .span_1_of_3 h3 { color:#FFF; font-size:1.5em; margin-bottom:10px; } .contact-form{ position:relative; padding-top:15px; } .contact-form div{ padding:5px 0; } .contact-form span{ display:block; font-size:0.9em; color:#F18D05; padding-bottom:5px; font-family :verdana, arial, helvetica, helve, sans-serif; } .contact-form input[type="text"],.contact-form textarea{ padding:6px; display:block; width:94%; background: rgba(252, 252, 252, 0); border:1px solid rgba(255, 255, 255, 0.38); outline:none; font-size:1.2em; font-family:Arial, Helvetica, sans-serif; color:#FFF; -webkit-appearance:none; } .contact-form textarea{ resize:none; height:120px; } .myButton { text-transform:uppercase; display: inline-block; font-weight: bold; line-height:18px; border:none; background: #465467; color: #fff; font-size:1em; padding:8px 12px; background-color: #f18d05; border-color: #bf7004; cursor:pointer; } .myButton:hover { background-color: #f18d05; } .myButton:active { background: #d8891e; color: #8d5303; } .company_address p{ color:#FFF; font-size:0.9em; line-height:1.8em; } .company_address p span{ text-decoration:underline; color:#EEE; cursor:pointer; } .contact_info{ padding-top:30px; } .map{ border:1px solid #CCC; margin-bottom:10px; } .copy_right{ padding:25px 0 10px 0; text-align:center; font-family:Verdana, Geneva, Arial, Helvetica, sans-serif; } .copy_right p{ font-size:0.8123em; color: #FFF; line-height:1.8em; } .copy_right p a{ color: #FFF; font-size:1em; text-decoration:underline; } .copy_right p a:hover{ color:#FD9200; text-decoration:none; }
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值