如何将按钮对齐?

时间:2016-12-31 11:20:02

标签: html css

下午好, 我已经多次询问这个主题并且已经有了几个解决方案,正如我在搜索论坛时看到的那样。

但是解决方案如, <input type="button" value="Click Me" **style="float: right;"**>

即使按钮成功对齐,它们也会重叠我的页脚,因为按钮应该在页脚正上方。这是我的代码:

.button {
  border-radius: 4px;
  background-color: #0FA0FF;
  border: none;
  color: #FFFFFF;
  text-align: center;
  font-size: 15px;
  padding: 10px;
  width: 200px;
  transition: all 0.5s;
  cursor: pointer;
  margin: 5px;
}
.button span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
}
.button span:after {
  content: '\00bb';
  position: absolute;
  opacity: 0;
  top: 0;
  right: -20px;
  transition: 0.5s;
}
.button:hover span {
  padding-right: 25px;
}
.button:hover span:after {
  opacity: 1;
  right: 0;
}
.containers-fluid {
  padding: 20px 50px;
  background-color: #000000;
  color: white;
}
<button class="button"><span>Proceed to Next Lesson </span>
</button>

<footer class="containers-fluid text-center">
</footer>

3 个答案:

答案 0 :(得分:1)

只需将样式float:right添加到button

即可

buttonfooter

之间添加此内容
<div class="clearfix"></div>

clearfix

的css
.clearfix{
 clear: both;
}

详细了解clearfix

&#13;
&#13;
.button {
  border-radius: 4px;
  background-color: #0FA0FF;
  border: none;
  color: #FFFFFF;
  text-align: center;
  font-size: 15px;
  padding: 10px;
  width: 200px;
  transition: all 0.5s;
  cursor: pointer;
  margin: 5px;
  float: right;
  display: block;
}
.button span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
}
.button span:after {
  content: '\00bb';
  position: absolute;
  opacity: 0;
  top: 0;
  right: -20px;
  transition: 0.5s;
}
.button:hover span {
  padding-right: 25px;
}
.button:hover span:after {
  opacity: 1;
  right: 0;
}
.containers-fluid {
  padding: 20px 50px;
  background-color: #000000;
  color: white;
}
.clearfix{
 clear: both;
}
&#13;
<button class="button"><span>Proceed to Next Lesson </span>
</button>
<div class="clearfix"></div>
<footer class="containers-fluid text-center">
</footer>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以使用float:right并将position属性设置为relative

答案 2 :(得分:0)

只需将它们包裹在display:flex;flex-direction:row;的容器中,然后将margin-right:0;应用于该按钮。

请参阅以下代码

.container{
  display:flex;
  flex-direction:column;
}
.button {
  border-radius: 4px;
  background-color: #0FA0FF;
  border: none;
  color: #FFFFFF;
  text-align: center;
  font-size: 15px;
  padding: 10px;
  width: 200px;
  transition: all 0.5s;
  cursor: pointer;
  margin: 5px 0 5px auto;
}
.button span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
}
.button span:after {
  content: '\00bb';
  position: absolute;
  opacity: 0;
  top: 0;
  right: -20px;
  transition: 0.5s;
}
.button:hover span {
  padding-right: 25px;
}
.button:hover span:after {
  opacity: 1;
  right: 0;
}
.containers-fluid {
  padding: 20px 50px;
  background-color: #000000;
  color: white;
}
<div class="container">
<button class="button"><span>Proceed to Next Lesson </span>
</button>

<footer class="containers-fluid text-center">
</footer>
</div>