首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSS将图像与文本垂直对齐不起作用(Wordpress)

问CSS将图像与文本垂直对齐不起作用(Wordpress)
EN

Stack Overflow用户
提问于 2012-10-15 06:42:53
回答 1查看 3.5K关注 0票数 0

所以我试图让一个图片文件在我的移动Wordpress主题中的div中间垂直对齐,文本在右手边。不幸的是,在图像上使用“垂直对齐:中间”会导致以下结果:

​

​

这是我的CSS:

代码语言:javascript
复制
        <div <?php post_class('post clearfix'); ?> id="post-<?php the_ID(); ?>">
    <div style="vertical-align:middle"><?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image');  endif; ?></div>
<h2 class="title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'themater' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
             <div class="postmeta-primary-fp">

           <?php echo get_the_date(); ?></div>

               <div class="postmeta-primary-fp"> <?php if(comments_open( get_the_ID() ))  {
                    ?><span class="meta_comments"><?php comments_popup_link( __( '<b>0</b> comments', 'themater' ), __( '<b>1</b> comment', 'themater' ), __( '<b>%</b> comments', 'themater' ) ); ?></span><?php
                } ?>
        </div>

任何帮助都将不胜感激!

EN

回答 1

Stack Overflow用户

发布于 2012-10-15 06:54:48

创建一个父div来保存图像和文本,将图像放在左侧浮动div中,将line-height设置为div的高度,垂直对齐设置为中间,然后为文本添加一个右侧浮动div。类似于:

代码语言:javascript
复制
<div style="width:400px;">
    <div style="float:left;width:50px;height:50px;line-height:50px;vertical-align:middle;">
        <img src="imageurl" />
    </div>

    <div style="width:380px;float:left;height:50px;">
        Text here
    </div>
</div>

如果您希望文本居中对齐图像,请将其行高设置为等于div高度,并将垂直对齐设置为居中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12887273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档