【问题标题】:Media query not working for specific div class媒体查询不适用于特定的 div 类
【发布时间】:2015-07-24 06:34:19
【问题描述】:

我在互联网上进行了彻底搜索,但无济于事。目前我有 left-authorright-author 类的以下文本

#wrapper-author {
  margin: 0 auto;
  padding: 15px;
  overflow: auto;
}
.left-author {
  width: 50%;
  vertical-align: top;
  float: left;
}
.right-author {
  width: 50%;
  vertical-align: top;
  float: right;
}

这用于媒体查询。除了left-authorright-author 之外的每个查询都可以。

@media screen and (max-width: 380px) {
  .left-author .right-author {
    float: none;
    width: 100%;
    vertical-align: initial;
  }
  .widget_highlighted_posts .single-article {
    float: none;
    margin-right: 0;
    max-width: 100%;
  }
}

有人知道我做错了什么吗?这是 HTML....

<div id="wrapper-author">

  	<div class="left-author clearfix">

<h4>I guess you want to know who <?php the_author(); ?> is.</h4>

<span style="font-family: sofia-pro; font-size: 20px;"><?php the_author_meta( 'description' ); ?></span><?php
$count_posts = wp_count_posts();

$published_posts = $count_posts->publish;
?>

  	</div>
  	<div class="right-author clearfix">
<?php userphoto_the_author_photo() ?>

<div class="social-links">
<ul>
<li  style="font-family: aw-conqueror-carved-one;">Follow <?php the_author_meta( first_name ); ?> on</li>
		<?php $facebook = get_the_author_meta('facebook'); if ($facebook) { ?><li><a href="<?php the_author_meta('facebook'); ?>"  target="_blank"><i class="fa fa-facebook"></i></a></li><?php } ?>
		<?php $twitter = get_the_author_meta('twitter'); if ($twitter) { ?><li><a href="http://twitter.com/<?php the_author_meta('twitter'); ?>"  target="_blank"><i class="fa fa-twitter"></i></a></li><?php } ?>
		<?php $googleplus = get_the_author_meta('googleplus'); if ($googleplus) { ?><li><a href="<?php the_author_meta('googleplus'); ?>"  target="_blank"><i class="fa fa-google-plus"></i></a></li><?php } ?>
        <?php $instagram = get_the_author_meta('instagram'); if ($instagram) { ?><li><a href="<?php the_author_meta('instagram'); ?>"  target="_blank"><i class="fa fa-instagram"></i></a></li><?php } ?>
        <?php $pinterest = get_the_author_meta('pinterest'); if ($pinterest) { ?><li><a href="<?php the_author_meta('pinterest'); ?>"  target="_blank"><i class="fa fa-pinterest"></i></a></li><?php } ?>
        <?php $email = get_the_author_email(); if ($email) { ?><a href="mailto:<?php the_author_email(); ?>"><i class="fa fa-envelope"></i></a></li><?php } ?>
        <li><a href="http://maphappy.org/author/<?php the_author_meta( 'user_login' ); ?>/feed/"><i class="fa fa-rss"></i></a></li>
		</ul></div>

	</div>
</div>

【问题讨论】:

  • 任何 HTML 与该 CSS 一起使用?
  • 我刚刚添加了它——很抱歉被否决了,我是 Stack Exchange 的新手!

标签: html css responsive-design media-queries


【解决方案1】:

您缺少逗号 , 以在同一声明中分隔 2 个类

@media screen and (max-width: 380px) {
  .left-author, .right-author {
    float: none;
    width: 100%;
    vertical-align: initial;
  }
  .widget_highlighted_posts .single-article {
    float: none;
    margin-right: 0;
    max-width: 100%;
  }
}

更新:(OP已给出HTML代码)

您在 a href:mailto 之前缺少一个 li 打开标签(从我在这里看到的不是问题)

所以,这是一个包含您的 HTML 的 sn-p(不包括 PHP 标记):

* {
    box-sizing:border-box;
    /*demo , applies box-model */
}
#wrapper-author {
    margin: 0 auto;
    padding: 15px;
    overflow: auto;
}
.left-author {
    width: 50%;
    vertical-align: top;
    float: left;
    border:1px dashed green   /* demo styles */
}
.right-author {
    width: 50%;
    vertical-align: top;
    float: right;
    border:1px dashed red   /* demo styles */
}
@media screen and (max-width: 380px) {
    .left-author, .right-author {
        float: none;
        width: 100%;
        vertical-align: initial;
    }
    .widget_highlighted_posts .single-article {
        float: none;
        margin-right: 0;
        max-width: 100%;
    }
}
<div id="wrapper-author">
  <div class="left-author clearfix">

    <h4>I guess you want to know who is.</h4>

    <span style="font-family: sofia-pro; font-size: 20px;"></span> 
  </div>
  <div class="right-author clearfix">
    <div class="social-links">
      <ul>
        <li style="font-family: aw-conqueror-carved-one;">Follow
          <li><a href="" target="_blank"><i class="fa fa-facebook"></i></a>

          </li>
          <li><a href="" target="_blank"><i class="fa fa-twitter"></i></a>

          </li>
          <li><a href="" target="_blank"><i class="fa fa-google-plus"></i></a>

          </li>
          <li><a href="" target="_blank"><i class="fa fa-instagram"></i></a>

          </li>
          <li><a href="" target="_blank"><i class="fa fa-pinterest"></i></a>

          </li>
         <!--the opening LI tag was missing here below -->
          <li><a href="mailto:"><i class="fa fa-envelope"></i></a>

          </li>
          <li><a href="http://maphappy.org/author/feed/"><i class="fa fa-rss"></i></a>

          </li>
      </ul>
    </div>
  </div>
</div>

【讨论】:

  • Dippas,我进行了更改,但这不起作用。没有逗号,其他所有类似乎也能正常工作。
  • 你需要向我们展示一些相关的 HTML,但这肯定是一个错误
猜你喜欢
  • 2021-10-04
  • 2018-05-12
  • 2013-08-07
  • 2013-06-05
  • 2015-09-06
  • 2015-12-18
  • 2013-12-05
  • 2017-12-02
  • 1970-01-01
相关资源
最近更新 更多