【问题标题】:Resize Buttons for Mobile调整移动按钮的大小
【发布时间】:2015-01-30 08:11:47
【问题描述】:

我正在尝试将我网站上当前的 CSS 按钮设置为移动设备实际大小的 2 或 3 倍。我运气不佳

风格

.all-news-btn {
background: #666666;
background-image: -webkit-linear-gradient(top, #666666, #333333);
background-image: -moz-linear-gradient(top, #666666, #333333);
background-image: -ms-linear-gradient(top, #666666, #333333);
background-image: -o-linear-gradient(top, #666666, #333333);
background-image: linear-gradient(to bottom, #666666, #333333);
-webkit-border-radius: 3;
-moz-border-radius: 3;
border-radius: 3px;
font-family: Arial !important;
color: #ffffff !important;
font-size: 12px !important;
padding: 7px 8px 7px 7px;
text-decoration: none;
margin-left: 3px;
}

.all-news-btn:hover {
background: #666666;
background-image: -webkit-linear-gradient(top, #666666, #000000);
background-image: -moz-linear-gradient(top, #666666, #000000);
background-image: -ms-linear-gradient(top, #666666, #000000);
background-image: -o-linear-gradient(top, #666666, #000000);
background-image: linear-gradient(to bottom, #666666, #000000);
text-decoration: none;
}

媒体查询

@media only screen and (max-device-width: 480px) 
{
  .all-news-btn {width: 100%; font-size: 4.25em;}
}

【问题讨论】:

    标签: css button media-queries media


    【解决方案1】:

    工作示例

    .bt{
      background: #333;
      color: #fdfdfd;
      min-height: 35px;
      margin: 0;
      border-radius: 3px;
      border: 0;
      line-height: 35px;
      text-align: center;
      margin: .5em 0 .5em 0;
    
    }
    
    a.bt{
      display: inline;
      padding: 7px 10px 7px 10px;
    }
    
    .bt:hover{
      background: #000;
    }
    
    @media only screen and (max-width:480px) { 
      .bt {
        width: 100%;
      }
      
      a.bt{
        display: block;
        padding: 0;
      }
    }
    <button class="bt">Button example</button>
    <a class="bt">A example</a>
    <input class="bt" type="button" value="Input example"/>

    解决

    您可以通过将min-width 属性添加到主按钮类来轻松解决此问题。看看吧:

    也在JSFiddle :)

    或Codepen

    .all-news-btn {
      
      background: #666666;
      
      background-image: -webkit-linear-gradient(top, #666666, #333333);
      background-image: -moz-linear-gradient(top, #666666, #333333);
      background-image: -ms-linear-gradient(top, #666666, #333333);
      background-image: -o-linear-gradient(top, #666666, #333333);
      background-image: linear-gradient(to bottom, #666666, #333333);
      
      -webkit-border-radius: 3;
      -moz-border-radius: 3;
      border-radius: 3px;
      
      font-family: Arial !important;
      color: #ffffff !important;
      font-size: 12px !important;
      padding: 7px 8px 7px 7px;
      text-decoration: none;
      margin-left: 3px;
    
      min-width: 100px;
      min-height: 30px;
      display: inline;
    }
    
    .all-news-btn:hover {
      background: #666666;
      background-image: -webkit-linear-gradient(top, #666666, #000000);
      background-image: -moz-linear-gradient(top, #666666, #000000);
      background-image: -ms-linear-gradient(top, #666666, #000000);
      background-image: -o-linear-gradient(top, #666666, #000000);
      background-image: linear-gradient(to bottom, #666666, #000000);
      text-decoration: none;
    }
    
     @media only screen and (max-width:480px) { 
      .all-news-btn {width: 100%; font-size: 4.25em; }
    }
    <button class="all-news-btn">Button example</button>
    <input class="all-news-btn" type="button" value="Input example"/>

    【讨论】:

    • 这成功了!谢谢...我确实必须取出字体大小上的 !important 标签,才能使媒体选项起作用。非常感谢!
    • 我是这个论坛的新手 - 两个答案都有效,但它是第二个最适合我的项目的答案 - 我不知道如何做到这一点.. 但感谢你们俩。
    猜你喜欢
    • 2019-11-20
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多