html - Bootstrap 页脚 : Trouble Centering The Social Media Icons

标签 html twitter-bootstrap css

一个多小时以来,我一直在尝试将社交媒体图标居中,但似乎无处可去。 以下是 HTML 代码片段。

<footer>
  <div class="container">
    <div class="row-footer">
      <div class="row row-content">
        <div class="nav navbar-nav" style="padding: 40px 10px;">
          <a class="btn btn-social-icon btn-google-plus" href="http://google.com/+"><i class="fa fa-google-plus"></i></a>
          <a class="btn btn-social-icon btn-facebook" href="http://www.facebook.com/profile.php?id="><i class="fa fa-facebook"></i></a>
          <a class="btn btn-social-icon btn-linkedin" href="http://www.linkedin.com/in/"><i class="fa fa-linkedin"></i></a>
          <a class="btn btn-social-icon btn-twitter" href="http://twitter.com/"><i class="fa fa-twitter"></i></a>
          <a class="btn btn-social-icon btn-youtube" href="http://youtube.com/"><i class="fa fa-youtube"></i></a>
          <a class="btn btn-social-icon" href="mailto:"><i class="fa fa-envelope-o"></i></a>
        </div>
      </div>
    </div>
  </div>
</footer>

下面是 CSS 代码片段。

.row-footer {
    background-color: #AfAfAf;
    margin:200px auto;
    padding: 20px 0px 20px 0px;
}

.navbar-nav {
  display: inline-block;
  text-align: center;
}

这是它在 Google Chrome 上的显示方式。 enter image description here

最佳答案

因为您正在使用 navbar-nav 类,所以您必须删除它的默认 float:left 规则。

.navbar-nav {
  padding: 40px 10px;
  float: none;
  text-align: center;
}

工作示例 1:

.row-footer {
  background-color: #AfAfAf;
  margin: 200px auto;
  padding: 20px 0px 20px 0px;
}
div.navbar-nav {
  padding: 40px 10px;
  float: none;
  text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<footer>
  <div class="container">
    <div class="row-footer">

      <div class="row">
        <div class="nav navbar-nav">
          <a class="btn btn-social-icon btn-google-plus" href="http://google.com/+"><i class="fa fa-google-plus"></i></a>
          <a class="btn btn-social-icon btn-facebook" href="http://www.facebook.com/profile.php?id="><i class="fa fa-facebook"></i></a>
          <a class="btn btn-social-icon btn-linkedin" href="http://www.linkedin.com/in/"><i class="fa fa-linkedin"></i></a>
          <a class="btn btn-social-icon btn-twitter" href="http://twitter.com/"><i class="fa fa-twitter"></i></a>
          <a class="btn btn-social-icon btn-youtube" href="http://youtube.com/"><i class="fa fa-youtube"></i></a>
          <a class="btn btn-social-icon" href="mailto:"><i class="fa fa-envelope-o"></i></a>
        </div>
      </div>
    </div>

  </div>
</footer>

工作示例 2:

.row-footer {
  background-color: #AfAfAf;
  margin: 200px 0;
}
.footer-nav {
  text-align: center;
  padding: 40px 0;
}
.footer-nav a {
  display: inline-block;
  padding: 0 20px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<footer>
  <div class="container">
    <div class="row">
      <div class="col-sm-12">

        <div class="row-footer">
          <div class="footer-nav">
            <a class="btn btn-social-icon btn-google-plus" href="#">
              <i class="fa fa-google-plus"></i>
            </a>
            <a class="btn btn-social-icon btn-facebook" href="#">
              <i class="fa fa-facebook"></i>
            </a>
            <a class="btn btn-social-icon btn-linkedin" href="#">
              <i class="fa fa-linkedin"></i>
            </a>
            <a class="btn btn-social-icon btn-twitter" href="#">
              <i class="fa fa-twitter"></i>
            </a>
            <a class="btn btn-social-icon btn-youtube" href="#">
              <i class="fa fa-youtube"></i>
            </a>
            <a class="btn btn-social-icon" href="#">
              <i class="fa fa-envelope-o"></i>
            </a>
          </div>

        </div>
      </div>
    </div>

  </div>
</footer>

关于html - Bootstrap 页脚 : Trouble Centering The Social Media Icons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41319964/

相关文章:

javascript - 将 4 个数字自动制表符填入下一个输入字段后

html - 尝试使用我的父类 firstRow 定位子元素

javascript - 更改 Bootstrap 导航栏滚动效果

javascript - 简单的 jQuery css 背景 "chooser"

ruby-on-rails - Rails 4 分页,will_paginate 与 Kaminari 与 bootstrap3 一起使用

Angularjs ui bootstrap is-open 不适用于下拉

javascript - jQuery 每个都没有在父 li 的子 ul 中获取元素

javascript - 使用 Javascript : How to create a 'Go Back' link that takes the user to a link if there's no history for the tab or window?

JavaScript .click 在 IE 11 中不起作用

javascript - 如何使用 CSS 或 JS 定位类的父类