?yb? 2011-06-17 06:15 采纳率: 100%
浏览 1340
已采纳

更改 hr 元素的颜色

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;
}

转载于:https://stackoverflow.com/questions/6382023/changing-the-color-of-an-hr-element

  • 写回答

25条回答 默认 最新

  • 程序go 2011-06-17 06:17
    关注

    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 }.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(24条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100