【问题标题】:flexslider on small screens小屏幕上的 flexslider
【发布时间】:2016-08-01 18:36:30
【问题描述】:

我在 Wordpress 网站上使用 Sparkling 主题。主题在页面顶部的 div 中使用 Flexslider。每张幻灯片都包含一个图像以及一个包含帖子标题和摘录的 div。

滑块是在 header.php 中构建的,就像在这个函数中一样:

function sparkling_featured_slider() {
   if ( is_front_page() && of_get_option( 'sparkling_slider_checkbox' ) == 1 ) {
      echo '<div class="flexslider">';
         echo '<ul class="slides">';
            $count = of_get_option( 'sparkling_slide_number' );
            $slidecat =of_get_option( 'sparkling_slide_categories' );

            $query = new WP_Query( array( 'cat' =>$slidecat,'posts_per_page' =>$count ) );
            if ($query->have_posts()) :
               while ($query->have_posts()) : $query->the_post();

               echo '<li>';
               if ( (function_exists( 'has_post_thumbnail' )) && ( has_post_thumbnail() ) ) :
                 echo get_the_post_thumbnail();
               endif;

               echo '<div class="flex-caption">';
                  if ( get_the_title() != '' ) echo '<h2 class="entry-title">'. get_the_title().'</h2>';
                  if ( get_the_excerpt() != '' ) echo '<div class="excerpt">' . get_the_excerpt() .'</div>';
              echo '</div>';
          echo '</li>';
          endwhile;
        endif;

  echo '</ul>';

echo ' </div>';

} } endif;

生成的 HTML 如下所示:

<div class="top-section">
    <div class="flexslider">
        <ul class="slides">
            <li>
                <img width="1920" height="512" src="http://pathtoslider.jpeg" 
                    class="attachment-post-thumbnail size-post-thumbnail wp-post-image" 
                    alt="slide1" 
                    srcset="pathstodifferentresolutions.jpg" 
                    sizes="(max-width: 1920px) 100vw, 1920px" />
                <div class="flex-caption">
                    <h2 class="entry-title">Tomatoes</h2>
                    <div class="excerpt">Knowledge is knowing that tomatoes are a fruit. Wisdom is knowing not to put them in a fruit salad.</div>
                    </div>
                </li>
                ..more slides..
        </ul>
    </div>
</div>

<div class="container main-content-area">

默认情况下,它通过在媒体查询中设置 display:none 来抑制小屏幕上的 flex-caption,但我想显示它,所以我在自己的媒体查询中将显示设置为内联。

这会导致另一个问题,因为整个顶部 div 是图像的高度,而 flex-caption 不一定有空间。

我希望 entry-title 的底部与图像的底部对齐,以及图像下方的摘录,我是这样完成的:

@media (max-width: 768px) {
  .flex-caption {
    display: inline;
    bottom: 0;
   }
  .entry-title {
    position: absolute;
    bottom: 0;
  }
  .excerpt {
    position: absolute;
    vertical-align: top;
  }
}

但这不会调整顶部 div 的大小,所以我要覆盖 main-content-area。

我尝试了很多不同的方法,包括几乎在任何地方都尝试过height:auto。

我无法弄清楚滑块高度是如何设置的。它似乎在 get_the_post_thumbnail 内。是这个问题吗?

【问题讨论】:

    标签: css flexslider


    【解决方案1】:

    您可以尝试在functions.php中设置图像高度 function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ).

    【讨论】:

    • 不。尝试 get_the_post_thumbnail($post_id, 'large') 更改了 img 标签中指定的大小,但根本没有更改功能
    猜你喜欢
    • 2019-06-23
    • 2021-07-17
    • 1970-01-01
    • 2021-06-05
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多