[英]How can I align this Wordpress image caption with the top of the image?
I'm writing a Wordpress theme. 我正在写一个WordPress主题。 I'd like the captions I add to my images in the theme to be pulled to the left of an image and aligned with the top of the image, like the picture below:
我希望将添加到主题中的图像的标题拉到图像的左侧,并与图像的顶部对齐,如下图所示:
The HTML output by Wordpress looks like this (simplified for clarity): Wordpress的HTML输出如下所示(为清楚起见已简化):
<div id="attachment_1726" style="width: 1034px" class="wp-caption aligncenter">
<a href="some_url"><img class="wp-image-1726 size-large" src="the_src" width="1024" height="640"></a>
<p class="wp-caption-text">Satoshi town, the trading capital of BitQuest</p>
</div>
I can't figure out how to pull the wp-caption-text
paragraph out. 我不知道如何拉出
wp-caption-text
段落。 I;ve tried the following: 我尝试了以下方法:
.wp-caption-text {
position: relative;
left: -170px;
top: 0;
width: 150px;
}
But this doesn't work. 但这是行不通的。 Here's the result:
结果如下:
Can anyone point me in the correct direction? 谁能指出我正确的方向?
You have to float both elements. 您必须同时浮动这两个元素。 Also may apply
vertical-align: top;
也可以应用
vertical-align: top;
.wrapper { width: 450px; } p, img { float: left; } p { margin: 0; width: 100px; }
<div class="wrapper"> <p>Satoshi town, the trading capital of BitQuest</p> <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" /> </div>
Try to display it as inline-block: 尝试将其显示为嵌入式块:
.wp-caption-text {
position: absolute;
display: inline-block;
left: -170px;
top: 0;
width: 150px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.