简体   繁体   English

在图像之间添加空间

[英]Add space in between images

On my front page I have three posts in a row that are spread across the full width of the page.在我的首页上,我连续发布了三个帖子,它们分布在页面的整个宽度上。 I want to add a padding of 30px to the left.我想在左边添加一个 30px 的填充。 However my problem is then that at the beginning of each row of images there is a padding of 30px.但是我的问题是在每行图像的开头有一个 30px 的填充。 I want it so that technical there is only a padding to the left and right 30px of the middle image, so the outer two images are always touching the end of the screen.我想要它,这样技术上只有中间图像的左右 30 像素的填充,所以外面的两个图像总是接触屏幕的末端。 I tried using :first-child to then take away the padding, however since I have the posts in a loop it did not work, and removed padding from all three images.我尝试使用 :first-child 然后去掉填充,但是因为我在循环中放置了帖子,所以它不起作用,并从所有三个图像中删除了填充。 Does anyone have a solution?有没有人有办法解决吗?

what it looks like...长什么样子…… 在此处输入图片说明

 <article <?php post_class( 'col-md-4' ); ?>> <div class="front-thumbnail-image"><?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?></div></article>

 .medium-front-thumbnail { max-width: 100%; height: auto; position: relative; margin: 0 auto; align-items: flex-end; display: block; float: left; } .front-thumbnail-image { padding-left: 30px !important; } .col-md-4 { padding: 0 0 0 0 !important; margin-bottom: 100px; background-color: red; }

my entire front-page.php我的整个front-page.php

 <?php /* * Template Name: */ get_header(); get_template_part ('inc/carousel'); $the_query = new WP_Query( [ 'posts_per_page' => 14, 'paged' => get_query_var('paged', 1) ] ); if ( $the_query->have_posts() ) { ?> <div id="ajax"> <?php $i = 0; while ( $the_query->have_posts() ) { $the_query->the_post(); if ( $i % 7 === 0 ) { // Large post: on the first iteration and every 7th post after... ?> <article <?php post_class( 'col-md-12' ); ?>> <div class="large-front-container"> <?php the_post_thumbnail('full', array('class' => 'large-front-thumbnail')); ?> </div> <h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p> <div class="front-post-info"> <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> <?php get_template_part ('front-page-shop'); ?> <?php get_template_part( 'share-buttons' ); ?> <div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div> </article><?php } else { // Small posts ?> <article <?php post_class( 'col-md-4' ); ?>> <div class="front-thumbnail-image"><?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?></div> <a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p> <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> <?php get_template_part ('front-page-shop'); ?> <?php get_template_part( 'share-buttons' ); ?> <div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div> </article> <?php } $i++; }?> </div> <?php if(get_query_var('paged') < $the_query->max_num_pages) { load_more_button(); } } elseif (!get_query_var('paged') || get_query_var('paged') == '1') { echo '<p>Sorry, no posts matched your criteria.</p>'; } wp_reset_postdata(); get_footer();

you can use :nth-child(2) to target the middle div.您可以使用:nth-child(2)来定位中间的 div。

 .grid > div:nth-child(2) { padding: 0 30px; } .grid > div { float: left; } .grid { background: red; overflow: auto; display: inline-block; } img { display: block; max-width: 100px; }
 <div class="grid"> <div><img src="https://www.smashingmagazine.com/wp-content/uploads/2015/06/10-dithering-opt.jpg"></div> <div><img src="https://www.smashingmagazine.com/wp-content/uploads/2015/06/10-dithering-opt.jpg"></div> <div><img src="https://www.smashingmagazine.com/wp-content/uploads/2015/06/10-dithering-opt.jpg"></div> </div>

On the code you've provided I can see you uses Flexbox.在您提供的代码中,我可以看到您使用了 Flexbox。 To the container of the images try to add justify-content: space-between .尝试向图像的容器添加justify-content: space-between That should only add space between the images.那应该只在图像之间增加空间。

 .front-thumbnail-image { display: flex; justify-content: space-between; background: red; }
 <article class='col-md-4'> <div class="front-thumbnail-image"> <img src="https://getuikit.com/v2/docs/images/placeholder_600x400.svg" height="120" /> <img src="https://getuikit.com/v2/docs/images/placeholder_600x400.svg" height="120" /> <img src="https://getuikit.com/v2/docs/images/placeholder_600x400.svg" height="120" /> </div> </article>

Try this :尝试这个 :

.grid img:not(:first-child) , .grid img:not(:last-child) {
     padding: 0 10px 0 10px;
}

Full code :完整代码:

 img { width: 100px; height: 100px; } .grid { background-color: red; display: inline-block; } .grid img:not(:first-child) , .grid img:not(:last-child) { padding: 0 10px 0 10px; }
 <div class="grid"> <img src="http://cdn.earthporm.com/wp-content/uploads/2014/10/animal-family-portraits-2__880.jpg"> <img src="http://onehdwallpaper.com/wp-content/uploads/2015/07/Abdorble-Animals-Desktop-Wallpapers-Pictures.jpg"> <img src="https://s-media-cache-ak0.pinimg.com/originals/b2/1e/c9/b21ec91754d33bb5de86c67c45482e12.jpg"> <img src="http://cisnerosnediadistribution.s3.amazonaws.com/media/images/reino_animal_-_trailer_image.png"> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM