html - 多个元素的媒体查询

标签 html css media-queries

媒体查询的新手。但我想我错过了某个地方。

假设我有一个 topBar,如下面的代码片段所示,由一个 topBar 容器、固定宽度和一个列表组成,整个单元向右浮动。我希望只要屏幕大小调整到 1000px,topBar 在调整大小时随屏幕一起缩小。当它达到 1000px 时会发生其他事情,但我们可以稍后再担心。

为此,我需要为 topBar 容器和 topBar 固定宽度设置查询,还是只为容器设置查询?另外,我应该针对整个屏幕设置最大宽度还是最小宽度?

#top-menu
{
    width: 100%;
    background-color: white;
    height: 40px;
    color: #00a5b5
}

#topMenu-fixedWidth
{
    height: 80px;
    width: 1156px;
    color: #00a5b5;
    margin: 0 auto;
}

#topMenu-fixedWidth ul
{
    list-style: none;
    float: right;
    margin-right: 5px;
}

#topMenu-fixedWidth ul:nth-child(4)
{
    margin-right: 0;
}

#topMenu-fixedWidth ul li
{
    float: left;
    margin: 10px;
      <div id="top-menu">
            <div id="topMenu-fixedWidth">
                <ul>
                    <li class="topMenuText">Partners</li>
                    <li class="topMenuText">Careers</li>
                    <li class="topMenuText">Language</li>
                    <li class="topMenuText">Login</li>
                </ul>
            </div>
        </div>

最佳答案

由于您希望内容随屏幕大小一起调整大小,因此您应该使用 viewport percentage长度,例如 vhvw。元素将根据视口(viewport)调整大小。

Also, is it a Max width or a min width that I should be targeting for the overall screen?

要么。没关系,除非您有特殊需要。

@media ( min-width: 1000px ) {
    /* executes code here when the screen is 1000px or more */   
}

@media ( max-width: 1000px ) {
    /* executes code here when the screen is 1000px or less */   
}

更多信息:

关于html - 多个元素的媒体查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41684769/

相关文章:

jquery - 使用 html5 验证和 jquery ajax 提交表单

PHP 未知发件人

java - 在没有站点 :site? 的情况下从 Maven 生成 Findbug HTML 报告的任何简单方法

python - 使用python从wix获取数据(文本)

Flash 视频在 IE7 中的所有其他内容之上播放

html - 文本框的垂直对齐方式

CSS:@media print & column-count 根本不起作用

css - iPhone 上的媒体查询

jquery - css3pie 框阴影在 ie8 中不起作用

html - 响应式样式表根本无法根据屏幕尺寸工作