如何在一个区域内将多个div居中?

时间:2019-07-16 19:04:29

标签: html css

我知道存在一个问题,似乎所有解决方案都不适合我,这是2014年发布的一个问题。

这是我的代码:

 <section id="team-block">
  <div class="team-block-centered">
    <div class="col-lg-3 col-sm-6 member-1">
      <div class="team-member">
        <img
          src="http://lvsmiledesigners.com/new/wp-content/uploads/2019/06/dr-tongsiri.jpg"
          data-original="http://lvsmiledesigners.com/new/wp-content/uploads/2019/06/dr-tongsiri.jpg"
          alt=""
          class="lazy"
          style="display: block;"
        />
        <div class="inner">
          <h4 class="name">Dr. Amy Tongsiri</h4>
          <p class="position">
            <small>Clinical Director</small>
          </p>
        </div>
        <div class="hover">
          <div class="description">
            <p>
              Dr. Amy Tongsiri has joined Smile Designers of Las Vegas in 2017.
              She has a joyous energy vibrating the room as she enters. Almost
              permanently smiling, she exudes positivity and can easily relaxed
              and soothe a nervous patient. The desire to pursue a career in
              dentistry came young for Dr. Tongsiri, during the course of her
              own dental health. "I originally wanted to do orthodontics, when I
              had braces,” she says, flashing the resulting perfect smile. “But
              eventually, I found General Dentistry to be more exciting because
              you are challenged by being able to cover everything."
            </p>
          </div>
          <div class="read-more">
            <a href="/new/dr-amy-tongsiri/" class="button white outline"
              >Read more <span class="nc-icon-glyph arrows-1_bold-right"></span
            ></a>
          </div>
        </div>
        <!--.hover-->
      </div>
      <!--.team-member-->
    </div>
    <!--.col-lg-3-->
  </div>
  <div class="col-lg-3 col-sm-6 member-2">
    <div class="team-member">
      <img
        src="http://lvsmiledesigners.com/new/wp-content/uploads/2019/07/Dr-Dominique-Dela-Cruz.jpg"
        data-original="http://lvsmiledesigners.com/new/wp-content/uploads/2019/07/Dr-Dominique-Dela-Cruz.jpg"
        alt=""
        class="lazy"
        style="display: block;"
      />
      <div class="inner">
        <h4 class="name">Dr. Dominique Dela Cruz</h4>
        <p class="position">
          <small>Lead Dentist</small>
        </p>
      </div>
      <div class="hover">
        <div class="description">
          <p>
            Providing comprehensive dental care that is tailored to each and
            every patient’s needs is Dr. Dominique Dela Cruz’s goal when it
            comes to treating patients. She strives to provide dental care in a
            comfortable environment while using the most innovative and advanced
            technology. Dr. Dela Cruz grew up in Las Vegas, NV. On her spare
            time, she likes to stay outdoors as much as possible. She loves to
            hike, travel, kayak and snowboard. She also likes to read books and
            watch movies with her dogs. Like most of her patients, Dr. Dela Cruz
            has a sweet tooth and enjoys eating candy, chocolate and other
            pastries.
          </p>
        </div>
        <div class="read-more">
          <a href="/new/dr-jorge-jimenez-marquez/" class="button white outline"
            >Read more <span class="nc-icon-glyph arrows-1_bold-right"></span
          ></a>
        </div>
      </div>
      <!--.hover-->
    </div>
    <!--.team-member-->
  </div>
  <!--.col-lg-3-->
  <div class="col-lg-3 col-sm-6 member-3">
    <div class="team-member">
      <img
        src="http://lvsmiledesigners.com/new/wp-content/uploads/2019/06/karla.jpg"
        data-original="http://lvsmiledesigners.com/new/wp-content/uploads/2019/06/karla.jpg"
        alt=""
        class="lazy"
        style="display: block;"
      />
      <div class="inner">
        <h4 class="name">Karla Brown</h4>
        <p class="position">
          <small>Office Manager</small>
        </p>
      </div>
      <div class="hover">
        <div class="description">
          <p>
            Delivering outstanding customer service has always been an essential
            part of a day’s work for Karla. As Smile Designers of Las Vegas
            Office Manager, she is responsible for all office procedures, and
            uses her organizational skills to ensure smooth operations in a busy
            work environment.
          </p>
        </div>
        <div class="read-more">
          <a href="/new/nancy-gutierrez/" class="button white outline"
            >Read more <span class="nc-icon-glyph arrows-1_bold-right"></span
          ></a>
        </div>
      </div>
      <!--.hover-->
    </div>
    <!--.team-member-->
  </div>
  <!--.col-lg-3-->
  <div class="col-lg-3 col-sm-6 member-4">
    <div class="team-member">
      <img
        src="http://lvsmiledesigners.com/new/wp-content/uploads/2019/06/nancy.jpg"
        data-original="http://lvsmiledesigners.com/new/wp-content/uploads/2019/06/nancy.jpg"
        alt=""
        class="lazy"
        style="display: block;"
      />
      <div class="inner">
        <h4 class="name">Nancy Gutierrez</h4>
        <p class="position">
          <small>Lead Back Office Assistant</small>
        </p>
      </div>
      <div class="hover">
        <div class="description">
          <p>
            As Smile Designers of Las Vegas lead dental assistant she says her
            coworkers and easy-going patients make it a pleasure to go to work
            every day. She loves been a part in patients journeys to a better
            and healthier oral health.
          </p>
        </div>
        <div class="read-more">
          <a href="/new/karla-brown/" class="button white outline"
            >Read more <span class="nc-icon-glyph arrows-1_bold-right"></span
          ></a>
        </div>
      </div>
      <!--.hover-->
    </div>
    <!--.team-member-->
  </div>
  <!--.col-lg-3-->
</section>

这是实时站点:http://lvsmiledesigners.com/new/

该部分位于“我们的团队可以为您提供帮助!”下标头。我所关心的是艾米博士的股利。我不确定为什么艾米博士的图片比其他图片要窄。

2 个答案:

答案 0 :(得分:2)

[更新]::您应将所有Doctors列都用.team-block-centered包裹起来,以将其定位在中间。在您的演示现场站点中,您只包装了艾米博士div

查看您的代码,所有带有col-lg-3类的元素都不是兄弟姐妹,而是嵌套在.team-block-centered元素中的Dr. Amy div元素。那就是主要原因。如果使用类.team-block-centered删除父包装器,一切都会好起来的。

[上一个]: .team-block-centered父包装类的宽度为900px。并且col-lg-3类的宽度为20%(在这种情况下为234px)。

问题是您有20% * 4 = 80%(234 * 4 = 936px)的4列宽度,该宽度大于父包装器的宽度。

提供.team-block-centeredwidth: 100%,然后将其居中。

答案 1 :(得分:0)

换句话说,图像的宽度非常短=原始的173px,应该超过204px。