如何修复wordpress中的响应式图像错误?

问题描述 投票:0回答:3

我正试图在wordpress上制作一个响应主题。当我使用桌面分辨率时,缩略图会100%调整到卡上,但是当我将分辨率降低到移动设备时,它会比卡大。为什么会这样?

我已经尝试添加bootstrap 4响应式图像类。

<section id="blog" class="blog  d-flex align-items-center mt-5 mb-5">

  <?php query_posts('posts_per_page=3'); ?>


  <div class="container">
<div class="d-flex align-items-center">

 <h1>ÚLTIMAS<BR>PUBLICAÇÕES</h1> </div>    <div class="row">


      <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
      <div class="col-sm-7 col-md-4 mt-3">

        <a href="<?php the_permalink() ?>"><img src="<?php the_post_thumbnail_url('thumbnail'); ?>" class="rounded-top"></a>
        <div class="card-body border rounded-bottom">

          <h4 class="card-title border-bottom pb-3 "><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h4>
          <p class="card-text"><?php the_subtitle(); ?></p>
          <a href="<?php the_permalink() ?>" class="btn btn-outline-dark btn-sm">Continuar lendo</a>
        </div>

      </div>

      <?php endwhile; ?>

      <?php endif; ?>




    </div>
</section>

预期:

enter image description here

现实:

enter image description here

在wordpress管理面板上配置的缩略图大小为350 x273px

wordpress twitter-bootstrap thumbnails
3个回答
0
投票

请为您的图片添加“img-responsive”类。应该是正确的代码

<section id="blog" class="blog  d-flex align-items-center mt-5 mb-5">

  <?php query_posts('posts_per_page=3'); ?>


  <div class="container">
<div class="d-flex align-items-center">

 <h1>ÚLTIMAS<BR>PUBLICAÇÕES</h1> </div>    <div class="row">


      <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
      <div class="col-sm-7 col-md-4 mt-3">

        <a href="<?php the_permalink() ?>"><img src="<?php the_post_thumbnail_url('thumbnail'); ?>" class="rounded-top img-responsive"></a>
        <div class="card-body border rounded-bottom">

          <h4 class="card-title border-bottom pb-3 "><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h4>
          <p class="card-text"><?php the_subtitle(); ?></p>
          <a href="<?php the_permalink() ?>" class="btn btn-outline-dark btn-sm">Continuar lendo</a>
        </div>

      </div>

      <?php endwhile; ?>

      <?php endif; ?>
    </div>
</section>

0
投票

使用一些保持宽度的CSS来定位您的图像。你目前有类rounded-top,所以你可以添加这个CSS:

.rounded-top {
  max-width: 100%;
  height: auto;
}

0
投票

我通过将.card-img添加到img标记来解决问题。

谢谢大家的答案。

© www.soinside.com 2019 - 2024. All rights reserved.