这将有点冗长。我倾向于把这个问题称为off-topic 首先,因为您已经计算出了特定于WP的部分<但是,由于我有一个不错的方格,而且我的足球俱乐部踢得很好,给你:
CSS
div.grid-row {
width: 100%;
max-width: 1140px; // adjust to your liking
margin: 0 auto;
overflow: hidden;
}
div.column,
div.splitcol {
margin-right: 3.8%;
float: left;
min-height: 1px;
}
div.column {
width: 30.75%;
}
.ie div.column { // width for IE (I use modernizr)
width: 30.6%;
}
div.splitcol {
width: 43.8%;
margin-right: 12.35%;
}
div.last {
margin-right: 0;
}
/* collapse columns at some threshold */
@media handheld, only screen and (max-width: 799px) { // adjust to your liking
div.column {
width: auto;
float: none;
margin-right: 0;
overflow: hidden;
}
}
/* further collapse splitcols at some threshold */
@media handheld, only screen and (max-width: 479px) { // adjust to your liking
div.splitcol {
width: auto;
float: none;
margin-right: 0;
overflow: hidden;
}
}
您的代码已调整/HTML
$categories = get_categories( \'child_of=2\' );
foreach ( $categories as $category ) {
echo \'<div class="grid-row"><h2>\'.$category->name.\'</h2></div>\';
$cat_posts = get_posts( \'cat=\'.$category->term_id );
$end = count( $cat_posts ) - 1;
$i = 0;
foreach ( $cat_posts as $post ) {
setup_postdata( $post );
$face = get_field( \'face\' );
$name = get_field( \'fullname\' );
if ( $i % 6 === 0 ) {
echo \'<div class="grid-row">\';
}
if ( $i % 2 === 0 ) {
echo \'<div class="column\';
if ( $i % 6 === 4 ) {
echo \' last\';
}
echo \'">\';
}
echo \'<div class="splitcol\';
if ( $i % 2 === 1 ) {
echo \' last\';
}
echo \'">\';
echo wp_get_attachment_image($face)
. \'<div class="name">\'.$name.\'</div>\';
echo \'</div>\';
if ( $i % 2 === 1 ) {
echo \'</div>\';
}
if ( $i % 6 === 5 ) {
echo \'</div>\';
}
if ( $i === $end && $i % 6 !== 5 ) {
echo \'</div>\';
if ( $i % 2 !== 1 ) {
echo \'</div>\';
}
}
$i++;
}
}
正如所预见的那样,备选方案非常冗长。但是,CSS会根据您对6列的要求进行调整。如果你想潜入其中,
here 是我目前在整个生产中使用的网格的CSS。
此外,您可以考虑: