CSS - 在Wordpress中重新调整大小时,元素不会堆叠在一起

时间:2017-08-02 08:26:37

标签: php css wordpress responsive-design

我正在将一些媒体查询样式规则应用于wordpress网站。一节有两排3 x 4列。在每一行中都有一个图像,下面有一个段落。当我重新调整页面大小时,我需要将每个图像堆叠在其各自的段落之上。我在我的前端测试网站上进行了这项工作,但是当我来到我的wordpress网站上进行测试时,它们会连续堆叠在一起。

这是一段代码片段 -

body {
  margin: 0 auto 0 auto;
}

.container {
  margin: auto;
  max-width: 100%;
  padding-left: 10px;
  padding-right: 10px;
}

section#team {
  height: 800px;
  max-width: 100%;
}

section#team div.row {
  height: 350px;
}

#team .four {
  position: relative;
  width: 320px;
  padding: 30px;
}

#team h4 {
  text-align: center;
  margin-top: 30px;
}

#team img {
  display: inline-block;
  border-radius: 50%;
  position: absolute;
  bottom: 50%;
  left: 40%;
  transform: translate(-50%, -50%);
}

#team p {
  text-align: center;
  font-size: 10px;
  margin-top: 100px;
}

@media screen and (max-width: 1000px) {
  div.container {
    float: none;
    margin: 0;
    width: calc(100% - 40px);
    box-sizing: border-box;
  }
  div.column {
    float: none;
  }
}

@media screen and (max-width: 480px) {
  body {
    max-width: 500px;
    border: 1px dashed #ccc;
    min-height: 400px;
  }
  
  section#team {
    float: none;
    height: auto;
  }
  
  #team .four {
    width: auto;
    height: auto;
    position: relative;
    transform: translate(-30%, -5%);
  }
}
<body>
  <section id="team">
    <div class="container">
      <div class="twelve columns">
        <h4>MEET THE TEAM</h4>
        <div class="row">
          <div class="four columns">
            <img src="https://static.pexels.com/photos/99551/hot-air-balloon-valley-sky-99551.jpeg" alt="Meet Tim" style="width:100px;height:100px;">
            <p>Praesent sodales, leo at pellentesque pellentesque, nunc erat dapibus nunc, ut congue libero lorem in orci. Suspendisse potenti. Quisque facilisis mauris in vestibulum tempor.</br>Praesent sodales, leo at pellentesque pellentesque, nunc erat
              dapibus nunc, ut congue libero lorem in orci. Suspendisse potenti. Quisque facilisis mauris in vestibulum tempor.
            </p>
          </div>
          <div class="four columns">
            <img src="https://static.pexels.com/photos/99551/hot-air-balloon-valley-sky-99551.jpeg" alt="Meet Tim" style="width:100px;height:100px;">
            <p>Praesent sodales, leo at pellentesque pellentesque, nunc erat dapibus nunc, ut congue libero lorem in orci. Suspendisse potenti. Quisque facilisis mauris in vestibulum tempor.</br>Praesent sodales, leo at pellentesque pellentesque, nunc erat
              dapibus nunc, ut congue libero lorem in orci. Suspendisse potenti. Quisque facilisis mauris in vestibulum tempor.
            </p>
          </div>
          <div class="four columns">
            <img src="https://static.pexels.com/photos/99551/hot-air-balloon-valley-sky-99551.jpeg" alt="Meet Tim" style="width:100px;height:100px;">
            <p>Praesent sodales, leo at pellentesque pellentesque, nunc erat dapibus nunc, ut congue libero lorem in orci. Suspendisse potenti. Quisque facilisis mauris in vestibulum tempor.</br>Praesent sodales, leo at pellentesque pellentesque, nunc erat
              dapibus nunc, ut congue libero lorem in orci. Suspendisse potenti. Quisque facilisis mauris in vestibulum tempor.</p>
          </div>
        </div>

        <div class="row">
          <div class="four columns">
            <img src="https://static.pexels.com/photos/99551/hot-air-balloon-valley-sky-99551.jpeg" alt="Meet Tim" style="width:100px;height:100px;">
            <p>Praesent sodales, leo at pellentesque pellentesque, nunc erat dapibus nunc, ut congue libero lorem in orci. Suspendisse potenti. Quisque facilisis mauris in vestibulum tempor.</br>Praesent sodales, leo at pellentesque pellentesque, nunc erat
              dapibus nunc, ut congue libero lorem in orci. Suspendisse potenti. Quisque facilisis mauris in vestibulum tempor.</p>
          </div>
          <div class="four columns">
            <img src="https://static.pexels.com/photos/99551/hot-air-balloon-valley-sky-99551.jpeg" alt="Meet Tim" style="width:100px;height:100px;">
            <p>Praesent sodales, leo at pellentesque pellentesque, nunc erat dapibus nunc, ut congue libero lorem in orci. Suspendisse potenti. Quisque facilisis mauris in vestibulum tempor.</br>Praesent sodales, leo at pellentesque pellentesque, nunc erat
              dapibus nunc, ut congue libero lorem in orci. Suspendisse potenti. Quisque facilisis mauris in vestibulum tempor.</p>
          </div>
          <div class="four columns">
            <img src="https://static.pexels.com/photos/99551/hot-air-balloon-valley-sky-99551.jpeg" alt="Meet Tim" style="width:100px;height:100px;">
            <p>Praesent sodales, leo at pellentesque pellentesque, nunc erat dapibus nunc, ut congue libero lorem in orci. Suspendisse potenti. Quisque facilisis mauris in vestibulum tempor.</br>Praesent sodales, leo at pellentesque pellentesque, nunc erat
              dapibus nunc, ut congue libero lorem in orci. Suspendisse potenti. Quisque facilisis mauris in vestibulum tempor.</p>
          </div>
        </div>
      </div>
    </div>
  </section>
</body>

我不知道我的wordpress网站是否需要一套不同的规则 - 这是该页面的php代码 -

<?php /* Template Name: Meet the team */ ?>
<?php get_header(); ?>

<?php get_template_part('topimage-about'); ?>
    <section id="team">
        <div class="container">
            <div class="twelve columns">
                             <h4>MEET THE TEAM</h4>
                <div class="row">
                        <div class="four columns">
                                <?php if( get_field('team_img_1') ): ?>

                                <img src="<?php the_field('team_img_1'); ?>" style="width:100px;height:100px;" />

                                <?php endif; ?>
                                <p><?php the_field('team_bio_1'); ?>
                                </p> 
                        </div>        
                        <div class="four columns">
                               <?php if( get_field('team_img_2') ): ?>

                                <img src="<?php the_field('team_img_2'); ?>" style="width:100px;height:100px;" />

                                <?php endif; ?>
                                <p><?php the_field('team_bio_2'); ?>
                                </p> 
                        </div>
                        <div class="four columns">    
                                <?php if( get_field('team_img_3') ): ?>

                                <img src="<?php the_field('team_img_3'); ?>" style="width:100px;height:100px;" />

                                <?php endif; ?>
                                <p><?php the_field('team_bio_3'); ?>
                                </p>
                        </div>    
                </div>

                <div class="row">
                        <div class="four columns">    
                                <?php if( get_field('team_img_4') ): ?>

                                <img src="<?php the_field('team_img_4'); ?>" style="width:100px;height:100px;" />

                                <?php endif; ?>
                                <p><?php the_field('team_bio_4'); ?>
                                </p>
                        </div>
                        <div class="four columns">    
                                <?php if( get_field('team_img_5') ): ?>

                                <img src="<?php the_field('team_img_5'); ?>" style="width:100px;height:100px;" />

                                <?php endif; ?>
                                <p><?php the_field('team_bio_5'); ?>
                                </p>
                        </div>
                        <div class="four columns">    
                                <?php if( get_field('team_img_6') ): ?>

                                <img src="<?php the_field('team_img_6'); ?>" style="width:100px;height:100px;" />

                                <?php endif; ?>
                                <p><?php the_field('team_bio_6'); ?>
                                </p>
                        </div>
                </div>
            </div>
        </div>                
    </section>

       <?php get_template_part('form'); ?>





<?php get_sidebar(); ?>

<?php get_footer(); ?>

更新 - 小提琴中提供的代码修复了我的媒体查询,但我的主要风格现在无法正常工作。这就是现在看起来完全伸展的方式 -

meet the team - desktop

1 个答案:

答案 0 :(得分:1)

这是为了帮助您找到正确的路径 - 它不完整,但它会给您一个想法。检查小提琴,玩耍:)

我必须发布一些代码,用小提琴回答。但你的一个问题是你的正常风格有一个固定的高度

@media screen and (max-width: 480px) {
    section#team div.row {
          height:auto;
    }
} 

Fiddle

很高兴它适合你。