Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文字前面的绝对垂直居中小圆点 #16

Open
AlexZ33 opened this issue Sep 1, 2021 · 0 comments
Open

文字前面的绝对垂直居中小圆点 #16

AlexZ33 opened this issue Sep 1, 2021 · 0 comments

Comments

@AlexZ33
Copy link
Owner

AlexZ33 commented Sep 1, 2021

在前端开发的时候经常会遇到一个问题,当一段文字设置 height: 30px;line-height: 30px; 的时候按理说我们预期它应该垂直居中的,但是实际上却不是而且各个浏览器的表现还不太一致,如下左边是一个垂直居中的红点,如果是 chrome 浏览器很明显可以感觉到文字实际上是偏下的导致和左边的点对不齐


<style>
  .dot-normal {
    border: 1px solid #eee;
    font-size: 45px;
    height: 50px;
    line-height: 50px;
    padding-left: 20px;
    position: relative;
  }

  .dot-normal::before {
    background: red;
    border-radius: 50%;
    content: '';
    display: inline-block;
    height: 10px;
    left: 10px;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
  }
</style>
<div class="dot-normal">齉齉齉</div>

image

vertical-align: middle 能够稍微修正这个问题,但是个人觉得往往是矫正过多

<style>
  .dot {
    border: 1px solid #eee;
    font-size: 45px;
    height: 50px;
    line-height: 50px;
    padding-left: 10px;
  }

  .dot::before {
    background: red;
    border-radius: 50%;
    content: '';
    display: inline-block;
    height: 10px;
    vertical-align: middle;
    width: 10px;
  }
</style>
<div class="dot">齉齉齉</div>

image

很明显可以看的出来左边的小圆点是跟着文字向下偏移了但是明显过多了,至于用哪种实现类似需求还是看个人了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant