提问者:小点点

使用超过%1个样式表的图标导致高度/对齐问题


我想从不同的样式表使用不同的图标,因为不是所有的图标都在1样式表中可用,我想使用。 当我尝试这样做的时候,它会导致高度问题,一个图标留在上面,留下一些底部空间,而另一个图标看起来就像它所需要的那样。 怎样才能使它们保持相同的高度? 如果你看到字体的最后一个图标的高度很棒,留下一些底部空间。。。

null

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.footer {
   position: fixed;
   left: 0;
   bottom: 0;
   width: 100%;
   background-color: red;
   color: white;
   text-align: center;
}
.footer a {
  float: left;
  display: block;
  color: black;
  text-align: center;
  padding: 14px 0px;
  text-decoration: none;
  font-size: 17px;
  width:20%;
  bottom:0;
  margin-bottom:0;
}

.footer a:hover {
  background-color: #ddd;
  color: black;
}

.footer a.active {
  background-color: #2196F3;
  color: white;
}

</style>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>

<h2>Fixed/Sticky Footer Example</h2>
<p>The footer is placed at the bottom of the page.</p>

<div class="footer">
  <a href=""><i class="material-icons">home</i></a>
    <a href=""><i class="material-icons">home</i></a>
      <a href=""><i class="material-icons">home</i></a>
        <a href=""><i class="fa fa-tachometer"></i></a>
</div>

</body>
</html> 

null


共2个答案

匿名用户

将页脚更改为显示,因为flex可以解决这个问题:

null

    <!DOCTYPE html>
        <html>
        <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <style>
        .footer {
          display: flex;
           position: fixed;
           left: 0;
           bottom: 0;
           width: 100%;
           background-color: red;
           color: white;
           text-align: center;
        }
        .footer a {
          /* float: left; */
          display: flex; /* Consider flex layout */
          color: black;
        justify-content: center; /* Alignment of icons */
          padding: 14px 0px;
          text-decoration: none;
          font-size: 17px;
          width:20%;
          bottom:0;
          margin-bottom:0;
        }

        .footer a:hover {
          background-color: #ddd;
          color: black;
        }

        .footer a.active {
          background-color: #2196F3;
          color: white;
        }

        </style>
        <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        </head>
        <body>

        <h2>Fixed/Sticky Footer Example</h2>
        <p>The footer is placed at the bottom of the page.</p>

        <div class="footer">
          <a href=""><i class="material-icons">home</i></a>
            <a href=""><i class="material-icons">home</i></a>
              <a href=""><i class="material-icons">home</i></a>
                <a href=""><i class="fa fa-tachometer"></i></a>
        </div>

        </body>
        </html> 

匿名用户

试试这个,在“i”标记上添加了行高和字体大小

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.footer {
   position: fixed;
   left: 0;
   bottom: 0;
   width: 100%;
   background-color: red;
   color: white;
   text-align: center;
}
.footer a {
  float: left;
  display: block;
  color: black;
  text-align: center;
  text-decoration: none;
  /*removed padding*/
  width:20%;
  bottom:0;
  margin-bottom:0;
  
}

.footer a:hover {
  background-color: #ddd;
  color: black;
}

.footer a.active {
  background-color: #2196F3;
  color: white;
}
/* added this */
.footer a i{
    font-size: 24px;
    line-height: 50px;
}

</style>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>

<h2>Fixed/Sticky Footer Example</h2>
<p>The footer is placed at the bottom of the page.</p>

<div class="footer">
  <a href=""><i class="material-icons">home</i></a>
    <a href=""><i class="material-icons">home</i></a>
      <a href=""><i class="material-icons">home</i></a>
        <a href=""><i class="fa fa-tachometer"></i></a>
</div>

</body>
</html>