【问题标题】:How do I center images in team section of my website如何在我的网站的团队部分中居中图像
【发布时间】:2018-01-04 17:33:30
【问题描述】:

我正在尝试将图像放在我网站的团队部分的中心。我有三个带有文本的图像,并且希望中心图像位于 PC、手机、ipad 等浏览器的中心。我构建了响应数据包,只需要调整 css 和 html 代码。

这是我现在拥有的:

.featured-images {
  padding: 55px 0;
  background: #f9b701;
  text-align: center;
}

.featured-images h1 {
  font-size: 44px;
  color: #2d6e84;
  text-transform: uppercase;
  font-family: 'fjalla_oneregular';
}

.featured-images h2 {
  text-align: center;
  font-size: 34px;
  color: #2d6e84;
  font-family: 'source_sans_prolight';
}

.featured-images .hh-divider {
  background: url(../img/hh-divider.png) repeat-x 50%;
  margin-bottom: 50px;
  margin-top: 20px;
  height: 7px;
}

.featured-images .grid li .user-info ul {
  margin-top: 15px !important;
}

.featured-images .grid li .user-info ul li {
  width: 16%;
  float: none !important;
}

.featured-images .grid li .user-info ul li a:hover {
  text-decoration: none !important;
}

.featured-images .grid li .user-info {
  display: inline-block;
  text-align: center;
}

.featured-images .user-info img {
  margin: 0 auto;
  padding-bottom: 25px;
}

.featured-images .user-info h1 {
  padding-bottom: 10px;
  color: #2a363c;
  font-size: 18px;
  line-height: 22px;
  font-family: 'fjalla_oneregular';
  text-transform: uppercase;
}

.featured-images .user-info p {
  color: #44535a;
  font-size: 16px;
  line-height: 24px;
  font-family: 'source_sans_proregular';
  text-align: center;
}

.featured-images .user-info ul {
  margin: 0;
  margin-top: 15px;
}

.featured-images .user-info ul li {
  list-style: none;
  display: inline-block;
  margin: 0px auto;
}

.featured-images .user-info ul li [class^="fw-icon-"] {
  border-radius: 23px;
  color: #f9b701;
  font-size: 10px;
  display: inline-block !important;
  cursor: pointer;
  width: 14px !important;
  height: 14px !important;
  border-radius: 50%;
  text-align: center;
  position: relative;
  z-index: 1;
  border: none;
  padding: 6px;
  background: #2d6e84;
  font-size: 14px;
  margin-bottom: 7px;
}

.featured-images .user-info ul li [class^="fw-icon-"]:hover {
  text-decoration: none;
  background: #fff;
  color: #2d6e84;
}
<div class="featured-images">
  <div class="container">
    <h1>OUR TEAM</h1>
    <h2>MEET OUR TEAM</h2>
    <div class="hh-divider"></div>
    <div class="row-fluid">
      <ul class="grid effect-3" id="grid">
        <!--##############################################################TEAM MEMBERS#########################################################################-->
        <li class="span2">
          <div class="user-info">
            <div class="aligncenter">
              <img src="img/sam.jpeg" alt="">
              <h1>name1 </h1>
              <p class="last">Co-president </br> MBA 2018 </p>
              <ul>
                <li><a href="#"><i class="fw-icon-facebook"></a></i>
                </li>
                <li><a href="#"><i class="fw-icon-twitter"></a></i>
                </li>
              </ul>
            </div>
        </li>
        <li class="span2">
          <div class="user-info">
            <div class="aligncenter">
              <img src="img/sam.jpeg" alt="">
              <h1>name2 </h1>
              <p class="last">Co-president </br> MBA 2018 </p>
              <ul>
                <li><a href="#"><i class="fw-icon-facebook"></a></i>
                </li>
                <li><a href="#"><i class="fw-icon-twitter"></a></i>
                </li>
              </ul>
            </div>
        </li>
        <li class="span2">
          <div class="user-info">
            <div class="aligncenter">
              <img src="img/sam.jpeg" alt="">
              <h1>name3 </h1>
              <p class="last">Co-president </br> MBA 2018 </p>
              <ul>
                <li><a href="#"><i class="fw-icon-facebook"></a></i>
                </li>
                <li><a href="#"><i class="fw-icon-twitter"></a></i>
                </li>
              </ul>
            </div>
        </li>

【问题讨论】:

  • CSS 不是很好,HTML cmets 中过多的# 是怎么回事?
  • @cybermonkey 似乎 cmets 使 .html 文件看起来更有条理。
  • @lejanp 对我来说看起来不错。您只需要从 ul 和可能的 li 元素中删除填充。
  • @ChrisHappy 是的,但确实不需要过多的#,尤其是在 Stack Overflow 上寻求帮助时。
  • 对不起那些家伙

标签: html css image center


【解决方案1】:

首先去掉整个ul 中的填充和列表标记。然后,将列表中的项目设置为内联显示。之后您可能需要使用边距和填充来调整项目的间距。

ul.grid {
  padding-left:0px;
  list-style-type:none;
}

ul.grid li {
  display: inline-block;
}

根据您需要支持的浏览器,您可以真正享受到一些 CSS Grid 的乐趣。查看CSS display property 的文档。

最后,正如评论者所提到的,稍微清理一下 CSS 选择器会很好。我知道我们在这里看不到整个页面,但这看起来有很多不必要的限定。

编辑:过度限定的选择器会影响我上面示例中的选择器。您可以简化一些已经在使用的选择器,也可以将!important 添加到一些声明中。 (这确实不是一个很好的工作方式,但它会起作用,并且您需要先修复此代码的许多其他问题。)

【讨论】:

  • 谢谢!问题似乎出在 features-images.user-info 部分。我按照您建议的方式进行了操作,但图像仍然向左缩进。
猜你喜欢
  • 2018-06-26
  • 2012-10-05
  • 2017-10-21
  • 2016-01-09
  • 1970-01-01
  • 1970-01-01
  • 2011-07-29
  • 2022-01-01
  • 2011-04-17
相关资源
最近更新 更多