【问题标题】:How do I make two buttons side by side and responsive?如何使两个按钮并排并响应?
【发布时间】:2017-08-08 17:22:58
【问题描述】:

我有一个小任务,它需要在使用桌面时将两个按钮并排放置,然后在移动设备上将它们堆叠在一起,但尺寸并没有减小。

我设法让它们堆叠在一起,但它们的尺寸不同?每当我定义按钮的 % 大小时,它会使它们挤在一起,在设备视图中看起来很可怕。

.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>


        

【问题讨论】:

  • 你能展示你的 HTML 吗?
  • 你好 Jasmine,你能在 jsfiddle 中提供你的代码和 html 部分吗
  • 我不习惯 jsfiddle 所以我希望这有帮助! jsfiddle.net/#&togetherjs=MK4G42vSV0

标签: html css button responsive-design


【解决方案1】:

将它们包裹在一个div中,给它们percentage width,让div拥有

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

填充可能会扰乱响应,所以也要注意这一点

【讨论】:

  • 谢谢!最后我确实将它们包装在一个名为 container 的 div 中,并使用了 text-align: center。但是以后我会用这个!哎呀,我知道。幸运的是,在他们要求的视图中看起来没问题!
  • @Jasmine google 类似 flex froggy,它是一些你在 css 中学习 flex 的游戏,它非常有用并且比使用引导网格 imo 好得多
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-12-01
  • 1970-01-01
  • 2017-02-06
  • 2020-09-23
  • 2013-05-09
  • 2020-11-16
  • 1970-01-01
相关资源
最近更新 更多