css 边线1像素问题

4 篇文章 0 订阅
4 篇文章 0 订阅

先看效果:

test.gif

代码思路:

1.新建4个div,加类
2.给类写基本样式
3.写鼠标移进来的效果

实践代码

<!-- 4个div,给div加类 -->
<div class="test"></div>
<div class="test"></div>
<div class="test"></div>
<div class="test"></div>

样式代码

<style type="text/css">
        .test {
            width: 223px;
            height: 258px;
            border: 1px solid #ccc;
            margin-top: 100px;
            float: left;
        }
        .test:hover {
            border: 1px solid #f40;
        }
</style>

实际效果:

Paste_Image.png

当鼠标移动上去的效果

Paste_Image.png

具体链接:
http://runjs.cn/detail/kipg09m3

Paste_Image.png

解决1像素问题

样式中添加
margin-left: -1px;

当鼠标移进来时候出现新的问题

Paste_Image.png

解决

div:hover 中添加定位,占据位置
position: relative;

边框被覆盖问题链接

http://runjs.cn/detail/jrcqvnu5

完整代码

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style type="text/css">
        .test {
            width: 223px;
            height: 258px;
            border: 1px solid #ccc;
            margin-top: 100px;
            float: left;

            margin-left: -1px;/*  添加的,解决1像素 */
        }
        .test:hover {
            border: 1px solid #f40;
            /*  解决某边框覆盖 */
            position: relative;
        }

    </style>
</head>
<body>
<div class="test">
</div>
<div class="test"></div>
<div class="test"></div>
<div class="test"></div>

</body>
</html>

问题:当当前容器有定位时候时候,该效果没用。

再度解决:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style type="text/css">
/*      .test {
            width: 223px;
            height: 258px;
            border: 1px solid #ccc;
            margin-top: 100px;
            float: left;

            margin-left: -1px;
        }
        .test:hover {
            border: 1px solid #f40;

            position: relative;
        }
*/
        .test {
            width: 150px;
            height: 150px;
            border: 1px solid #ccc;
            margin-top: 100px;
            float: left; 
            margin-left: -1px;
            position: relative;
        }
        .test:hover {
            border: 1px solid #f40;
            z-index: 1;

        }
    </style>
</head>
<body>
<div class="test">
    <!-- <div class="">热卖</div> -->
</div>
<div class="test"></div>
<div class="test"></div>
<div class="test"></div>

</body>
</html>

具体链接效果:
http://runjs.cn/detail/ykartdjk

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值