Text border using css (border around text)

前端 未结 5 1313
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-04 07:34

Is there a way to integrate a border around text like the image below?

\"text

5条回答
  •  执念已碎
    2020-12-04 07:53

    I don't like that much solutions based on multiplying text-shadows, it's not really flexible, it may work for a 2 pixels stroke where directions to add are 8, but with just 3 pixels stroke directions became 16, and so on... Not really confortable to manage.

    The right tool exists, it's SVG The browsers' support problem worth nothing in this case, 'cause the usage of text-shadow has its own support problem too, filter: progid:DXImageTransform can be used or IE < 10 but often doesn't work as expected.

    To me the best solution remains SVG with a fallback in not-stroked text for older browser:

    This kind of approuch works on pratically all versions of Chrome and Firefox, Safari since version 3.04, Opera 8, IE 9

    Compared to text-shadow whose supports are: Chrome 4.0, FF 3.5, IE 10, Safari 4.0, Opera 9, it results even more compatible.

    .stroke {
      margin: 0;
      font-family: arial;
      font-size:70px;
      font-weight: bold;
      }
      
      svg {
        display: block;
      }
      
      text {
        fill: black;
        stroke: red;
        stroke-width: 3;
      }

    Stroked text

提交回复
热议问题