【问题标题】:Wordpress responsive post image sizes on mobile移动设备上的 Wordpress 响应式帖子图像大小
【发布时间】:2018-02-20 08:39:19
【问题描述】:

我添加了自定义图像尺寸:

add_image_size( 'post-thumb', 350, 350,true);
add_image_size( 'post-thumb-large', 767, 350,true);
add_image_size( 'post-single', 1200, 520,true);

<?php
    if ( has_post_thumbnail() ) {
       the_post_thumbnail( 'post-thumb' );
    }
?>

<?php
    if ( has_post_thumbnail() ) {
       the_post_thumbnail( 'post-single' );
    }
?>

我希望从 400 像素到 767 像素的所有帖子图像(和单个帖子图像)都具有 post-thumb-large 大小和 post-thumb 大小。我认为解决方案是使用srcset 属性,但是在哪里以及如何添加它?

【问题讨论】:

标签: php html css wordpress


【解决方案1】:

请参考这篇关于 CSS-Tricks 的文章:https://css-tricks.com/responsive-images-youre-just-changing-resolutions-use-srcset/

您的转译后的 HTML 应该如下所示(根据上面的文章):

<img src="small.jpg" srcset="medium.jpg 1000w, large.jpg 2000w" alt="yah">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-03
    • 2023-03-12
    • 2013-07-28
    • 2016-02-15
    • 2016-10-14
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多