【发布时间】: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 之外的那一刻。如果这有意义的话。