逛园子,看到个练习题,小试了一把(淘宝ued的两道小题)
闲来无事,逛园子,充充电。发现了一个挺有意思的博文,自己玩了一把。
第一题:使用 HTML+CSS 实现如图布局,border-widht 1px,一个格子大小是 60*60,hover时候边框变为橘红色(兼容IE6+,考虑语义化的结构)
效果图:

简单分析一下: 使用伪类 :hover的时候相对定位 改变z-index,
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{ padding: 0; margin: 0; }
.hover{ overflow: hidden; margin: 10px; width: 244px; height: 244px; }
.item_hover{ float: left; width: 60px; height: 60px; padding:10px; text-align: center; border: 1px solid #e8e8e8; margin-right: -1px; margin-bottom: -1px; z-index: 1; position: relative; cursor: pointer; }
.item_hover:hover{border: 1px solid #f40;z-index: 2;}
</style>
</head>
<body>
<div class="hover">
<div class='item_hover' href="#">1</div>
<div class='item_hover' href="#">2</div>
<div class='item_hover' href="#">3</div>
<div class='item_hover' href="#">4</div>
<div class='item_hover' href="#">5</div>
<div class='item_hover' href="#">6</div>
<div class='item_hover' href="#">7</div>
<div class='item_hover' href="#">8</div>
<div class='item_hover' href="#">9</div>
</div>
</body>
</html>
此方法在IE6下无效,原因是伪类:hover在IE6下只支持a标签,其他标签的伪类是不支持的。要想在IE6呈现出效果只需把class='item_hover'的标签<div>替换为<a>即可
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{ padding: 0; margin: 0; }
.hover{ overflow: hidden; width: 188px; height: 188px; }
a{display: block; float: left; z-index: 1; border: 2px solid #e8e8e8; margin-right: -2px; margin-bottom: -2px; width: 60px; height: 60px;line-height: 60px; text-align: center; position: relative;}
a:hover{border: 2px solid #f40;z-index: 2;}
</style>
</head>
<body>
<div class="hover">
<a class='item_hover' href="#">1</a>
<a class='item_hover' href="#">2</a>
<a class='item_hover' href="#">3</a>
<a class='item_hover' href="#">4</a>
<a class='item_hover' href="#">5</a>
<a class='item_hover' href="#">6</a>
<a class='item_hover' href="#">7</a>
<a class='item_hover' href="#">8</a>
<a class='item_hover' href="#">9</a>
</div>
</body>
</html>
当border值设置为1px,margin-right:-1px;margin-bottom:-1px;.hover相应的变为{width:184px;height:184px;overflow:hidden;}后产生了一个新的问题,如下图

当width:185px后,就正常了.搞了半天没弄清,这个1px哪来的?求大神解答。
第二题:使用一个标签和纯CSS <a href="#" title="订阅博客">订阅博客</a> 实现如图效果,文字始终保持左边距10px, 下边距5px,改变字体大小(12px-50px)时,边距保持不变,不使用 content:"订阅博客",兼容现代浏览器
效果图:

代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
a{
text-decoration: none;
}
.mouse{
width:500px;
height: 100px;
text-align: left;
padding-left:10px;
padding-bottom: 5px;
vertical-align: bottom;
display: table-cell;
border-bottom: 5px solid #f40;
background-color: #a0d0e0;
color: #000;
transition: font-size 4s;
}
.mouse:hover{
background-color: #a0d0e0;
font-size: 50px;
-webkit-animation: color .3s;
-o-animation: color .3s;
animation: color .3s;
}
@keyframes color{
50% {background: green;}
100% {background: #a0d0e0;}
}
@-webkit-keyframes color{
50% {background: green;}
100% {background: #a0d0e0;}
}
</style>
</head>
<body>
<a class='mouse' href="#" alt='鼠标过来,我要变身啦'>鼠标过来,我要变身啦</a>
</body>
</html>
关于css3 animation动画属性,各浏览器兼容问题(来源W3School):

到此结束啦。
绿豆刚发芽,正在汲取营养,有错误的地方还请指正。
逛园子,看到个练习题,小试了一把(淘宝ued的两道小题)的更多相关文章
- ACM/ICPC 之 两道dijkstra练习题(ZOJ1053(POJ1122)-ZOJ1053)
两道较为典型的单源最短路径问题,采用dijkstra解法 本来是四道练习题,后来发现后面两道用dijkstra来解的话总觉得有点冗余了,因此暂且分成三篇博客(本篇以及后两篇). ZOJ1053(POJ ...
- 听说 JVM 性能优化很难?今天我小试了一把!
文章首发于公众号「陈树义」及个人博客 shuyi.tech,欢迎关注访问. 对于 Java 开发的同学来说,JVM 性能优化可以说是比较难掌握的知识点.这不仅因为 JVM 性能优化需要掌握晦涩难懂的 ...
- sparksql 练习题两道
第一题:select '{"id":1,"name":{"url":"http://xxx/yyy/zz/test.js" ...
- Data URL简介及Data URL的利弊
之前写过一篇“漫谈前端优化”的文章,里面提到过DataUrl,粗鲁的描述了下,感觉不甚详焉,所以这几天也总结了这方面的知识,参考一些资料,补充一篇文章在这里,对这方面的资料来说,也是一种强化记忆应用: ...
- 【转】Data URL和图片,及Data URI的利弊
Data URL给了我们一种很巧妙的将图片“嵌入”到HTML中的方法.跟传统的用img标记将服务器上的图片引用到页面中的方式不一样,在Data URL协议中,图片被转换成base64编码的字符串形式, ...
- NOIP2016纪录[那些我所追求的]
人生第一场正式OI [序] 2016-12-04 见底部 [Day -1] 2016-11-17 期中考试无心插柳柳成荫,考了全市第2班里第1(还不是因为只复习了不到两天考试),马上请了一个周的假准备 ...
- CSS3与页面布局学习总结(四)——页面布局大全
一.负边距与浮动布局 1.1.负边距 所谓的负边距就是margin取负值的情况,如margin:-100px,margin:-100%.当一个元素与另一个元素margin取负值时将拉近距离.常见的功能 ...
- [转]9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路
1,简介 毕业答辩搞定,总算可以闲一段时间,把这段求职经历写出来,也作为之前三个半月的求职的回顾. 首先说说我拿到的offer情况: 微软,3面->终面,搞定 百度,3面->终面,口头of ...
- CSS3与页面布局学习笔记(四)——页面布局大全(负边距、双飞翼、多栏、弹性、流式、瀑布流、响应式布局)
一.负边距与浮动布局 1.1.负边距 所谓的负边距就是margin取负值的情况,如margin:-100px,margin:-100%.当一个元素与另一个元素margin取负值时将拉近距离.常见的功能 ...
随机推荐
- Effective Java2读书笔记-类和接口(三)
第17条:要么为继承而设计,并提供文档说明,要么就禁止继承 第18条:接口优于抽象类 这两条中,提到了一个很重要的概念骨架实现.也就是说,抽象类实现接口的形式.这样的好处是,接口本来不能提供默认的实现 ...
- poj2484--A Funny♂Game
题意:n个硬币围成环,每次可以取相邻两个硬币或者一个,不能取者负. Ans:n<=2的时候先手必胜,其他任意情况后手必胜,因为不论我先手取什么,我后手总有中心对称与它配对. #include&l ...
- LeetCode_Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...
- Keil C动态内存管理机制分析及改进
Keil C是常用的嵌入式系统编程工具,它通过init_mempool.mallloe.free等函数,提供了动态存储管理等功能.本文通过对init_mempool.mallloe和free这3个Ke ...
- Find out C++ Memory Usage in Code
You can use Microsoft Platform SDK functions to get the heap size at a specific point. If get the he ...
- PowerShell为什么强大
PowerShell为什么强大 本文索引 [隐藏] 5.1举例介绍 1破天荒的方便 2面向对象 3绑上.NET这棵大树 4强大的兼容性 5基于平台的可扩展性 微软是一个很”低调”的公司,取名为微软,感 ...
- eclipsecdt添加自动补全功能
自动代码补全完全是一个改善生活质量的功能呀!cdt拥有自动代码补全功能,只是我们没有打开而已 1. 绑定快捷方式 1. windows -> preferences ->general-& ...
- WifiDog系统
WifiDog:A captive portal suite What is it composed of ? A: It is composed of 2 components: The clien ...
- Hive 11、Hive嵌入Python
Hive嵌入Python Python的输入输出都是\t为分隔符,否则会出错,python脚本输入print出规定格式的数据 用法为先add file,使用语法为TRANSFORM (name, it ...
- python json基础学习01
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' import json #全称(javascript object ...