【问题标题】:How to make a picture responsive that is on wordpress custom post type through HTML/CSS如何通过 HTML/CSS 使图片在 wordpress 自定义帖子类型上具有响应性
【发布时间】:2015-05-07 23:03:19
【问题描述】:

我是一名新手,工作深入,包括 Wordpress 和自定义类型帖子类型。我已将我的图像正确放置到 wordpress 中,并已成功将照片应用到“关于页面”上。就桌面模式而言,它工作得很好,但是当我响应并将其带到平板电脑/移动设备时,图片状态为静止,并且在转换为平板电脑/移动设备界面时没有响应。我一直在摆弄边距,将我的样式语法应用到不同的媒体查询中,但是一旦将响应式页面带到平板电脑或移动设备上,似乎没有任何结果。这是我目前拥有的 HTML 代码和 CSS 代码。

HTML

<?php 
/*
Template Name: About
*/
?>
<?php get_header(); ?>

<div class="about" style="">
    <h1>Why?</h1>
</div>

<div class="about">
    Many may ask the question "Why". Questions such as; "Why is this website relevant?", "Why do I need to know this?" or "Why does this topic even matter?"
    Many of those questions can be anwsered in different ways, with different attitudes and opinions, yet the only importance this website offers is Knowledge.
    The access of clear and ordered catagories of famous people from the actors all the way up to our goverment officials whom represent us, the United States citizens, the opportunity for individuals that may have this disability to understand that it does not make you less from anyone else, and that it simply gives you the power to express who you are and reach milestones in your lifetime that many "ordinary" people don't.
</div>

<div class="about" style="">
    <h1>General Statistics</h1>
</div>

<div class="about">
    <img src="<?php the_field('data_graphic');?>"/>
</div>  

<main role="main" class="col-md-3">
<!-- section -->
    <section>
        <?php if (have_posts()): while (have_posts()) : the_post(); ?>
            <!-- article -->
            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

                <?php the_content(); ?>

                <br class="clear">
            </article>
            <!-- /article -->

        <?php endwhile; ?>
        <?php else: ?>
            <!-- article -->
            <article>
                <h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
            </article>
            <!-- /article -->

        <?php endif; ?>

        </section>
        <!-- /section -->
    </main>

    <?php //get_sidebar(); ?>

<?php get_footer(); ?>

**CSS**

.about img {
  max-width: 100%%;
  vertical-align: bottom;
  margin-left: 150px;
}

如果有人可以帮助我解决这个响应问题,将不胜感激。

【问题讨论】:

  • 你的最大宽度有 2%,它应该只有 1%,比如:max-width:100%;
  • 谢谢,我在最后一分钟才注意到,并进行了快速更改,非常感谢!

标签: php html css wordpress


【解决方案1】:

我喜欢这样:

.about img{
    max-width:100% !important;
    height:auto;
    display:block;
}

注意:这是响应式图片,我去掉了位置规则,因为你可以自己调整

【讨论】:

  • 简单,它总是独立于浏览器大小获得最大宽度。如果您的浏览器/块将有 200 像素...图像将 100% 最大为 200 像素。
  • 您为什么使用heightdisplay 以及为什么删除vertical-alignmargin-left
  • height:auto -> 比例图像; display:block -> 顾名思义,像块一样; margin-left: 150px -> 没有理由
  • 不需要“!important”,只有在有真正充分的理由时才使用它
  • 是的...但是是为了避免测试解决方案出现问题或误解。我认为这是一个很好的理由!
【解决方案2】:

您的图片需要填充 100% 的容器。

.about img {
  width: 100%;
  vertical-align: bottom;
  margin-left: 150px;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 2014-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-15
    相关资源
    最近更新 更多