【问题标题】:Issue regarding bootstrap collapse and it's effect on DOM关于引导崩溃的问题及其对 DOM 的影响
【发布时间】:2017-04-22 02:22:15
【问题描述】:

我在我的网页中使用引导程序。现在我想实现一个特定的效果。我有一个类名为“container-fluid”的 div 和一个带有文本的 h2 标签。就像下面这样:

<div class="container-fluid" style="background-color: #f8f8f8;text-align: center;height: 76px;">
    <br>
    <h2 id="mesheading" style="color: #a76281; font-size: 14px; cursor: pointer; margin-top: -4px; font-family: 'brandon_grotesquebold'; text-transform: uppercase; letter-spacing: 2px;">
        Helping manufacturers save 20%-30% of the store cost &nbsp;
        <span>
            <button class="button_one" type="button" onclick="open_win_two()">
                LEARN MORE
            </button>
        </span>
    </h2><br>
</div>

我的要求是当浏览器窗口折叠时,h2标签的字体大小会变小。例如它将变为 10px。

在浏览器窗口按实际大小展开时,它会变回原来的字体大小,即 14 像素

我对jQuery的崩溃相关事件做了很多研究。但这对我没有帮助。

所以请帮助我实现这一目标。

提前致谢!!!

【问题讨论】:

  • 查找 CSS 媒体查询

标签: jquery html css twitter-bootstrap collapse


【解决方案1】:

您应该像这样使用媒体查询的默认断点:

CSS

/* Extra Small Devices, Phones */ 
  @media only screen and (min-width : 480px) {
    .container-fluid h2 {
      your font size
      }
    }

/* Small Devices, Tablets */
  @media only screen and (min-width : 768px) {
    .container-fluid h2 {
      font-size: 10px;
    }
  }

/* Medium Devices, Desktops */
  @media only screen and (min-width : 992px) {
    .container-fluid h2 {
      your font size
    }
   }

/* Large Devices, Wide Screens */
  @media only screen and (min-width : 1200px) {
     .container-fluid h2 {
        your font size
    }
  }

【讨论】:

    【解决方案2】:

    问题

    根据屏幕大小更改元素的 css。

    解决方案

    您可以使用媒体查询来更改h2 或任何元素的字体大小。

    示例

    使用此媒体查询为您在查询中提供的两个宽度之间的任何内容设置条件。您可以通过更改minmax width 的宽度来重复使用它来创建多个场景。

     @media only screen and (min-device-width: 481px) and (max-device-width: 1024px) {
          .container-fluid h2 {
             font-size: 10px;
    }
        }
    

    然后,在媒体查询之外,对于不属于您的任何media queries 条件的任何内容,您都可以默认执行此操作。

    .container-fluid h2 {
        font-size: 14px;
    }
    

    定位特定设备

    以下是针对流行设备的一些更常见的必要媒体查询。

    /* Smartphones (portrait and landscape) ----------- */
    @media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
    /* Styles */
    }
    
    /* Smartphones (landscape) ----------- */
    @media only screen and (min-width : 321px) {
    /* Styles */
    }
    
    /* Smartphones (portrait) ----------- */
    @media only screen and (max-width : 320px) {
    /* Styles */
    }
    
    /* iPads (portrait and landscape) ----------- */
    @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
    /* Styles */
    }
    
    /* iPads (landscape) ----------- */
    @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
    /* Styles */
    }
    
    /* iPads (portrait) ----------- */
    @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
    /* Styles */
    }
    /**********
    iPad 3
    **********/
    @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {
    /* Styles */
    }
    
    @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {
    /* Styles */
    }
    /* Desktops and laptops ----------- */
    @media only screen  and (min-width : 1224px) {
    /* Styles */
    }
    
    /* Large screens ----------- */
    @media only screen  and (min-width : 1824px) {
    /* Styles */
    }
    
    /* iPhone 4 ----------- */
    @media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio : 2) {
    /* Styles */
    }
    
    @media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : portrait) and (-webkit-min-device-pixel-ratio : 2) {
    /* Styles */
    }
    
    /* iPhone 5 ----------- */
    @media only screen and (min-device-width: 320px) and (max-device-height: 568px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
    /* Styles */
    }
    
    @media only screen and (min-device-width: 320px) and (max-device-height: 568px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
    /* Styles */
    }
    
    /* iPhone 6 ----------- */
    @media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
    /* Styles */
    }
    
    @media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
    /* Styles */
    }
    
    /* iPhone 6+ ----------- */
    @media only screen and (min-device-width: 414px) and (max-device-height: 736px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
    /* Styles */
    }
    
    @media only screen and (min-device-width: 414px) and (max-device-height: 736px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
    /* Styles */
    }
    
    /* Samsung Galaxy S3 ----------- */
    @media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
    /* Styles */
    }
    
    @media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
    /* Styles */
    }
    
    /* Samsung Galaxy S4 ----------- */
    @media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 3){
    /* Styles */
    }
    
    @media only screen and (min-device-width: 320px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 3){
    /* Styles */
    }
    
    /* Samsung Galaxy S5 ----------- */
    @media only screen and (min-device-width: 360px) and (max-device-height: 640px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 3){
    /* Styles */
    }
    
    @media only screen and (min-device-width: 360px) and (max-device-height: 640px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 3){
    /* Styles */
    }
    

    【讨论】:

    • 如果您要在另一个问题中复制并粘贴其他人的答案,至少要感谢他们的工作
    • @RoryMcCrossan +1
    • 我没有复制和发布别人的代码。这来自我手头的 css 文件。如果你想让我用它们淹没墙壁,我还有很多。当这个问题一直被问到时,我已经在整个互联网上发布了这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-09
    • 2018-07-02
    • 1970-01-01
    • 2021-04-19
    • 2012-11-10
    • 1970-01-01
    相关资源
    最近更新 更多