php - 如何正确放置我的字幕?

标签 php jquery css image html

我有一个图片库,目前只显示图片。我希望画廊看起来像这样(我的简单测试画廊): http://jsfiddle.net/karin_A/Nmxx4/1/ 即图片下方中心的标题。

到目前为止,我能做到的最好的是将标题放在图片下方但在图片右侧的图库:

image example

html 图像容器:

 <div data-role="content" id="pagecontent" class="gallerycontent">
    <?= $output ?>
        </div> 

php图像输出:

 $html .= '<a href="#imgshow" data-transition="pop" data-index="'.$i.'" data-rel="dialog" id="thumb">
        <img src="https://[url]/'.rawurlencode($this->_decode_path($xml->COM->MOVIE[$i]->attributes()->dbIcoFilename)).'" alt="'.$xml->COM->MOVIE[$i]->attributes()->nameS.'" class="imgAlt">
        </a>';

jQuery 添加环绕边框和标题:

$.each($("img"), function() {
        $(this).wrap('<div class="wrapper"/>');
    });
    $.each($("img.imgAlt"), function() {
        $(this).after($(this).attr("alt"));
    });

CSS:

#pagecontent {
text-align:center;
font-size:12px;
color:#000;
text-decoration:none;
}

.wrapper{
    float:left;
    padding:0.2em;
    border: 1px solid #C0C0C0;
    margin:10px;
}

.thumb{
    padding: 0.1em;
    margin-right: 10px;
    margin-bottom: 15px;
}

.gallerycontent a img { 
    margin: 0.2em;
}

.caption{
    float:left;
    width:100%;
}

当我限制宽度 (width:100px;) 如果环绕边框我得到这个结果: newdump 如您所见,如果图像名称真的很短,它就可以工作,但有时却不是。

另一个尝试:

$.each($("img.imgAlt"), function() {
        var title = this.alt;
        $(this).after('<div class="caption">'+ title +'</div>');
    });

将标题置于图片下方的中心位置,同时使 div 填充整个页面宽度,而不仅仅是标题的宽度。

最佳答案

尝试将 clear:both 添加到您的 .caption CSS 类

关于php - 如何正确放置我的字幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9158163/

相关文章:

jquery - Grails View 渲染。渲染GSP还是使用主干+模板?

jQuery 计算某个类的 div 数量?

html - Tizen WebView (EFL WebKit) 中的 CSS 不支持字体系列

html - 我的行占据了太多的高度

html - 自动返回链接的预悬停和预聚焦状态

php - 当对两列使用 mysqli_multi_query 时,排序无法正常工作

php - 使用 php 日期函数根据全年特定月份范围回显字符串

javascript - 使用Ajax获取php函数调用的数组

php - csrf_token() 在 l5-swagger 中为空,除 GET 请求外无法执行任何请求

javascript - jQuery 表单,存在检查