【发布时间】:2018-12-21 07:19:51
【问题描述】:
我创建了一个页面来显示网格,但 CSS 网格在桌面视图中堆叠显示。我不知道为什么会这样。代码如下:
CSS
我还添加了<div class="row"> 以表明它们是同一行的一部分。我试图将它分成 4 列,然后使用 span 来指示宽度。但没有一个是
#grid-list-page {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 1px;
}
.listUL {
padding: 2px;
margin: 1px;
height: 200px;
overflow-y: scroll;
overflow-x: hidden;
}
.listUL li a {
text-decoration: none;
font-size: 1em;
padding: 0;
}
@media (max-width: 700px) {
#grid-list-page {
grid-template-columns: 1fr;
}
}
<div id="grid-list-page">
<div class="row">
<div class="grid-item">
<h4>List for USA</h4>
<ul id="usalistUL" class="listUL">
<?php
$args = array(
'post_type' => 'post',
'numberposts' => -1,
'meta_query' => array(
array(
'key' => 'list_country',
'value' => 'usa',
),
),
);
$usaposts = get_posts($args);
foreach($usaposts as $usapost) {
$post_id = $usapost->ID; ?>
<li>
<a href="<?php echo get_the_permalink($post_id); ?>"><?php echo get_the_title($post_id); ?></a>
</li>
<?php } ?>
</ul>
</div>
<div class="grid-item">
<h4>List for Canada</h4>
<ul id="canlistUL" class="listUL">
<?php
$args = array(
'post_type' => 'post',
'numberposts' => -1,
'meta_query' => array(
array(
'key' => 'list_country',
'value' => 'canada',
),
),
);
$canposts = get_posts($args);
foreach($canposts as $canpost) {
$post_id = $canpost->ID; ?>
<li>
<a href="<?php echo get_the_permalink($post_id); ?>"><?php echo get_the_title($post_id); ?></a>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>
出于某种原因工作。我在另一个页面上有一个网格,它使用相同的结构可以正常工作,但这个不工作。任何指导都会有所帮助。提前致谢。
【问题讨论】: