温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

css中outline怎么用

发布时间:2022-03-10 16:09:50 来源:亿速云 阅读:246 作者:iii 栏目:web开发

这篇“css中outline怎么用”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“css中outline怎么用”文章吧。

    Spec是这样描述它的

    作用

    用于创建可视对象的轮廓(元素的border-box),如表单按钮轮廓等。

    与border不同

    1、outline不占文档空间;

    2、outline不一定是矩形。

    具体属性说明

    /*轮廓线颜色

    *invert表示为颜色反转,即使轮廓在不同的背景颜色中都可见

    */

    outline-color:invert|<color_name>|<hex_number>|<rgb_number>|inherit

    /*轮廓线样式*/

    outline-style:none|dotted|dashed|solid|double|groove|ridge|inset|outset|inherit

    /*轮廓线宽度*/

    outline-width:medium|thin|thick|<length>|inherit

    /*一次性设置轮廓线的颜色、样式和宽度*/

    outline:<outline-color><outline-style><outline-width>;

    /*轮廓线的偏移量,大于0则轮廓扩大,小于0则轮廓缩小*/

    outline-offset:0px;

    魔鬼在细节

    兼容性

    outline作为CSS2.1规范,因此IE6/7/8(Q)均不支持,在IE8下写入正确的DOCTYPE则支持outline属性。

    outline-offset则IE下均不支持。

    IE6/7/8(Q)下隐藏outline

    若要在IE6/7/8(Q)下隐藏outline效果,则在元素上添加hideFocus特性即可。

    outline:0和outline:none的区别

    在Chrome下执行如下代码

    <styletype="text/css">

    .outline0{

    outline:0;

    }

    .outline-none{

    outline:none;

    }

    </style>

    outline:0

    outline:none

    <scripttype="text/javascript">

    const$=document.querySelector.bind(document)

    constprint=console.log.bind(console)

    constcssProps=["outline-width","outline-style","outline-color"]

    constslctrs=[".outline0",".outline-none"]

    slctrs.forEach(slctr=>{

    styles=window.getComputedStyle($(slctr))

    cssProps.forEach(cssProp=>{

    print("%s,%sis%s",slctr,cssProp,styles[cssProp])

    })

    })

    </script>

    结果:

    .outline0,outline-widthis0px

    .outline0,outline-styleisnone

    .outline0,outline-colorisrgb(0,0,238)

    .outline-none,outline-widthis0px

    .outline-none,outline-styleisnone

    .outline-none,outline-colorisrgb(0,0,238)

    outline仅仅为设置单个或多个具体的outline属性提供更便捷的API而已,因此outline:0和outline:none本质上效果是一致的。

    真心没法弄出圆角

    自从有了border-radius后,我们就可以通过CSS制作圆角矩形、圆形等图形,甚至连box-shadow也受到border-radius影响从而实现元素阴影也能做到圆角的效果。那么outline是否也能做出圆角的效果呢?答案是否定的。那是因为outline的作用本来就是用于勾勒出元素所占的空间轮廓,通过border-radius虽然实现了图形视觉上的圆角,但该元素所占位置空间一点都没有变化,还是那个有棱有角的方形。

    <styletype="text/css">

    .round{

    width:100px;

    height:100px;

    background:yellow;

    border-radius:50%;

    outline:solid1pxred;

    }

    </style>
css中outline怎么用

以上就是关于“css中outline怎么用”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI