html - 如何使按钮位于div下方

标签 html css

我试图让一个按钮位于 div 下方,但是,该按钮 float 到左侧而不是 float 到右侧。我正在努力实现这样的目标: enter image description here

到目前为止,这是:

HTML:

<div class="container">
  <div class="main">
    <div class="sectiontitle">
      <h1 class="maintitle">Free Pick-Up<br>and Delivery</h1>
    </div>
    <div class="sectiondes">
      <p class="maintext"> We offer a free pick up and delivery service to your home or place of work.</p>
    </div>
    <div class="sectionbutton">
      <button href="#!" class="button">learn more</button>
    </div>
  </div>
</div>

CSS:

.container {
  margin-right: auto;
  margin-left: auto;
  margin-bottom:0px;
}


.main{
    margin-top: 100px;
    background: url("../img/Home-img.jpg");
    height: 931.5px;
    width: 1920px;
    float: right;
}



.maintitle{
    font-family: 'Roboto', sans-serif;
    font-weight: 500;
    font-size: 65px;
    color: #000;
    letter-spacing: 2px;
    line-height: 60px;
    height: 120px;
    width: 641.6px;
    margin-top: 121px;
    margin-right: 392.4px;
    margin-left: 886px;
    margin-bottom: 30px;
    text-align: right;
}

.maintext{
    height: 68px;
    width: 489.6px;
    margin-right: 392.4px;
    text-align: right;
    float: right;
    font-size: 24px;
    color: #000;
    letter-spacing: 0;
    line-height: 34px;
    margin-top:0px;
    font-family: 'Roboto', sans-serif;
    font-weight: 400;
    margin-bottom: 30px;

}

.sectionbutton{
    float: right;
}

button{
    background-color: #1B325F; 
    font-family: 'Roboto', sans-serif;
    font-weight: 700;
    border: none;
    padding: 13px 28.5px 13px 29px;
    float: right;
    text-align: center;
    text-decoration: none;
    border-radius: 2px;
    margin-bottom: 20px;
    text-transform: uppercase;
    font-size: 18px;
    color: #ffffff;
    letter-spacing: -0.03px;
    margin-right: 392.4px;

}

我知道问题确实出在我的 CSS 上,但我不知道如何让按钮位于另一个 div 下方。代码笔是 https://codepen.io/mrsalami/pen/Yxpyop

最佳答案

.container {
  margin-right: auto;
  margin-left: auto;
  margin-bottom:0px;
}


.main{
    margin-top: 100px;
    background: url("../img/Home-img.jpg");
    height: 931.5px;
    width: 1920px;
    float: right;
}



.maintitle{
    font-family: 'Roboto', sans-serif;
    font-weight: 500;
    font-size: 65px;
    color: #000;
    letter-spacing: 2px;
    line-height: 60px;
    height: 120px;
    width: 641.6px;
    margin-top: 121px;
    margin-right: 392.4px;
    margin-left: 886px;
    margin-bottom: 30px;
    text-align: right;
}

.maintext{
    height: 68px;
    width: 489.6px;
    margin-right: 392.4px;
    text-align: right;
    float: right;
    font-size: 24px;
    color: #000;
    letter-spacing: 0;
    line-height: 34px;
    margin-top:0px;
    font-family: 'Roboto', sans-serif;
    font-weight: 400;
    margin-bottom: 30px;
    
}

.sectionbutton{
    clear: both;
    float: right;
}

button{
    background-color: #1B325F; 
    font-family: 'Roboto', sans-serif;
    font-weight: 700;
    border: none;
    padding: 13px 28.5px 13px 29px;
    float: right;
    text-align: center;
    text-decoration: none;
    border-radius: 2px;
    margin-bottom: 20px;
    text-transform: uppercase;
    font-size: 18px;
    color: #ffffff;
    letter-spacing: -0.03px;
    margin-right: 392.4px;
    
}
<div class="container">
  <div class="main">
    <div class="sectiontitle">
      <h1 class="maintitle">Free Pick-Up<br>and Delivery</h1>
    </div>
    <div class="sectiondes">
      <p class="maintext"> We offer a free pick up and delivery service to your home or place of work.</p>
    </div>
    <div class="sectionbutton">
      <button href="#!" class="button">learn more</button>
    </div>
  </div>
</div>

关于html - 如何使按钮位于div下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45496571/

相关文章:

javascript 全部替换不起作用?

html - 单选按钮在菜单中未正确对齐

css - 用 div 内容包裹列表项

javascript - 如何将 animate.css 动画与 Vue 的 Transition 和 TransitionGroup 组件一起使用

css - 如果颜色可以访问,这些颜色之间的渐变是否可以访问?

wordpress 列表中的 css

javascript - 单击按钮将下拉列表添加到新行

html - 如何使 div 扩展以适应可用的垂直空间?

html - 为什么 <br/> 与 XHTML 中的 <br></br> 不同?

javascript - 如果按下按键,Javascript