CSS3案例—学成在线

要点:

1.直接只用<header><nav>等CSS3新标签

2.使用新的盒子模型border-box内减式模型,不用再来回设置盒子大小

3.过渡效果和动画效果的联合使用,不考虑兼容

base.css

*{
	box-sizing: border-box;
	/*全部定义为内减式盒子模型*/
}
a{
	text-decoration: none;
}
body{
	background-color: #F7F4F4;
}
li{
	margin: 0;
	padding: 0;
	list-style: none;
}
img{
	border: 0;
	vertical-align: middle;
	/*主要是为了解决图片和文字之间的垂直居中问题*/
}
.w{
	width: 1200px;
	margin: auto;
}

@font-face {
  font-family: 'icomoon';
  src:  url('../fonts/icomoon.eot?rsc7tj');
  src:  url('../fonts/icomoon.eot?rsc7tj#iefix') format('embedded-opentype'),
    url('../fonts/icomoon.ttf?rsc7tj') format('truetype'),
    url('../fonts/icomoon.woff?rsc7tj') format('woff'),
    url('../fonts/icomoon.svg?rsc7tj#icomoon') format('svg');
  font-weight: normal;
  font-style: normal;
}
/*引入字体图标,一定要注意调用fonts文件夹路径一定要正确*/
.mySyllabus dl,.mySyllabus dd,.mySyllabus dt{
	padding: 0;
	margin: 0;
}
.mySyllabus h5,.mySyllabus a,.mySyllabus ul,.mySyllabus li{
	padding: 0;
	margin: 0;
}
.pro-bd li,.pro-bd ul{
	margin: 0;
	padding: 0;
}

normalize.css(不好用,建议下次直接使用京东小米的,放在最后)

index.css代码:

header{
	width: 1300px;
	height: 100px;
	margin: 0 auto;
	padding-top: 30px;
	/*如果是传统盒子的模型,盒子会变大,就要回去将盒子宽高定义的小一点
	在base中将所有的元素定义为内减式的盒子模型*/
}
.logo{
	width: 195px;
	height: 42px;
	float: left;
}
.logo a{
	display: block;
	width: 195px;
	height: 42px;
	background: url(../img/logo.png) no-repeat;
	text-indent: -999px;
	overflow: hidden;
	/*怕屏幕页面缩小会暴露出来*/
}

nav{
	float: left;
}
nav li{
	float: left;
	height: 40px;
	line-height: 40px;
	margin-left: 25px;
}
nav li a{
	display: block;
	height: 40px;
	font-size: 18px;
	padding: 0 10px;
	color: #000;
}
nav li a:hover{
	border-bottom: 2px solid #00a4ff; 
}

.search{
	width: 410px;
	height: 40px;
	float: left;
	margin-left: 80px;
	padding-top: 18px;
}
.search input{
	width: 361px;
	height: 40px;
	border: 1px solid #00a4ff;
    outline: none;
    padding-left: 10px;
    float: left;
}
.search button{
	width: 49px;
	height: 40px;
	border: 0;
	outline: none;
	float: left;
	background: url(../img/fa-search.png) no-repeat;
}

.personal{
	float: right;
	height: 40px;
	line-height: 40px;
}
.personal dt,.personal dd{
	float: left;
}
.personal s{
	position: relative;
	padding-right: 30px;
}
.personal s::before{
	content: "";
	display: block;
	position: absolute;
	/*这两步基本是必备的选项,因为伪元素默认
	是行内的元素,如果要插入一些东西。需要这两个*/
	width: 6px;
	height: 6px;
	right: 13px;
	top: 0;
	background-color: red;
	border-radius: 50%;
}
.personal span img{
	border-radius: 50%;
}


/*顶部通栏模块*/


.banner{
	height: 420px;
	background-color: #1c036c;
}
.inner{
	height: 420px;
	position: relative;
}
.subnav{
	position: absolute;
	left: 0;
	top: 0;
	height: 100%;
	width: 190px;
	background: rgba(0,0,0,.2);
	padding-top: 20px;
}
.subnav a{
	font-size: 14px;
	color: #fff;
}
.subnav li{
	position: relative;
	display: block;
}
.subnav i{
	font-family: "icomoon";
	color: #fff;
	font-style: normal;
	font-size: 14px;
	line-height: 14px;
	position: absolute;
	top: 0;
	right: 20px;
}
.subnav ul li a:hover{
	color: #00b4ff;
}
/*侧边栏模块*/

.circle{
	width: 176px;
	height: 20px;
	position: absolute;
	left: 50%;
	/*margin-left: -88px;*/
	transform: translate(-50%);
	/*上面注释需要自己计算,这样就水平向左移动了自己盒子的一半
	第二个垂直属性不写,其默认为0*/
	bottom: 15px;
}
.circle i {
	display: inline-block;
	width: 13px;
	height: 13px;
	background: rgba(255,255,255,.4);
	margin: 0 5px;
	border-radius: 50%;
	/*高度的50%如果是正方形,可以形成圆*/
	transition: all 0.4s;
}
.circle .current, i:hover{
	width: 20px;
    border-radius: 6px;
    /*这里直接写50%会成椭圆,直接定义为高度的一半,可以形成圆角*/
    background-color: #fff;
}
/*侧边栏模块*/

.mySyllabus{
	width: 228px;
	height: 300px;
	position: absolute;
	right: 0;
	top: 50%;
	transform:translateY(-50%);
	background-color: #fff;
}
.mySyllabus dl dt{
    height: 50px;
    background-color: #9bceea;
    font-weight: 700;
    color: #fff;
    line-height: 50px;
    font-size: 18px;
    text-align: center;
}
.mySyllabus dd{
    padding: 15px 20px 0;
}
.mySyllabus dd li{
	height: 60px;
	border-bottom: 1px solid #ccc;
	padding-top: 6px;
}
.mySyllabus dd li:last-child{
	border: 0;
}
.mySyllabus h5{
	font-size: 15px;
	font-weight: normal;
}
.mySyllabus p{
    font-size:12px;
}
.mySyllabus .all{
	height: 40px;
	border: 1px solid #22b0ff;
	color: #22b0ff;
	display: block;
	text-align: center;
	line-height: 40px;
	font-size: 18px;
}
.mySyllabus .all:hover{
	background-color: #22b0ff;
	color: #fff;
}


/*导航栏模块*/

.recommend{
	margin-top: 10px;
	height: 60px;
	line-height: 60px;
	position: relative;
	background-color: #fff;
	box-shadow: 0px 1px 12px rgba(0,0,0,.4);
	/*阴影非常不好调,可以先在浏览器中,用开发工具写
	边试边看效果*/
}
.rec-1{
	padding-left: 30px;
}
.rec-1 a{
    color: #000;
	margin: 0 15px;
	font-size: 14px;
}
.rec-1 a:hover{
	color: #22b0ff;
}
.rec-1 a:first-child{  
	color: #22b0ff;
	font-size: 14px;
	margin-right: 15px;
}
.recommend em{
	position: absolute;
	right: 56px;
	bottom: 0;
	font-style: normal;
	color: #22b0ff;
}

.pro-hd{
	height: 40px;
	position: relative;
}
.pro-hd h4{
	font-weight: normal;
	font-size: 18px;
}
.pro-hd a{
	position: absolute;
	top: 0;
	right: 20px;
}
.pro-bd li{
	width: 228px;
	height: 270px;
	float: left;
	margin-right: 15px; 
	margin-bottom: 15px;
	background-color: #fff;
	overflow: hidden;
	/*隐藏超出盒子部分的图片*/
}
.pro-bd li:hover{
	box-shadow: 2px 2px 10px rgba(0,0,0,.3);
	transform: translateY(-5px);
}

.pro-bd li:nth-child(5n){
	margin-right: 0;
}
/*nth-child(5n)里面这种是表达式,筛选出*5的倍数子孩子*/

.pro-title{
	width: 185px;
	margin: 20px auto 16px;
	font-size: 14px;
	color: #050505;
}
.pro-bd p{
	width: 185px;
	margin: 0 auto;
	color: #999;
}
.pro-bd p span{
    color: #ff7c2d;
}
.pic img{
	transition: all 0.4s;
}
.pic img:hover{
	margin-left: -5px;
}
/*为选中图片之后添加动画,那个元素变化,将过渡给那个元素*/

html代码:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>学成在线教育平台——愿每个认真坚持的学子学有所成</title>
	<link rel="stylesheet" type="text/css" href="css/normalize.css">
	<link rel="stylesheet" type="text/css" href="css/base.css">
	<link rel="stylesheet" type="text/css" href="css/index.css">
	<link rel="shortcut icon" href="favicon.ico">
	<!-- 注意rel代表的是引入的类型,字体图标格式-->
</head>
<body>
	<header>
		<div class="logo">
			<h1><a href="#"></a></h1>
		</div>
		<nav>
			<ul>
				<li><a href="#">首页</a></li>
				<li><a href="#">课程</a></li>
				<li><a href="#">职业规划</a></li>
			</ul>
		</nav>

		<div class="search">
			<input type="search" placeholder="请输入关键字">
			<button></button>
		</div>
		<div class="personal">
			<dl>
				<dt>个人中心</dt>
				<dd>
					<s><img src="img/ld.png"></s>
					<span>
						<img src="img/pic.png">
						rainbow
					</span>
				</dd>
			</dl>
		</div>
	</header>
	<!-- 头部通栏模块 -->

	<div class="banner">
		<div class="w inner">
			<ul>
				<li><a href="#"><img src="img/banner.jpg"></a></li>
			</ul>
			<div class="subnav">
				<ul>
					<li><a href="#">前端开发<i></i></a></li>
				</ul>
				<ul>
					<li><a href="#">后端开发</a><i></i></li>
				</ul>
				<ul>
					<li><a href="#">移动开发</a><i></i></li>
				</ul>
				<ul>
					<li><a href="#">人工智能</a><i></i></li>
				</ul>
				<ul>
					<li><a href="#">商业预测</a><i></i></li>
				</ul>
				<ul>
					<li><a href="#">云计算&大数据</a><i></i></li>
				</ul>
				<ul>
					<li><a href="#">运维&测试</a><i></i></li>
				</ul>
				<ul>
					<li><a href="#">UI设计</a><i></i></li>
				</ul>
				<ul>
					<li><a href="#">JAVA</a><i></i></li>
				</ul>
				<ul>
					<li><a href="#">PYHTON</a><i></i></li>
				</ul>
				<ul>
					<li><a href="#">数据结构</a><i></i></li>
				</ul>
			</div>

			<div class="circle">
				<i class="current"></i>
				<i></i>
				<i></i>
				<i></i>
				<i></i>
				<i></i>
			</div>
			<div class="mySyllabus">
				<dl>
					<dt>我的课程表</dt>
					<dd>
						<ul>
							<li>
								<h5>继续学习 程序语言设计</h5>
								<p>上次学到-没有对象</p>
							</li>
							<li>
								<h5>继续学习 数据库详解</h5>
								<p>上次学到-删库跑路</p>
							</li>
							<li>
								<h5>继续学习 Linx基础</h5>
								<p>上次学到-半截入土</p>
							</li>
						</ul>
						<a href="#" class="all">全部课程</a>
					</dd>
				</dl>
			</div>
		</div>
	</div>
	<!-- 导航栏模块 -->

    <div class="recommend w">
    	<div class="rec-1">
    		<a href="#">精品推荐</a>|
    		<a href="#">jQuery</a>|
    		<a href="#">Spark</a>|
    		<a href="#">MySQL</a>|
    		<a href="#">JavaWeb</a>|
    		<a href="#">Bootstrap</a>|
    		<a href="#">Node</a>
    	</div>
    	<em>修改选修课程</em>
    </div>

    <div class="products w">
    	<div class="pro-hd">
    		<h4>精品推荐</h4>
    		<a href="#">查看全部</a>
    	</div>
    	<div class="pro-bd">
    		<ul>
    			<li>
    				<div class="pic">
    					<img src="img/hotpic.png">
    				</div>
    				<div class="pro-title">
    					Think PHP 5.0 博客系统实战项目训练 
    				</div>
    				<p>
    					<span>高级</span> * 1125人在学   
    				</p>
    			</li>
    			<li>
    				<div class="pic">
    					<img src="img/tuijianpic.png">
    				</div>
    				<div class="pro-title">
    					Think PHP 5.0 博客系统实战项目训练 
    				</div>
    				<p>
    					<span>高级</span> * 1125人在学   
    				</p>
    			</li>
    			<li>
    				<div class="pic">
    					<img src="img/tuijianpic.png">
    				</div>
    				<div class="pro-title">
    					Think PHP 5.0 博客系统实战项目训练 
    				</div>
    				<p>
    					<span>高级</span> * 1125人在学   
    				</p>
    			</li>
    			<li>
    				<div class="pic">
    					<img src="img/tuijianpic.png">
    				</div>
    				<div class="pro-title">
    					Think PHP 5.0 博客系统实战项目训练 
    				</div>
    				<p>
    					<span>高级</span> * 1125人在学   
    				</p>
    			</li>
    			<li>
    				<div class="pic">
    					<img src="img/tuijianpic.png">
    				</div>
    				<div class="pro-title">
    					Think PHP 5.0 博客系统实战项目训练 
    				</div>
    				<p>
    					<span>高级</span> * 1125人在学   
    				</p>
    			</li>
    			<li>
    				<div class="pic">
    					<img src="img/hotpic.png">
    				</div>
    				<div class="pro-title">
    					Think PHP 5.0 博客系统实战项目训练 
    				</div>
    				<p>
    					<span>高级</span> * 1125人在学   
    				</p>
    			</li>
    			<li>
    				<div class="pic">
    					<img src="img/tuijianpic.png">
    				</div>
    				<div class="pro-title">
    					Think PHP 5.0 博客系统实战项目训练 
    				</div>
    				<p>
    					<span>高级</span> * 1125人在学   
    				</p>
    			</li>
    			<li>
    				<div class="pic">
    					<img src="img/tuijianpic.png">
    				</div>
    				<div class="pro-title">
    					Think PHP 5.0 博客系统实战项目训练 
    				</div>
    				<p>
    					<span>高级</span> * 1125人在学   
    				</p>
    			</li>
    			<li>
    				<div class="pic">
    					<img src="img/tuijianpic.png">
    				</div>
    				<div class="pro-title">
    					Think PHP 5.0 博客系统实战项目训练 
    				</div>
    				<p>
    					<span>高级</span> * 1125人在学   
    				</p>
    			</li>
    			<li>
    				<div class="pic">
    					<img src="img/tuijianpic.png">
    				</div>
    				<div class="pro-title">
    					Think PHP 5.0 博客系统实战项目训练 
    				</div>
    				<p>
    					<span>高级</span> * 1125人在学   
    				</p>
    			</li>	
    		</ul>
    	</div>
    </div>
</body>
</html>

效果:

/*! normalize.css v5.0.0 | MIT License | github.com/necolas/normalize.css */
/*
http://necolas.github.io/normalize.css/
*/
/**
 * 1. Change the default font family in all browsers (opinionated).
 * 2. Correct the line height in all browsers.
 * 3. Prevent adjustments of font size after orientation changes in
 *    IE on Windows Phone and in iOS.
 */

/* Document
   ========================================================================== */

html {
    font-family: sans-serif; /* 1 */
    line-height: 1.15; /* 2 */
    -ms-text-size-adjust: 100%; /* 3 */
    -webkit-text-size-adjust: 100%; /* 3 */
}

/* Sections
   ========================================================================== */

/**
 * Remove the margin in all browsers (opinionated).
 */

body {
    margin: 0;
}

/**
 * Add the correct display in IE 9-.
 */

article,
aside,
footer,
header,
nav,
section {
    display: block;
}

/**
 * Correct the font size and margin on `h1` elements within `section` and
 * `article` contexts in Chrome, Firefox, and Safari.
 */

h1 {
    font-size: 2em;
    margin: 0.67em 0;
}

/* Grouping content
   ========================================================================== */

/**
 * Add the correct display in IE 9-.
 * 1. Add the correct display in IE.
 */

figcaption,
figure,
main { /* 1 */
    display: block;
}

/**
 * Add the correct margin in IE 8.
 */

figure {
    margin: 1em 40px;
}

/**
 * 1. Add the correct box sizing in Firefox.
 * 2. Show the overflow in Edge and IE.
 */

hr {
    box-sizing: content-box; /* 1 */
    height: 0; /* 1 */
    overflow: visible; /* 2 */
}

/**
 * 1. Correct the inheritance and scaling of font size in all browsers.
 * 2. Correct the odd `em` font sizing in all browsers.
 */

pre {
    font-family: monospace, monospace; /* 1 */
    font-size: 1em; /* 2 */
}

/* Text-level semantics
   ========================================================================== */

/**
 * 1. Remove the gray background on active links in IE 10.
 * 2. Remove gaps in links underline in iOS 8+ and Safari 8+.
 */

a {
    background-color: transparent; /* 1 */
    -webkit-text-decoration-skip: objects; /* 2 */
}

/**
 * Remove the outline on focused links when they are also active or hovered
 * in all browsers (opinionated).
 */

a:active,
a:hover {
    outline-width: 0;
}

/**
 * 1. Remove the bottom border in Firefox 39-.
 * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
 */

abbr[title] {
    border-bottom: none; /* 1 */
    text-decoration: underline; /* 2 */
    text-decoration: underline dotted; /* 2 */
}

/**
 * Prevent the duplicate application of `bolder` by the next rule in Safari 6.
 */

b,
strong {
    font-weight: inherit;
}

/**
 * Add the correct font weight in Chrome, Edge, and Safari.
 */

b,
strong {
    font-weight: bolder;
}

/**
 * 1. Correct the inheritance and scaling of font size in all browsers.
 * 2. Correct the odd `em` font sizing in all browsers.
 */

code,
kbd,
samp {
    font-family: monospace, monospace; /* 1 */
    font-size: 1em; /* 2 */
}

/**
 * Add the correct font style in Android 4.3-.
 */

dfn {
    font-style: italic;
}

/**
 * Add the correct background and color in IE 9-.
 */

mark {
    background-color: #ff0;
    color: #000;
}

/**
 * Add the correct font size in all browsers.
 */

small {
    font-size: 80%;
}

/**
 * Prevent `sub` and `sup` elements from affecting the line height in
 * all browsers.
 */

sub,
sup {
    font-size: 75%;
    line-height: 0;
    position: relative;
    vertical-align: baseline;
}

sub {
    bottom: -0.25em;
}

sup {
    top: -0.5em;
}

/* Embedded content
   ========================================================================== */

/**
 * Add the correct display in IE 9-.
 */

audio,
video {
    display: inline-block;
}

/**
 * Add the correct display in iOS 4-7.
 */

audio:not([controls]) {
    display: none;
    height: 0;
}

/**
 * Remove the border on images inside links in IE 10-.
 */

img {
    border-style: none;
}

/**
 * Hide the overflow in IE.
 */

svg:not(:root) {
    overflow: hidden;
}

/* Forms
   ========================================================================== */

/**
 * 1. Change the font styles in all browsers (opinionated).
 * 2. Remove the margin in Firefox and Safari.
 */

button,
input,
optgroup,
select,
textarea {
    font-family: sans-serif; /* 1 */
    font-size: 100%; /* 1 */
    line-height: 1.15; /* 1 */
    margin: 0; /* 2 */
}

/**
 * Show the overflow in IE.
 * 1. Show the overflow in Edge.
 */

button,
input { /* 1 */
    overflow: visible;
}

/**
 * Remove the inheritance of text transform in Edge, Firefox, and IE.
 * 1. Remove the inheritance of text transform in Firefox.
 */

button,
select { /* 1 */
    text-transform: none;
}

/**
 * 1. Prevent a WebKit bug where (2) destroys native `audio` and `video`
 *    controls in Android 4.
 * 2. Correct the inability to style clickable types in iOS and Safari.
 */

button,
html [type="button"], /* 1 */
[type="reset"],
[type="submit"] {
    -webkit-appearance: button; /* 2 */
}

/**
 * Remove the inner border and padding in Firefox.
 */

button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
    border-style: none;
    padding: 0;
}

/**
 * Restore the focus styles unset by the previous rule.
 */

button:-moz-focusring,
[type="button"]:-moz-focusring,
[type="reset"]:-moz-focusring,
[type="submit"]:-moz-focusring {
    outline: 1px dotted ButtonText;
}

/**
 * Change the border, margin, and padding in all browsers (opinionated).
 */

fieldset {
    border: 1px solid #c0c0c0;
    margin: 0 2px;
    padding: 0.35em 0.625em 0.75em;
}

/**
 * 1. Correct the text wrapping in Edge and IE.
 * 2. Correct the color inheritance from `fieldset` elements in IE.
 * 3. Remove the padding so developers are not caught out when they zero out
 *    `fieldset` elements in all browsers.
 */

legend {
    box-sizing: border-box; /* 1 */
    color: inherit; /* 2 */
    display: table; /* 1 */
    max-width: 100%; /* 1 */
    padding: 0; /* 3 */
    white-space: normal; /* 1 */
}

/**
 * 1. Add the correct display in IE 9-.
 * 2. Add the correct vertical alignment in Chrome, Firefox, and Opera.
 */

progress {
    display: inline-block; /* 1 */
    vertical-align: baseline; /* 2 */
}

/**
 * Remove the default vertical scrollbar in IE.
 */

textarea {
    overflow: auto;
}

/**
 * 1. Add the correct box sizing in IE 10-.
 * 2. Remove the padding in IE 10-.
 */

[type="checkbox"],
[type="radio"] {
    box-sizing: border-box; /* 1 */
    padding: 0; /* 2 */
}

/**
 * Correct the cursor style of increment and decrement buttons in Chrome.
 */

[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
    height: auto;
}

/**
 * 1. Correct the odd appearance in Chrome and Safari.
 * 2. Correct the outline style in Safari.
 */

[type="search"] {
    -webkit-appearance: textfield; /* 1 */
    outline-offset: -2px; /* 2 */
}

/**
 * Remove the inner padding and cancel buttons in Chrome and Safari on macOS.
 */

[type="search"]::-webkit-search-cancel-button,
[type="search"]::-webkit-search-decoration {
    -webkit-appearance: none;
}

/**
 * 1. Correct the inability to style clickable types in iOS and Safari.
 * 2. Change font properties to `inherit` in Safari.
 */

::-webkit-file-upload-button {
    -webkit-appearance: button; /* 1 */
    font: inherit; /* 2 */
}

/* Interactive
   ========================================================================== */

/*
 * Add the correct display in IE 9-.
 * 1. Add the correct display in Edge, IE, and Firefox.
 */

details, /* 1 */
menu {
    display: block;
}

/*
 * Add the correct display in all browsers.
 */

summary {
    display: list-item;
}

/* Scripting
   ========================================================================== */

/**
 * Add the correct display in IE 9-.
 */

canvas {
    display: inline-block;
}

/**
 * Add the correct display in IE.
 */

template {
    display: none;
}

/* Hidden
   ========================================================================== */

/**
 * Add the correct display in IE 10-.
 */

[hidden] {
    display: none;
}

猜你喜欢

转载自blog.csdn.net/qq_42036616/article/details/83584515