php - 如何在灯箱画廊中将图像下方的文本居中?

标签 php html css lightbox

我试图将 this site 上每张图片下方的文本居中但我遇到了问题。

每次我尝试将图像放入 div 时,它都会破坏灯箱画廊。

这是我的相册生成代码:

<?php
class struct
{
    function imageDisplayGallery($img_folder_path)
    {
        //lists all files with _thumbs in folder. stores letter number as key in array called $numbers, and thumbnail as value
        $numbers=array();
        foreach(glob("$img_folder_path*/*_thumb.jpg") as $thumb)
        {
            $thumb=str_replace("%2F","/",urlencode($thumb));
            $thumb=str_replace("+"," ",$thumb);
            $int=explode("/",$thumb)[3].explode("/",$thumb)[4];
            $int=str_replace("Letter %23","",$int);
            $int=str_replace("_thumb.jpg","",$int);
            $numbers[$int]=$thumb;
        }

        //generate code to display image and thumb
            foreach($numbers as $key => $thumb)
        {
            $full=str_replace("_thumb","",$thumb);
            echo '<a href="',$full,'" data-lightbox="roadtrip"><img src="',$thumb,'" /></a>';
            echo "$key";
        }
        echo '<div class="clear"></div>';
    }
}
?>

最佳答案

为每个元素尝试此设置。它使用 CSS flex 布局将图像和文本排列在一列中。文本包裹在 span 元素中并放置在 anchor 元素内。

a {
  display: inline-flex;
  flex-direction: column;
  color: black;
  text-decoration: none;
  font-size: 16px;
  font-weight: bold;
  margin: 10px;
}
<a href="#" data-lightbox="roadtrip"><img src="http://www.germanwarletters.com/img/letter_images/Chapter11IntotheAbyss/Letter%20%23%20445/A_thumb.jpg" /><span>445A</span></a>
<a href="#" data-lightbox="roadtrip"><img src="http://www.germanwarletters.com/img/letter_images/Chapter11IntotheAbyss/Letter%20%23%20445/A_thumb.jpg" /><span>445A</span></a>
<a href="#" data-lightbox="roadtrip"><img src="http://www.germanwarletters.com/img/letter_images/Chapter11IntotheAbyss/Letter%20%23%20445/A_thumb.jpg" /><span>445A</span></a>
<a href="#" data-lightbox="roadtrip"><img src="http://www.germanwarletters.com/img/letter_images/Chapter11IntotheAbyss/Letter%20%23%20445/A_thumb.jpg" /><span>445A</span></a>

jsFiddle demo

关于php - 如何在灯箱画廊中将图像下方的文本居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43858749/

相关文章:

php - 为什么选择 TCPDF 而不是 mpdf

html - 如何使 span 的内容换行到嵌入的 <a> 中的下一行

javascript - 如何根据数据属性获取 HTML 选择更改事件来触发 DIV 的显示/隐藏?

javascript - jquery animate() 函数没有在表单上触发

html - 如何使用 bootstrap 3.0 右对齐元素?

javascript - 用于在 PHP 上剥离 javascript 的正则表达式

php - 对 Mysql 查询进行微小编辑,以编辑数据库中的一些链接

php - 尝试用 Javascript 填充字段,由 PHP 回显

html - 如何在悬停时使用 CSS 更改选择选项的颜色?

html - 悬停时使类元素变大