最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - CSS text inside anchor tag seems slightly off center on IOS - Stack Overflow

programmeradmin2浏览0评论

I've recently started my CSS journey and I'm currently working on my first project for a friend. While testing I noticed my text inside my anchor tag was slightly off center, see comparison below.

The left is on Chrome, the right on IOS

Though it's hard to see, the spacing underneath the text in IOS is bigger than above.

I've tried text-size-adjust: none and resetting the line-height, but neither seem to work for me.

Any Ideas?

* {
    margin: 0;
    padding: 0;
    font: inherit;
    text-size-adjust: none;
}

a {
    text-decoration: none;
    line-height: 1;
    color: black;
    display: flex;
    align-items: center;
    gap: .75rem; /* The gap between the text and the arrow-icon. */
    border: 1px solid black;
    border-radius: 10rem;
    padding: 1rem 1.25rem;
}
<a href="">Read Our Story <span>→</span></a>

I've recently started my CSS journey and I'm currently working on my first project for a friend. While testing I noticed my text inside my anchor tag was slightly off center, see comparison below.

The left is on Chrome, the right on IOS

Though it's hard to see, the spacing underneath the text in IOS is bigger than above.

I've tried text-size-adjust: none and resetting the line-height, but neither seem to work for me.

Any Ideas?

* {
    margin: 0;
    padding: 0;
    font: inherit;
    text-size-adjust: none;
}

a {
    text-decoration: none;
    line-height: 1;
    color: black;
    display: flex;
    align-items: center;
    gap: .75rem; /* The gap between the text and the arrow-icon. */
    border: 1px solid black;
    border-radius: 10rem;
    padding: 1rem 1.25rem;
}
<a href="">Read Our Story <span>→</span></a>

Share Improve this question edited Feb 7 at 9:07 mplungjan 178k28 gold badges180 silver badges240 bronze badges asked Feb 7 at 8:47 Itsjul1anItsjul1an 3211 gold badge2 silver badges13 bronze badges 1
  • I made you a snippet. Please edit and add whatever relevant CSS is needed to show the button like your image – mplungjan Commented Feb 7 at 8:59
Add a comment  | 

1 Answer 1

Reset to default 0

I read the following on the net:

  • iOS uses different text baseline alignment compared to other browsers.
  • Flexbox doesn’t perfectly center inline text elements when their font has built-in vertical offsets.
  • Different fonts have different built-in ascender/descender values, and iOS may render those slightly differently.

Can you try these changes?

* {
    margin: 0;
    padding: 0;
    font: inherit;
    text-size-adjust: none;
}

a {
    text-decoration: none;
    color: black;
    display: inline-flex; /* Fix iOS flex alignment */
    align-items: center;
    gap: .75rem; /* The gap between the text and the arrow-icon. */
    border: 1px solid black;
    border-radius: 10rem;
    padding: 1rem 1.25rem;
    line-height: normal; /* Fix text baseline alignment */
    vertical-align: middle; /* Centers inside flex */
}

/* Optional iOS fix */
@supports (-webkit-touch-callout: none) {
  a {
    position: relative;
    top: -0.1rem;
  }
}
<a href="">Read Our Story <span>→</span></a>

发布评论

评论列表(0)

  1. 暂无评论