【问题标题】:(SCSS) My media queries aren't working correctly with display: flex;(SCSS) 我的媒体查询无法正常使用 display: flex;
【发布时间】:2019-01-24 20:23:44
【问题描述】:

我正在使用 SCSS 尝试创建一个响应式网站。我正在使用 Koala 编译我的代码,并且我有一个 styles.scss 正在导入我的其他部分样式表。更改宽度时,某些样式确实在我的网站上动态工作,但使用我的显示:事情并没有改变到我想要的样子。

我尝试将媒体查询更改为嵌套在自身内部,但没有任何工作正常。

styles.scss

@import "reset";

@import "variables";

// @media only screen and (min-width: 1em) {
@import "small-default";
// }

//35em is also 560px (if basefont is 16px)
@media only screen and (min-width: 560px) {
@import "medium";
}

//64em is also 1028px (if basefont is 16px)
@media only screen and (min-width: 1028px) {
@import "large";
} 

index.html

<div class="footer">
        <footer>
          <div class="info">
              <div class="contact">
                <h2>Contact Us</h2>
                <p>CABOT CRUIZES</p>
                <p>23 South Main St. Suite 16</p>
                <p>Lexington, VA 24450</p>

                <br>
                <h2>Phone:</h2>
                <p>1-800-555-1234</p>

                <br>

                <h2>Hours of Operation:</h2>
                <p>Monday - Friday 9am - 4pm</p>
              </div>

              <div class="newsletter">
                <h2>News Letter</h2>
                <p>Subscribe to our email list and stay up-to-date with our hottest offers and latest specials.</p>

                <div class="subscribe">
                    <input type="email" name="" id="subscribeEmail">
                    <button type="submit">Subscribe</button>
                </div>
              </div>
            </div>  

              <div class="why">
                <h2>Why Cabot Cruises?</h2>
                <p>Cabot Cruises is a travel agency providing the best cruise deals on our online travel website. We can help you with all inclusive vacations including discounted cruises.</p>
                <br>
                <p>We do not sell travel to residents of Deleware, Iowa, Florida, Hawaii and Washington state because those states are just wierd. If you are a resident of one of these states, call your congressman and tell them to change the regulations. </p>
              </div>


        </footer>
      </div>

_small-default.scss

.footer {
  background-color: $secondaryColor;

  footer {
    max-width: 1024px;
    margin: 0 $gutter;
    padding: 1rem 0;
    color: $thirdColor;


    .info {
      margin: 0 auto;
      color: $thirdColor;

      display: flex;
      flex-direction: column;




      .contact, .newsletter, .why {
        padding: .5rem 0;
      }

      .contact {
      }

      .newsletter {
        display: flex;
        flex-direction: column;
        justify-content: center;


        .subscribe {
          display: flex;
          flex-direction: column;
          justify-content: center;

          input{
            height: 35px;
            margin-bottom: .2rem;
          }

          button {
            height: 44px;
            background-color: #666;
            border-radius: 10px;
            color: #fff;
          }
        }
      }

      .why {
      }



      h2{
        margin-bottom: .75rem;
      }
      input {
        margin-top: .6rem;
      }
    }


  }
}

_medium.scss (我只是想对布局做一个简单的方向改变,但没有任何效果。)

footer {

    .info {
        flex-direction: row;
    }
}

【问题讨论】:

  • 您好 manuel.espinoza 我们可以查看相关代码以更好地帮助您解决此问题吗?您在媒体查询中使用 em 而不是像素是否有特殊原因?
  • 我更新了提供的代码。如果您需要任何进一步的说明,请告诉我。我也选择了 ems,因为它的代码有点旧。我切换回 px 并没有任何变化。
  • 好的,谢谢,我去看看。只需确保在使用 ems 之前在 safari 中进行彻底测试
  • 快速浏览一下,您在 small.scss 中将其称为 .footer footer .info 并在 medium.scss 中将其称为 footer .info ,除非我遗漏了一些您的 small 比您的更具体的东西中..如果你走另一条路,我可能是错的..IE从中到小
  • .footer 在 small.scss 上以建立一些默认样式,在我的媒体上,为了便于查找,我的页脚是空的,但我没有设置任何其他样式除了试图改变我的 .info 的 flex-direction 之外的那一刻。如果这有意义的话。

标签: html css sass flexbox


【解决方案1】:

应该是

.footer {
  footer {
     .info {
        flex-direction: row;
    }
  }
}

.footer footer .info {
    flex-direction: row;
}

如果您想像在 medium.scss 中那样调用它

【讨论】:

  • 这样就行了。您不能直接引用对象吗?我的问题是,如果我只是引用 .info,为什么它不起作用?
  • 特异性规则。如果您之前引用了 .footer footer .info 并声明了您的 css(例如 padding: 1px ...),那么稍后您尝试更改 padding 的引用方式,它需要与您的引用方式相同或更具体第一次引用它。因此,如果您在小型 scss 中将其引用为 .info,那么您只需在 medium.scss 中引用 .info 即可。让我知道这是否没有意义。如果你看我上面的两个例子,它们是完全一样的......一旦 scss 被编译成 css
  • 这很有意义,我只是试图绕过以前的所有内容,但它无法正常工作。感谢您的帮助。
  • 没问题的老板,如果我们都在这里完成,请把那个复选标记打掉。请和谢谢你
猜你喜欢
  • 2022-01-05
  • 2021-01-25
  • 1970-01-01
  • 2014-02-25
  • 2016-12-13
相关资源
最近更新 更多