逛园子,看到个练习题,小试了一把(淘宝ued的两道小题)

时间:2023-02-15 16:13:02

闲来无事,逛园子,充充电。发现了一个挺有意思的博文,自己玩了一把。

第一题:使用 HTML+CSS 实现如图布局,border-widht 1px,一个格子大小是 60*60,hover时候边框变为橘红色(兼容IE6+,考虑语义化的结构)

效果图:

  逛园子,看到个练习题,小试了一把(淘宝ued的两道小题)

简单分析一下: 使用伪类 :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;}后产生了一个新的问题,如下图

逛园子,看到个练习题,小试了一把(淘宝ued的两道小题)

当width:185px后,就正常了.搞了半天没弄清,这个1px哪来的?求大神解答。

第二题:使用一个标签和纯CSS <a href="#" title="订阅博客">订阅博客</a> 实现如图效果,文字始终保持左边距10px, 下边距5px,改变字体大小(12px-50px)时,边距保持不变,不使用 content:"订阅博客",兼容现代浏览器

效果图:

逛园子,看到个练习题,小试了一把(淘宝ued的两道小题)

代码如下:

 <!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的两道小题)

到此结束啦。

绿豆刚发芽,正在汲取营养,有错误的地方还请指正。