我不知道如何将我的按钮向右浮动,希望有人能在这里帮助我。
黄色显示了div的背景。 div的宽度设置为50%。
.faq {
width: 100%;
padding: 12px 20px;
display: block;
box-sizing: border-box;
width: 50%;
margin: auto;
margin-top: 30px;
}
.outerDiv {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
margin-top: 20px;
background-color: yellow;
}
.save {
float: right;
background-color: red;
}
<div class="outerDiv">
<h2>New FAQ</h2>
<input type="text" class="faq">
<br>
<button class="save" mat-raised-button color="primary">Primary</button>
</div>
我做错了什么?
outerDiv
的样式会覆盖按钮上的浮动样式。您可以在.save
按钮中使用flexbox来右对齐,例如使用align-self
等。此外,请提供一个完整的可运行示例,使用Stackoverflow片段或代码沙箱。 - Abdulrahman Ali