CSS应用内容补充及小实例
一.clear
清除浮动
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.clearfix:after{ /*善用after和defore*/
content: "111"; /*注意加引号*/
clear: both;
display: block;
visibility: hidden; /*隐藏并有高度*/
height: 0; /*去掉高度*/ }
.c{
width: 100px;
/*height: 100px;*/
background-color:red;
}
.c .item{
float:left;
width:30px;
background-color: green ;
} </style>
</head>
<body>
<div class='c clearfix'>
<div class='item'>123</div>
<div class='item'>456</div> </div> <div class="test">内容</div>
</body>
</html>
定义公共样式clearfix
避免每次都写标签clear:both来清除浮动
二.hover
样式一:
为伪类加边框效果
<!DOCTYPE html>
<html lang="en">
<!--伪类1-->
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body{margin: 0}
.ele{
border: 2px solid transparent;
}
.ele:hover {
border: 2px solid red;
}
.ele:hover .ele_item{
color: red;
}
</style>
</head>
<body>
<div class="ele">
<div class="ele_item">
123
</div>
test
</div> </body>
</html>
样式一
加图片文字
<!DOCTYPE html>
<html lang="en">
<!--伪类2-->
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.main{
width: 200px;
height: 169px;
overflow: hidden;
position: relative;
}
.main .content{
position: absolute;
top:0;
left: 0;
right: 0;
bottom: 0;
background-color: #666666;
opacity: 0.7;
text-align: center;
visibility: hidden;
}
.main:hover .content{
visibility: visible;
}
.main .content .c2{
color: red;
} </style>
</head>
<body>
<div class="main">
<div class="images"><img src="a.png"></div>
<div class="content">
<div>test</div>
<div class="c2">ttttt</div>
</div>
</div>
</body>
</html>
样式二
Z-index可被用于将在一个元素放置于另一元素之后
三.position
规定元素的定位类型
说明
这个属性定义建立元素布局所用的定位机制。任何元素都可以定位,不过绝对或固定元素会生成一个块级框,而不论该元素本身是什么类型。相对定位元素会相对于它在正常流中的默认位置偏移
属性值

例 :
<!DOCTYPE html>
<html lang="en">
<!--position-->
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body{
margin: 0;
}
.main{
background-color: whitesmoke;
height: 800px;
}
.main .pos{
position: fixed;
right: 10px;
bottom: 10px;
width: 50px;
height: 50px;
background-color: rosybrown;
}
.main .pos2{
position: relative;
background-color: burlywood;
width: 800px;
margin: 0 auto;
height: 100px; } .main .pos2 .little_div{
position: absolute;
background-color: darksalmon;
width: 100px;
height: 30px;
left: 0;
bottom: 0; }
</style>
</head>
<body>
<div class="main">
<div class="pos2">
<div class="little_div"></div>
</div>
<div class="pos"></div>
</div> </body>
</html>
relative与absolute并用
四.实现小尖角
通过设置边框实现小尖角效果,如
<!DOCTYPE html>
<html lang="en">
<!--下拉尖角-->
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.up{
border-top: 30px solid transparent;
border-right: 30px solid transparent;
border-bottom: 30px solid green;
border-left: 30px solid transparent;
display: inline-block;
}
.down{
border-top: 30px solid green;
border-right: 30px solid transparent;
border-bottom: 30px solid transparent;
border-left: 30px solid transparent;
display: inline-block;
}
.c1{
border: 30px solid transparent;
border-top: 30px solid green;
display: inline-block;
margin-top: 40px;
}
.c1:hover{
border: 30px solid transparent;
border-bottom: 30px solid green;
display: inline-block;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="up"></div>
<div class="down"></div>
<div style="height: 100px;background-color: #666666">
<div class="c1"></div>
</div> </body>
</html>
小尖角
五.图标
一般实现制作图标有三种方式:
- 图片(自定义)
- CSS实现
- fontawsome
本例引用第三方,fontawsome,网址:http://fontawesome.io/icons/
首先下载解压,引用,使用方法,例:
<!DOCTYPE html>
<html lang="en">
<!--图标-->
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="font-awesome/css/font-awesome.css">
</head>
<body>
<span class="icon-dollar"></span>
</body>
</html>
六.important
CSS写在不同的地方有不同的优先级, .css文件中的定义 < 元素style中的属性,但是如果使用!important,事情就会变得不一样
css定义中的用!important限定的定义却是优先级最高的
格式:
Tag:css !important
例:
<!DOCTYPE html>
<html lang="en">
<!--important-->
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div{
font-size: 16px;
color: red;
font-weight: bold;
}
.limit{
color: orchid !important;
} </style>
</head>
<body>
<div>
<p>没应用样式</p>
</div>
<div >
<a class="limit">应用了</a>
<p>hello</p>
</div>
</body>
</html>
important应用
七.overflow
规定溢出元素的首选滚动方法
例:
<!DOCTYPE html>
<html lang="en">
<!--页面布局-->
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body{margin: 0px}
.top{
background-color: #666666;
height: 30px;
}
.center .center_left{
position: absolute;
background-color: antiquewhite;
width: 110px;
left: 0;
}
.center .content{
position: absolute;
background-color: #2459a2;
top: 30px;
left: 112px;
right: 0;
bottom: 0;
overflow: auto;
} </style>
</head>
<body>
<div class="top"></div>
<div class="center">
<div class="center_left">
<ul>
<li>menu</li>
<li>menu</li>
<li>menu</li>
<li>menu</li>
<li>menu</li>
</ul>
</div>
<div class="content">
<h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1>
<h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1>
<h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1>
<h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1><h1>标题</h1>
</div>
</div> </body>
</html>
内容溢出滚动
八.小实例
1.登录框
<!DOCTYPE html>
<html lang="en">
<!--登录框-->
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.login_des{
position: relative;
width: 200px;
}
.login_des .user_info{
width: 160px;
height: 30px;
padding-right: 30px;
}
.login_des .user_logo{
position: absolute;
top: 8px;
left: 170px;
}
</style>
</head>
<body>
<div class="login_des">
<input type="text" class="user_info">
<span class="user_logo">R</span>
</div> </body>
</html>
2.提示框
边缘标签:relative,absolute
<!DOCTYPE html> <html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<style>
a {color: #428bca;
text-decoration: none;
} .modal-backdrop {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1050;
background-color: #white;
opacity: 0.8;
} .modal {
position: fixed;
top: 30%;
left: 50%;
z-index: 1030;
} .hide {
display:none;
}
</style> </head>
<body>
<div>
<input type="button" onclick="fadeIn();" value="模态对话框"/>
</div>
<div id="shade" class="modal-backdrop hide">
<div class="modal">
<img src="./images/loading_32.gif"/>
</div>
</div>
<script >
function fadeIn() {
document.getElementById('shade').className = 'modal-backdrop';
} function fadeOut() {
document.getElementById('shade').className = 'modal-backdrop hide';
}
</script>
</body>
</html>
3.购物产品选择框
<!DOCTYPE html>
<html lang="en">
<!--加减框-->
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body{margin: 0}
.left{
float: left;
}
.select{
background-color: #999999;
height: 25px;
width: 140px;
border: 1px solid darksalmon;
}
.select .minus{
width: 20px;
height: 25px;
line-height: 25px;
text-align: center;
cursor: pointer;
}
.select .plus{
width: 20px;
height: 25px;
line-height: 25px;
text-align: center;
cursor: pointer;
} .select .content input{
width: 88px;
height: 23px;
border: 0;
border-left: 1px solid darksalmon;
border-right: 1px solid darksalmon;
}
</style>
</head>
<body>
<div class="select">
<div class="minus left" onclick="Minus()">-</div>
<div class="content left">
<input id = "count" type="text" name="num" value="0"/>
</div>
<div class="plus left" onclick="Plus()">+</div>
</div>
<script type="text/javascript">
// 定义函数
function Plus() {
var old_str = document.getElementById("count").value;
var old_int = parseInt(old_str)
var new_int = old_int + 1;
document.getElementById("count").value = new_int
}
function Minus() {
var old_str = document.getElementById("count").value;
var old_int = parseInt(old_str)
var new_int = old_int - 1;
document.getElementById("count").value = new_int
}
</script>
</body>
</html>
CSS应用内容补充及小实例的更多相关文章
- Django 小实例S1 简易学生选课管理系统 12 CSS样式完善
Django 小实例S1 简易学生选课管理系统 第12节--CSS样式完善 点击查看教程总目录 作者自我介绍:b站小UP主,时常直播编程+红警三,python1对1辅导老师. 课程模块的逻辑代码到这里 ...
- Django 小实例S1 简易学生选课管理系统 8 CSS样式优化
Django 小实例S1 简易学生选课管理系统 第8节--CSS样式优化 点击查看教程总目录 作者自我介绍:b站小UP主,时常直播编程+红警三,python1对1辅导老师. 前面的几节下来,用户模块基 ...
- JavaScript 小实例 - 表单输入内容检测,对页面的增删改
JavaScript 小实例 - 表单输入内容检测,对页面的增删改 效果体验地址:https://xpwi.github.io/js/JavaScript01/jsForm.html 功能: 1.向页 ...
- django Form 表单 总结与小实例
开头寄语: 这几天一直在看Django的form表单验证,然后想对于这几天要有个总结. 首先,先来看一下找到的一个form表单验证的流程: 验证过程 流程详解1. 函数full_clean()依次调用 ...
- canvas实践小实例一 —— 画板工具
前面讲了一部分的canvasAPI的基础知识,光看API的介绍确实是很无趣乏味,需要一点可以激发内心的激情的东西来激励自己来学习,于是就了伴随canvasAPI学习的小实例,这样通过API的知识,结合 ...
- python 全栈开发,Day93(vue内容补充,VueX)
昨日内容回顾 1. 页面的布局 Vue中使用Bootstrap搭页面 1. 安装 1. npm install bootstrap@3.3.7 -S 2. 使用 1. import 'bootstra ...
- jquery-1 jquery几个小实例
jquery-1 jquery几个小实例 一.总结 一句话总结:jquery真的是简单加简便. 1.jquery中改变多个css属性怎么整? 可以链式连接方式,也可以大括号整多个.中间是键值对加引号 ...
- Django 小实例S1 简易学生选课管理系统 5 实现注册功能
Django 小实例S1 简易学生选课管理系统 第5节--实现注册功能 点击查看教程总目录 作者自我介绍:b站小UP主,时常直播编程+红警三,python1对1辅导老师. 本文涉及到的新的额外知识点: ...
- CSS进阶内容—浮动和定位详解
CSS进阶内容-浮动和定位详解 我们在学习了CSS的基本知识和盒子之后,就该了解一下网页的整体构成了 当然如果没有学习之前的知识,可以到我的主页中查看之前的文章:秋落雨微凉 - 博客园 CSS的三种布 ...
随机推荐
- undercore & Backbone对AMD的支持(Require.js中如何使用undercore & Backbone)
RequireJS填补了前端模块化开发的空缺,RequireJS遵循AMD(异步模块定义,Asynchronous Module Definition)规范,越来越多的框架支持AMD,像最近的jQue ...
- 安卓开发笔记——自定义广告轮播Banner(实现无限循环)
关于广告轮播,大家肯定不会陌生,它在现手机市场各大APP出现的频率极高,它的优点在于"不占屏",可以仅用小小的固定空位来展示几个甚至几十个广告条,而且动态效果很好,具有很好的用户& ...
- spring框架面试相关问题
Spring 框架中核心组件有三个:Core.Context 和 Beans.其中最核心的组件就是Beans, Spring提供的最核心的功能就是Bean Factory. Spring 解决了的最核 ...
- 同时支持控制台和MFC窗口程序的APP
BOOL CMyApp::InitInstance() { if ( m_bShowGui==FALSE ) { FILE *stream = NULL; AllocConsole(); // 开辟控 ...
- ASP.NET Web API 的简单示例
Demo1: HTML: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...
- User Settings in WPF
原文:<User Settings in WPF> Posted on 2014/04/09 =============================================== ...
- [git]解决:git config --global push.default matching
解决:git config --global push.default matching 这个警告的意思是:需要设置默认push的分支,所以设置好全局push的默认分支就好了.命令如下: 在有git目 ...
- [linux]删除目录下的一类文件
find 目录 -name "*.类型" | xargs rm -f 通过find命令,查找指定目录下的某一类型的文件.并通过管道传递给xargs,执行后面的rm -f命令. 最终 ...
- Android View 之进度条+拖动条+星级评论条....
PS:将来的你会感谢现在奋斗的自己.... 学习内容: 1.进度条 2.拖动条 3.星级评论条 1.进度条... 进图条这东西想必大家是很熟悉的...为了使用户不会觉得应用程序死掉了,因此 ...
- doctrine2到底是个什么玩意
之前和最近一个项目用到了Doctrine,由于是别人搭建的,自己没有很了解,最近又开始做的时候发现拙荆见肘,于是看了一下doctrine教程,本文就是加上自己理解的doctrine教程文档笔记了. D ...