简体   繁体   English

使用Bootstrap 3为不同屏幕尺寸设置网站样式

[英]Styling website for different screen sizes with Bootstrap 3

I am using the following method to style my website for different screen sizes. 我使用以下方法为我的网站设置不同屏幕尺寸的样式。

<div id="sidebar" class="col-md-3 hidden-xs hidden-sm">
    <!-- Inner Classes and Stuff -->
    <!-- IMPORTANT: Div auto-inserted by Typo3 -->
</div>  <!-- sidebar -->

<div id="sidebar_mobile" class="col-xs-12 hidden-md hidden-lg">
    <!-- Inner Classes and Stuff -->
    <!-- IMPORTANT: Div auto-inserted by Typo3 -->
</div>  <!-- sidebar -->

I then define different styles that I need for #sidebar and #sidebar_mobile in my CSS. 然后我在CSS中定义了#sidebar和#sidebar_mobile所需的不同样式。 This leads to two problems: 这导致两个问题:

  • Repetition (there are many shared properties between #sidebar and #sidebar_mobile). 重复(#sidebar和#sidebar_mobile之间有许多共享属性)。
  • Duplicate IDs - The divs that are automatically inserted by Typo3 (Raw HTML content inserted via Typo3 backend) end up having the same ID (inside #sidebar and #sidebar_mobile). 重复ID - 由Typo3自动插入的div(通过Typo3后端插入的原始HTML内容)最终具有相同的ID(在#sidebar和#sidebar_mobile内)。 This fails WCAG 2.0 AA and I need my website to pass this. 这使WCAG 2.0 AA失败,我需要我的网站通过这个。

I would like to know if there is a better way of going about things in this case. 我想知道在这种情况下是否有更好的办法。 What would be a better solution 什么是更好的解决方案

Why are you using two different wrappers for mobile/desktop instead using CSS to style them individually: 为什么你使用两个不同的移动/桌面包装器而不是使用CSS来单独设置它们:

<div id="sidebar" class="col-sm-12 col-md-3">
    <!-- Inner Classes and Stuff -->
    <!-- IMPORTANT: Div auto-inserted by Typo3 -->
</div>
#sidebar {
    /* Mobile/Tablet styles (xs, sm) */
}
@media (min-width: 991px) {
    #sidebar {
        /* Tablet/Desktop styles (md, lg) */
    }
}

This is the mobile first variant. 这是移动的第一个变种。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM