CSS 悬停在 WordPress 中的缩略图上
我正在尝试在 WordPress 中创建缩略图网格,我已经成功做到了。然后,当用户将鼠标悬停在图像上时,我希望它变成半透明颜色并在下面显示帖子标题。我想我已经开始对代码进行一些处理,但目前悬停出现在图像下方而不是缩略图上方。我想知道是否有人可以帮助我解决这个问题?我认为CSS是问题所在。我尝试了position:absolute,但它只是粘在网格顶部的一个位置。
<div id="gridContainer">
<?php
$c = 1; //init counter
$bpr = 3; //boxes per row
if(have_posts()) :
while(have_posts()) :
the_post();
?>
<div class="post" id="post-<?php the_ID(); ?>">
<div class="postImage">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('grid-post-image'); ?></a>
</div>
<div class="hover">
<h1 class="title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
</div>
</div>
<?php
if($c == $bpr) :
?>
<div class="clr"></div>
<?php
$c = 0;
endif;
?>
<?php
$c++;
endwhile;
endif;
?>
<div class="clr"></div>
</div>
这是CSS,我认为它需要改变。
.post {
float: left;
width: 275px;
}
.clr {
clear:both;
}
.hover {
width: 275px;
height: 185px;
top: 0;
z-index: 1;
background: #fff;
opacity:0;
}
.hover:hover{
opacity:0.9;
}
I am trying to create a grid of thumbnails in wordpress, which I've managed to do. Then when the user hovers over an image, I want it to go a semi transparent colour and show the post title underneath. I think I've begun to make some way with the code, but at present the hover over appears underneath the image instead of ontop of the thumbnail. I was wondering if somebody could help me with this? I think it is the CSS that is the problem. I tried position: absolute but that just sticks in one place to the top of the grid.
<div id="gridContainer">
<?php
$c = 1; //init counter
$bpr = 3; //boxes per row
if(have_posts()) :
while(have_posts()) :
the_post();
?>
<div class="post" id="post-<?php the_ID(); ?>">
<div class="postImage">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('grid-post-image'); ?></a>
</div>
<div class="hover">
<h1 class="title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
</div>
</div>
<?php
if($c == $bpr) :
?>
<div class="clr"></div>
<?php
$c = 0;
endif;
?>
<?php
$c++;
endwhile;
endif;
?>
<div class="clr"></div>
</div>
And here is the CSS, which is what I think needs altering.
.post {
float: left;
width: 275px;
}
.clr {
clear:both;
}
.hover {
width: 275px;
height: 185px;
top: 0;
z-index: 1;
background: #fff;
opacity:0;
}
.hover:hover{
opacity:0.9;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将两个元素(image 和 h1)放在同一个 div 中
Put both elements (image and h1) in the same div