【问题标题】:How to get button below div如何获取div下方的按钮
【发布时间】:2018-05-16 20:36:39
【问题描述】:

我一直试图让这个按钮位于 div 下方,但我不知道出了什么问题。该按钮应该位于页面正下方的中心。

我尝试修改 z-index,更改 CSS 以使按钮为 inline-block,将块放在单独的 div 中并修改该 div,但到目前为止,没有任何效果。

问题的形象

* {
  background-color: rgba(0, 0, 0, 0.1);
}

.header {
  font-family: arial;
  text-align: center;
}

.recent_projects {
  position: absolute;
  width: 100%;
  text-align: center;
}

.container {
  height: 400px;
  width: 250px;
  display: inline-block;
  padding-left: 75px;
  padding-right: 75px;
  padding-top: 50px;
  text-align: justify;
  overflow: hidden;
}

#box1 {
  float: left;
}

#box2 {
  margin: 0 auto;
}

#box3 {
  float: right;
}

.recentProjectImages {
  height: 200px;
  width: 250px;
}


/*--Button--*/

.button {
  border-radius: 4px;
  background-color: #0466D4;
  border: none;
  color: #FFFFFF;
  display: block;
  text-align: center;
  font-size: 28px;
  padding: 20px;
  width: 200px;
  transition: all 0.5s;
  cursor: pointer;
  margin: auto;
  position: relative;
}
<div class="header">
  <h1>Recent Projects</h1>
</div>
<section class="recent_projects">
  <div id="box1" class="container">
    <img class="recentProjectImages" src="placeholder.png" alt="placeholder">
    <p>Lorem ipsum dolor sit amet</p>
  </div>
  <div id="box2" class="container">
    <img class="recentProjectImages" src="placeholder.png" alt="placeholder">
    <p>Lorem ipsum dolor sit amet</p>
  </div>
  <div id="box3" class="container">
    <img class="recentProjectImages" src="placeholder.png" alt="placeholder">
    <p>Lorem ipsum dolor sit amet.</p>
  </div>
</section>
<button class="button"><span>Details</span></button>

【问题讨论】:

  • @kevin 我建议你使用,引导程序。这会容易得多,并且也会提供响应能力。
  • 谢谢老兄!我会调查的!
  • @RejectEd27 找到了解决方案。不确定你是否需要那个。你能快速检查一下,让我知道这是否是你所期望的吗?
  • @Praveen 但它没有响应。否则它正在工作。

标签: html css button alignment


【解决方案1】:

这是因为您在&lt;section&gt; 标记上有position: absolute。不知道你为什么会这样,但删除它会给你想要的结果:

* {
  background-color: rgba(0, 0, 0, 0.1);
}

.header {
  font-family: arial;
  text-align: center;
}

.recent_projects {
  /* position: absolute; /* Remove this! */
  width: 100%;
  text-align: center;
}

.container {
  height: 400px;
  width: 250px;
  display: inline-block;
  padding-left: 75px;
  padding-right: 75px;
  padding-top: 50px;
  text-align: justify;
  overflow: hidden;
}

#box1 {
  float: left;
}

#box2 {
  margin: 0 auto;
}

#box3 {
  float: right;
}

.recentProjectImages {
  height: 200px;
  width: 250px;
}


/*--Button--*/

.button {
  border-radius: 4px;
  background-color: #0466D4;
  border: none;
  color: #FFFFFF;
  display: block;
  text-align: center;
  font-size: 28px;
  padding: 20px;
  width: 200px;
  transition: all 0.5s;
  cursor: pointer;
  margin: auto;
  position: relative;
}
<div class="header">
  <h1>Recent Projects</h1>
</div>
<section class="recent_projects">
  <div id="box1" class="container">
    <img class="recentProjectImages" src="placeholder.png" alt="placeholder">
    <p>Lorem ipsum dolor sit amet</p>
  </div>
  <div id="box2" class="container">
    <img class="recentProjectImages" src="placeholder.png" alt="placeholder">
    <p>Lorem ipsum dolor sit amet</p>
  </div>
  <div id="box3" class="container">
    <img class="recentProjectImages" src="placeholder.png" alt="placeholder">
    <p>Lorem ipsum dolor sit amet.</p>
  </div>
</section>
<button class="button"><span>Details</span></button>

预览

【讨论】:

    猜你喜欢
    • 2015-07-13
    • 2016-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多