• Changing the color of an hr element


    Changing the color of an hr element

    I want to change the color of my hr tag using CSS. The code I've tried below doesn't seem to work:

    hr {
        color: #123455;
    }

    回答1

    I think you should use border-color instead of color, if your intention is to change the color of the line produced by <hr> tag.

    Although, it has been pointed in comments that, if you change the size of your line, border will still be as wide as you specified in styles, and line will be filled with the default color (which is not a desired effect most of the time). So it seems like in this case you would also need to specify background-color (as @Ibu suggested in his answer).

    HTML 5 Boilerplate project in its default stylesheet specifies the following rule:

    hr { display: block; height: 1px;
        border: 0; border-top: 1px solid #ccc;
        margin: 1em 0; padding: 0; }
    

    An article titled “12 Little-Known CSS Facts”, published recently by SitePoint, mentions that <hr> can set its border-color to its parent's color if you specify hr { border-color: inherit }.

    回答2

    • border-color works in Chrome and Safari.
    • background-color works in Firefox and Opera.
    • color works in IE7+.

    回答3

    I think this can be useful. this was simple CSS selector.

    hr { background-color: red; height: 1px; border: 0; }
  • 相关阅读:
    二分图的最大匹配
    染色法判定二分图
    kruskal求最小生成树
    prim算法求最小生成树
    floyd
    spfa算法
    bellman_ford
    Dijkstra
    文件操作_1-18 选择题
    会话控制_2-5 编程练习
  • 原文地址:https://www.cnblogs.com/chucklu/p/14275033.html
Copyright © 2020-2023  润新知