css - 如何在div中将图像居中

标签 css wordpress html header center

我试图将 Logo 置于页眉的中央。我在我的 #site-title 类中尝试了 display:blockmargin:auto,但它不起作用。

代码链接是:http://pastebin.com/iNvhTSBL CSS 是:http://pastebin.com/f5mPTjuU

我不确定该怎么做...也许我没有正确执行 CSS?

任何帮助将不胜感激! CSS 来自 wordpress 主题,只是让大家知道。

谢谢!

最佳答案

下次,只发布问题中的相关代码位。这使得人们更有可能费心回答。

如果这是您所指的代码:

<div id="header">
            <div id="site-title">
                    <a href="http://www.panduzee.com/wordpress"><img src="http://i.imgur.com/ysxPP.jpg"></a>
            </div>
            <!-- other bits stripped for brevity -->
            <div class="clear"></div>
    </div>

css 是这样的:

#header {
    border-bottom: 1px solid #dedfe0; 
    padding-bottom: 50px;
}
#site-title { 
    float: left; 
    width: 100%; 
    padding-right: 40px; 
    overflow: hidden; 
    line-height: 27px; 
    font-size: 23px; 
    display:block; 
    margin: auto;
}  
#site-title a {
    color: #333; 
    font-weight: bold; 
    text-decoration: none; 
}

然后需要修改css如下:
1. 从站点标题中删除 float: left。没必要。
2. 请注意,您的 padding-right of 40px 会导致您的 width: 100%
出现问题 3. 添加text-align: center;到网站标题。
4. 将 margin: 0 auto; 添加到您的站点标题 a

以下代码将执行您想要的操作:

#header {
    border-bottom: 1px solid #dedfe0; 
    padding-bottom: 50px;
}
#site-title { 
    width: auto; 
    padding-right: 40px; 
    overflow: hidden; 
    line-height: 27px; 
    font-size: 23px;  
    text-align: center;
}  
#site-title a {
    color: #333; 
    font-weight: bold; 
    text-decoration: none; 
    margin: 0 auto;
}

关于css - 如何在div中将图像居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10326361/

相关文章:

configuration - 覆盖 WordPress 多站点的 WP_SITEURL 和 WP_HOME

html - 两列布局,右列固定,左列最少

javascript - 向元素添加删除 css 类时的 Jquery javascript 最佳实践

php - 使用同位素和帖 subview 的 Wordpress 主题

wordpress - 强制纯文本粘贴

javascript - 如何识别 <select> 中的特定项目并在 jquery 中的每一行添加删除按钮

javascript - 人造视频播放器的 Canvas 与图像

xhtml - css 菜单在加粗时移动

javascript - 我可以将使用 div 和 border-radius 创建的圆分成 6 个相等的部分并获得该点坐标吗?

html - CSS动画旋转