简体   繁体   English

告诉div根据屏幕大小更改大小时遇到​​问题

[英]Having problems telling a div to change sizes based on screen size

I am making site in Dreamweaver(with bootstrap.) I am trying to tell the div to be at 75% width when screen is larger then 992px, and 100% width when screen is smaller then 992px. 我正在Dreamweaver中创建站点(带有bootstrap。),我试图告诉div当屏幕大于992px时宽度为75%,而当屏幕小于992px时宽度为100%。 Any ideas what i might be doing wrong? 任何想法,我可能做错了什么?

@media (min-width: 768px) and (max-width: 991px){
}
 .bar {
   width: 100%;
   background-color: #C54345;
}
@media (min-width: 992px) {
}
 .bar {
   width: 75%;
   background-color: #C54345;
}

It very well could be being overridden. 很有可能被覆盖。 A good way to check this is by launching your project in the browser and using the Developer Tools to see what CSS is being overridden denoted by a slash going through it. 检查此问题的一种好方法是在浏览器中启动项目,并使用开发人员工具查看正被斜杠表示的CSS被覆盖的情况。

Typically though, I wouldn't take this sort of approach. 通常,尽管如此,我不会采用这种方法。 I don't know your exact situation, but doing this isn't really going to cut it in the terms of standards. 我不知道您的确切情况,但是这样做并不能真正减少标准方面的负担。

Instead, because you're using bootstrap, I suggest looking in to "hidden-xs"/"visible-xs" classes built in to bootstrap. 相反,因为您使用的是引导程序,所以我建议查看引导程序中内置的“ hidden-xs” /“ visible-xs”类。 I'm guessing you're trying to do something different on a tablet than you would a larger screen size or vice-versa. 我猜您正在尝试在平板电脑上做一些不同于更大屏幕尺寸的事情,反之亦然。

You have brackets in the wrong places, you've closed the media query braces immediately after you opened them! 您将括号放在错误的位置,打开媒体查询括号后立即将其关闭! otherwise the code is fine. 否则代码就可以了。
Your code should look like this: 您的代码应如下所示:

@media (min-width: 768px) and (max-width: 991px){
    .bar {
       width: 100%;
       background-color: #C54345;
    }
}
@media (min-width: 992px) {
     .bar {
       width: 75%;
       background-color: #C54345;
    }
}

working demo here 这里工作演示

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

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