如何使两个按钮并排并响应?

问题描述:

我有一个小任务,它需要两个按钮并排使用桌面时,然后在移动时,他们堆叠在彼此的顶部,但没有减少大小。如何使两个按钮并排并响应?

我已经设法使他们堆叠在一起,但他们是不同的大小?每当我定义按钮的百分比大小时,它们会使它们在设备视图中挤在一起并看起来很丑。

.button { 
 
    background-color: #f2f2f2;; 
 
    border: none; 
 
    color: #737373; 
 
    padding: 15px 32px; 
 
    text-align: center; 
 
    text-decoration: none; 
 
    display: inline-block; 
 
    font-size: 16px; 
 
    margin: 4px 2px; 
 
    cursor: pointer; 
 
    border-radius: 4px; 
 
    border: 2px solid #003366; 
 
    font-family: sans-serif; 
 
    font-style: italic; 
 
    font-weight: bold; 
 
    font-size:0.875em; 
 
     display: inline-block;} 
 
.button2 { 
 
background-color: #003366; 
 
border: none; 
 
color: white; 
 
padding: 15px 32px; 
 
text-align: center; 
 
text-decoration: none; 
 
display: inline-block; 
 
font-size: 16px; 
 
margin: 4px 2px; 
 
cursor: pointer; 
 
border-radius: 4px; 
 
border: 2px solid #003366; 
 
font-family: sans-serif; 
 
font-style: italic; 
 
font-weight: bold; 
 
font-size:0.875em; 
 
    display: inline-block;}
<div class="booking"> 
 
     <h2><i class="fa fa-check-circle" aria-hidden="true"   
 
     style="color:#33cc33;""> </i> Congratulations your jet2 holiday 
 
     booking has been confirmed</h2> 
 

 
     <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. 
 
     Consectetur inventore, dignissimos quasi fuga sunt, nihil nemo 
 
     labore? Molestiae, eum, eos! Illum non laborum asperiores, 
 
     mollitia minima quasi atque. Eligendi, atque.</p> 
 

 

 
    <button class="button">Cancel</button> 
 
    <button class="button2">Continue</button> 
 

 
</div> 
 

 

 
    

+1

你可以请你展示你的HTML吗? –

+0

你好茉莉花,你能提供你的代码在HTML部分jsfiddle –

+0

我不习惯jsfiddle,所以我希望这是有帮助的! https://jsfiddle.net/#&togetherjs=MK4G42vSV0 – Jasmine

总结他们在一个div,给他们percentage width,使格已经

div{ 
    display: flex; 
    justify-content: space-between; 
} 

填充可能可能陷入困境的反应,所以要意识到这一点,以及

+0

谢谢!我最后将它们包装在一个名为container的div中,并使用了text-align:center。但将来我会用这个!嗨,我知道。幸运的是,他们所要求的观点看起来没问题! – Jasmine

+0

@Jasmine谷歌的东西像flex froggy,它的一些游戏,你在CSS学习flex,这是非常有用的,比使用引导网格更好imo – grabnem