CSS拾遗+技巧集合
1、实现尖角符号。
这是内联inline-block标签独有的特性。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.a{
border-top:30px solid #000000 ;
border-bottom: 30px solid #2c78d5;
border-left:30px solid #1dd537 ;
border-right: 30px solid #ff3021;
display: inline-block;
}
.b{
border-top:30px solid #000000 ;
/*border-bottom: 30px solid #2c78d5;*/
border-left:30px solid #1dd537 ;
border-right: 30px solid #ff3021;
display: inline-block;
}
.c{
border: 30px solid transparent;
/*transparent为透明色*/
margin-top:20px ;
display: inline-block;
border-top:30px solid #000000 ;
}
.c:hover{
margin-top:-10px ;
border: 30px solid transparent;
border-bottom:30px solid #000000;
}
.bb{
border-top:30px solid #000000 ;
/*border-bottom: 30px solid #2c78d5;*/
border-left:30px solid #1dd537 ;
border-right: 30px solid #ff3021;
display: inline-block;
}
/*bb为自己想的方法,不需要改变自身的位置即可。*/
/*bb和b为长方形,其他为正方形*/
.bb:hover{
margin-top:15px ;
border: 0;
border-bottom: 30px solid #2c78d5;
border-left:30px solid #1dd537 ;
border-right: 30px solid #ff3021;
}
.a:hover{ }
</style>
</head>
<body>
<div class="a"></div>
<div class="b"></div>
<div class="bb"></div>
<div style="background-color: #ff3021;height: 70px">
<div class="c"></div>
</div>
</body>
</html>
鼠标临幸前:
鼠标临幸后:
2、实现输入框最后有小图标
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.login{
position: relative;
/*父级标签 position为 relative时,子标签才会根据父级标签定位。否则一级一级找,找不到就根据body定位*/
}
.login input{
width: 170px;
padding-right: 20px;
/*达到输入到R处就不增长的效果*/
height: 30px;
}
.ren{
position: absolute;
/*根据父标签 来定位。*/
top: 8px;
left: 180px;
}
</style>
</head>
<body>
<div class="login">
<input type="text">
<span class="ren">R</span>
</div>
</body>
</html>
输入前:
输入后:
文字不会超过“R”的位置,通过设置padding-right.
3、实现购物加减按钮
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.left{
float: left;
}
/*公用left*/
.w{
width: 96px;
border: 1px solid #ddd;
height: 22px;
}
.jia{
text-align: center;
line-height: 22px;
height: 22px;
width: 22px;
cursor: pointer;
/*鼠标放上去时,变成小手*/
}
.text{
height: 22px;
width: 50px;
padding: 0;
border: 0;
border-left: 1px solid #ddd ;
border-right: 1px solid #ddd ;
}
/*输入框左右2边各1px边框。*/
</style>
</head>
<body>
<div class="w">
<div class="jia left">+</div>
<input type="text" class="text left">
<div class="jia left">-</div>
</div>
</body>
</html>
4、页面布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body{
margin: 0;
}
.top{
height: 48px;
width: 100%;
background-color: #7d7d7d;
}
.left{
position: absolute;
top:48px;
left: 0px;
width: 180px;
bottom: 0;
background-color: #1dd537;
}
.right{
position: absolute;
top:48px;
right: 0px;
left: 183px;
bottom: 0;
background-color: #1c6a9e;
overflow: auto;
/*如果内容超过自动长度,就会生成一个滚动条*/
}
</style>
</head>
<body>
<div class="top"> </div>
<div class="left">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<div class="right">
<h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1>
<h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1> <h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1> <h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1> <h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1> <h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1> <h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1> <h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1> <h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1><h1>333</h1>
</div>
</body>
</html>
这里最重要的就是:overflow: auto;如果内容超过自动长度,就会生成一个滚动条.
图上这个滚动条是属于蓝色背景的,非页面的滚动条
5、实现模态对话框
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
/*分为3层 1、最底层内容 2、一个遮罩层 3、对话框层*/
.zhezhao{
background-color: rgba(0,0,0,0.4);
position: fixed;
top:0;
left: 0;
bottom: 0;
right: 0;
z-index: 2;
/*优先级 比较低*/
}
.kuang{
width: 350px;
height: 250px;
/*5行*/
position: fixed;
top:50%;
left: 50%;
margin-left: -175px;
margin-top:-125px;
/*这5行 实现了真正的居中,margin的是框长宽的一半*/
background-color: white;
z-index: 3;
/*优先级 比较高 在最上边显示*/
}
</style>
</head>
<body>
<div><h1>Mr很大的龙</h1></div>
<div class="zhezhao">
</div>
<div class="kuang"></div>
</body>
</html>
6、伪类选择器补充
伪类选择器 可以对别的标签样式修改,例如:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.touch{
background-color: #1c6a9e;
width: 300px;
height: 300px;
overflow: hidden;
position: relative;
/*用来给子标签提供定位参考*/
}
.touch .content{
position: absolute;
top: 0;
left: 0;
right: 0;
bottom:0;
/*占满父级标签*/
background:rgba(0,0,0,0.6);
/*设置透明度*/
color: white;
text-align: center;
visibility: hidden;
/*隐藏起来*/
}
.touch:hover .content{
visibility: visible;
}
/*当touch被鼠标临幸时,修改content为显示*/
.touch .c1{
font-size: 32px;
/*padding: 60px 0;*/
line-height: 300px;
}
</style>
</head>
<body>
<div class="touch">
<div class="img"><img src="http://pic.iqshw.com/d/file/qita/weixin/2016/07/04/74af10abec5420f74c6c172dab6969a4.jpg"></div>
<div class="content c1">
大龙
</div>
</div>
</body>
</html>
鼠标临幸前:
鼠标临幸后:
7、css代码保护样式不被修改(优先级)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.a{
color: #ff3021 !important;
/*当一句css代码 后边跟!important的时候,下边的普通代码改变不了*/
font-size:50px ;
}
.b{
color: #1dd537 ;
/*试图改变颜色*/
}
</style>
</head>
<body>
<div class="a b">Mr很大的龙</div>
</body>
</html>
按照CSS执行顺序来说,文字应该是绿色,但文字为红色,因为被后边的“!important”保护
8、用position进行定位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body> <div style="height: 2000px;width: 1000px">
<div style="width: 500px;height: 200px;margin: 0 auto;background-color: #2c78d5">
<!--有一定的宽度在设置margin:0 auto 可以让该标签左右居中-->
<div style="width: 300px;height: 100px;margin: 0 auto;background-color:#Fc78d5;position: relative">
<!--父级设置了relative-->
<div style="width: 30px;height: 30px;margin: 0 auto;background-color:#f7fc42;position:absolute;bottom: 0;left: 0"></div>
<!--子标签会根据最近的relative来进行定位-->
</div>
</div>
<div style="width: 50px;height: 50px;margin: 0 auto;background-color: #1dd537;position: fixed;top: 30px;right: 50px;">
<!--fixed 用来绝对定位,根据窗口来定位,滑动滚轮,位置也不会改变-->
</div>
</body>
</html>
当滚动条在最顶端时:
当滚动条在下边时:可以看到绿色块保持的位置是不变的。这就是position的 fixed属性
CSS拾遗+技巧集合的更多相关文章
- css常用技巧集合
1 不想让按钮touch时有蓝色的边框或半透明灰色遮罩(根据系统而定) /*解决方式一*/ -webkit-tap-highlight-color:rgba(0,0,0,0); -webkit-use ...
- css 实战技巧
css 看起来比较简单,但是要想做的好也不是那么容易,我们在平时开发中,主要用css 来美化我们的html结构,所有我觉得css 还是挺重要的,这里记录整理一些关于css 的技巧以及容易忘记的知识点. ...
- css小技巧(1)
1.-webkit-overflow-scrolling: touch; 解决ios滑动时无缓冲问题 2.::-webkit-scrollbar 设置ios滑动时是否显示滚动条 3.::selecti ...
- CSS 代码技巧与维护 ★ Mozilla Hacks – the Web developer blog
原文链接:https://hacks.mozilla.org/2016/05/css-coding-techniques/ 译文链接 :http://www.zcfy.cc/article/css-c ...
- 2天驾驭DIV+CSS (技巧篇)(转)
这是去年看到的一片文章,感觉在我的学习中,有不少的影响.于是把它分享给想很快了解css的兄弟们.本文是技巧篇. 基础篇[知识一] “DIV+CSS” 的叫法是不准确的[知识二] “DIV+CSS” ...
- 教你50招提升ASP.NET性能(十三):精选技巧集合
(19)A selection of tips 招数19: 精选技巧集合 Including height and width in <img /> tags will allow you ...
- CSS hack技巧
CSS hack技巧一览,原文来自CSDN freshlover的博客专栏<史上最全CSS Hack方式一览> 什么是CSS hack 由于不同厂商的流览器或某浏览器的不同版本(如IE6- ...
- CSS编码技巧
前面的话 本文将从DRY.currentColor.inherit和合理使用简写这几方面来详细介绍CSS编码技巧 DRY DRY,即don`t repeat yourself,尽量减少代码重复 在软件 ...
- 你所不知道的 CSS 滤镜技巧与细节
承接上一篇你所不知道的 CSS 动画技巧与细节,本文主要介绍 CSS 滤镜的不常用用法,希望能给读者带来一些干货! OK,下面直接进入正文.本文所描述的滤镜,指的是 CSS3 出来后的滤镜,不是 IE ...
随机推荐
- 使用PHP绘制统计图
使用PHP画统计图的方法 第一种方法 <?php //最后一次修改:2004-6-21 //一个生成矩形图,曲线图的图形分析类 //作者:tonera //说明: //任何人可在任何场合自由使用 ...
- 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...
- MFC 解析xml文件
CComVariant IXMLDOMElement http://blog.sina.com.cn/s/blog_69e905cd0100kp5i.html
- 通用表表达式(Common Table Expression)
问题:编写由基本的 SELECT/FROM/WHERE 类型的语句派生而来的复杂 SQL 语句. 方案1:编写在From子句内使用派生表(内联视图)的T-SQL查询语句. 方案2:使用视图 方案3:使 ...
- select XXX into 和 Insert into XXX select
检索一个表中的部分行存到另一张表中. 一 .另外的那张表没有新建的时候,使用 select XXX into,创建的表与原表有相同的列名和类型: select * into Departments_C ...
- OpenStack的Resize和冷迁移代码解析及改进
原文:http://www.hengtianyun.com/download-show-id-79.html OpenStack的Resize(升级)功能,我们可以改变虚拟机的CPU核数.内存及磁盘大 ...
- 【移动开发】安卓Lab2(02)
Design UI 总共有三个activity 1. MainActitivty: search bar:先用edittext来代替 map:用imageview装图片 2. DetailActiti ...
- android 拍照或者图库选择 压缩后 图片 上传
通过拍照或者从相册里选择图片通过压缩并上传时很多应用的常用功能,记录一下实现过程 一:创建个临时文件夹用于保存压缩后需要上传的图片 /** * path:存放图片目录路径 */ private Str ...
- Windows 下整理内存工具推荐——cleanmem
---恢复内容开始--- cleanmem 是个不错的内存整理工具,www.xdown.com 下载有便携版提供下载. 软件有pro版和free版,一般情况下,free版够用了,没必要用pro版. p ...
- JDBC学习笔记(4)——PreparedStatement的使用
PreparedStatement public interface PreparedStatement extends Statement;可以看到PreparedStatement是Stateme ...