简体   繁体   English

在HTML中将文本对齐到红色圆圈的中心,并在其下方带有一个图标

[英]Align text to the center on a red circle with a icon below it in HTML

I have the following HTML to show notifications on a website. 我有以下HTML可以在网站上显示通知。 I want the number to be centered in the red circle. 我希望数字以红色圆圈为中心。 Also I want the whole div to be a href 我也希望整个div成为href

I tried using the following CSS. 我尝试使用以下CSS。 Also please suggest how to approach such a problem. 还请提出如何解决此类问题的建议。 I'm completely new to frontend programming. 我是前端编程的新手。

 .txt { position: absolute; top: 4px; left: 25px; } .btn-circle { width: 30px; height: 30px; text-align: center; background: red; border-radius: 50%; } 
 <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.css" rel="stylesheet" /> <div> <i class="fa fa-inbox fa-2x"></i> <a href="#" class="btn btn-circle txt"> <div class="count">10</div> </a> </div> 

You can try this: 您可以尝试以下方法:

 .txt { position: absolute; top: 4px; left: 25px; } .btn-circle { width: 30px; height: 30px; line-height: 30px; text-align: center; background: red; border-radius: 50%; text-decoration:none; } 
 <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.css" rel="stylesheet" /> <div> <i class="fa fa-inbox fa-2x"></i> <a href="#" class="btn btn-circle txt"> 10 </a> </div> 

Use this 

    <a href="#">
      <i class="fa fa-inbox fa-2x"></i> 
      <div class="btn btn-circle">
        <span class="txt">10</span>
        </div>
      </a>
and in style 

    <style>
    .txt 
    {
    display:table-cell;
    vertical-align:middle;
    text-align:center;
    }
    .btn-circle
    {
    width: 30px;
    height: 30px;
    text-align: center;
    background: red;
    border-radius: 50%;
    display:table-cell;
    }
    </style>

Use this code: 使用此代码:

HTML: HTML:

<a href="#"> 
      <div>
        <i class="fa fa-inbox fa-2x">
          <span class="btn btn-circle txt">
            <span class="count">10</span>
          </span>
        </i> 
      </div>
    </a>

CSS: CSS:

.btn-circle {
  position: absolute;
  top: 65px;
  left: 20px;
  width: 30px;
  height: 30px;
  background: red;
  border-radius: 50%;
  text-align: center;
}

.count {
  font-size: 15px;
  vertical-align: center;
  position: relative;
  top: -5px;
}

Hope this helps.... 希望这可以帮助....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM