【问题标题】:How to use two different designs for web and mobile如何为 Web 和移动设备使用两种不同的设计
【发布时间】:2016-08-31 23:17:25
【问题描述】:

我希望能够为我的网页设计一种特定的设计,并在调整到移动设备的大小时使用不同的设计。我会附上照片以更好地解释。

这是我想使用的设计 Web 这是草图 Mobile 我目前不完全确定如何使用媒体查询 这是到目前为止的代码

HTML 婴儿 2岁以上儿童

    <div class="row">
        <div class="full-time col-sm-12 col-md-12 col-lg-2">Full Time</div>
        <div class="prices-left-box col-sm-12 col-md-12 col-lg-5">
            <div class="prices-left">$200 Per Week</div>
        </div>
        <div class="prices-right-box col-sm-12 col-md-12 col-lg-5">
            <div class="prices-right">$150 Per Week</div>
        </div>
    </div>
    <div class="row">
        <div class="full-time col-sm-12 col-md-12 col-lg-2">Up to 4 Hours</div>
        <div class="prices-left-box col-sm-12 col-md-12 col-lg-5">
            <div class="prices-left">$125 Per Week</div>
        </div>
        <div class="prices-right-box col-sm-12 col-md-12 col-lg-5">
            <div class="prices-right">$100 Per Week</div>
        </div>
    </div>
</div>

还有 CSS:

@media (max-width: 992px) {
    .infants{
        color: black;
        background-color: #7FC7AF;
        font-size: 36px;
        font-weight: bold;
        font-family: "open sans";
        height: 125px;
        width: 304.3px;
        text-align: center;
        margin: auto;
        display: inline-block;
    }

    .children{
        color: black;
        background-color: #FF9E9D;
        font-size: 36px;
        font-weight: bold;
        font-family: "open sans";
        height: 125px;
        width: 304.4px;
        text-align: center;
        padding: auto;
        display: inline-block;
    }
}

.infants{
    color: white;
    background-color: #7FC7AF;
    font-size: 36px;
    font-weight: bold;
    font-family: "open sans";
    height: 87px;
    width: 304.3px;
    text-align: center;
}

.infants-box{
    padding-left: 176px;
    padding-right: 80px;
}

.children{
    color: white;
    background-color: #FF9E9D;
    font-size: 36px;
    font-weight: bold;
    font-family: "open sans";
    height: 87px;
    width: 304.4px;
    text-align: center;
}

.payment-method{
    font-size: 24px;
    padding-bottom: 57px;
    padding-top: 57px;
    text-align: center;
    font-family: "Source Sans Pro";
    font-weight: 600;
    font-style: italic;
    font-size: 24px;
    line-height: 30px;
    color: #4B4B4B
}

.full-time{
    background-color: #454545;
    color: white;
    font-size: 24px;
    font-weight: bold;
    font-family: "open sans";
    height: 150px;
    margin: auto;
    width: 176px;
    text-align: center;
}
.prices-left-box{
    background-color: white;
    width: 304.4px;
    height: 150px;
}
.prices-left{
    font-family: "source sans pro";
    font-size: 24px;
    width: 304.3px;
    margin-right: 220px;
    text-align: center;
}

.prices-right-box{
    background-color: #ffffff;
    width: 304.4px;
    margin-left: 10%;
    height: 150px
}

.prices-right{
        font-family: "source sans pro";
    font-size: 24px;
    background color: white !important;
    text-align: center;
}
.background-pricing{
    background-color: #F0F0F0;
    padding-bottom: 84px;
}

【问题讨论】:

    标签: html css twitter-bootstrap mobile web


    【解决方案1】:

    无论您使用的是Bootstrap,只需引用grid 并将更改应用于引用的类名。您还可以在文档中看到这些Responsive Utilities

    如果您确实需要使用上面的代码,请尝试像这样重写上面的 sn-p:

    @media only screen and (max-width: 992px) {
        .infants{
               /* 
               Custom CSS here 
               ...
               */
         }
    }
    

    【讨论】:

    • 我需要为移动设备创建一个全新的 html 吗?我试着玩网格,但它把设计扔得一塌糊涂
    • Bootstrap 的默认设置是用于超小屏幕。 col-xs-12 等。尝试从手机开始,然后使用更大的屏幕。您当然不需要创建完全不同的 HTML(大多数时候)。您只需要更改一些网格类。
    • 还可以尝试使用offset,即col-lg-2 col-lg-offset-4 来居中您的内容
    • 我需要为移动设备创建单独的行吗?还是引导程序会自动堆叠所有内容? (谢谢耐心,哈哈)
    • np,bootstrap 会在没有新行的情况下为移动设备堆叠它
    【解决方案2】:

    我建议您查看http://getbootstrap.com/css/#gridBootstrap Responsive Utilities 上的文档,以创建一个响应式布局,为较小的移动屏幕堆叠您的行网格结构。

    我建议首先为移动设备而不是桌面构建布局。使用.col-xs-* 调整您的移动布局,然后使用.col-sm-* 移动到平板电脑尺寸,使用.col-md-* 移动到更大的平板电脑和台式机,最后使用.col-lg-* 移动到大型设备桌面。有关选项的一个很好的示例,请参阅此代码笔 - http://codepen.io/arsinak/pen/qDgvt/

    通过在列中添加 .col-xs-* .col-md-* 来使用额外的中小型设备网格类。 Example: Mobile and desktop.

    您不需要在自己的 css 中为您的容器和网格系统定义媒体查询,bootstrap 会处理这个问题。如果您需要基于媒体查询定义 CSS。我建议先为移动设备创建 CSS,然后根据屏幕大小进行横向扩展。

    /*==========  Mobile First Method  ==========*/
    
    /* Custom, iPhone Retina */
    @media only screen and (min-width : 320px){
    
    }
    
    /* Extra Small Devices, Phones */
    @media only screen and (min-width : 480px){
    
    }
    
    /* Small Devices, Tablets */
    @media only screen and (min-width : 768px){
    
    }
    
    /* Medium Devices, Desktops */
    @media only screen and (min-width : 992px){
    
    }
    
    /* Large Devices, Wide Screens */
    @media only screen and (min-width : 1200px){
    
    }
    

    此外,为了清理您的 CSS 并减少重复代码,我建议您使用 SASSBEM Methodology 以更清晰、易于理解和维护的方式构建您的 CSS。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-26
      • 1970-01-01
      • 2021-01-27
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多