How to create dotted border with round dots in WebKit browsers?

百般思念 提交于 2020-06-24 07:27:30

问题


In WebKit driven browsers, e.g. Safari, Chrome, borders with their style declared as dotted are rendered with square dots instead of round.

Is there any way to force rendering of round dots seamlessly across browsers?

Reference Test

  • on jsFiddle

回答1:


A natively supported solution is currently lacking, as the specification does not define these properties explicitly, and leaves it for the browser's implementation.

You may, however, use SVG to create the border, as it offers full control over the characteristics you're after.

Draw a line, than define its stroke-dasharray and stroke-linecap attributes to achieve the desired effect.

Example Code Snippet

<line 
    x1="40" x2="260" 
    y1="100" y2="100" 
    stroke="#5184AF" 
    stroke-width="20" 
    stroke-linecap="round" 
    stroke-dasharray=".001, 30" />

Result Snapshot

SVG dotted round border

Demo

  • http://jsfiddle.net/eliranmal/hsfxS/

References (on Mozilla Developer Network)

  • stroke-dasharray
  • stroke-linecap



回答2:


border-image would be a possibility: http://www.css3.info/preview/border-image/




回答3:


I also had this problem but I only needed three round dots under my menu item. So I just used a terrible hack, but it worked: First of all I hooked in FontAwesome using @import Then added the round dot characters as content in the CSS:

#nav ul .current_page_item a:after {
    font-family: 'FontAwesome';
    content: "\f111  \f111  \f111";
    font-size: 6px;
    display: block;
}


来源:https://stackoverflow.com/questions/11280676/how-to-create-dotted-border-with-round-dots-in-webkit-browsers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!