中心将H1标签与图像的左侧和右侧对齐

时间:2012-05-10 14:26:50

标签: html css image

我正在尝试找到一种方法,将包含图像的块中心对齐到H1标记的左侧和右侧。图像需要包装h1标记。 H1代码需要能够以标题大小增长:

<div class=titlewrap">
    <img src="/images/hl.png" class="dl">
        <h1 class="title">Gallery</h1>
    <img src="/images/hr.png" class="dr">    
</div>

4 个答案:

答案 0 :(得分:2)

如果这是UI的一部分(不是内容) - 填充H1的左侧并使用CSS背景图像,然后对包装器执行相同操作(但填充右端)。使用background-position左右对齐图像。

答案 1 :(得分:1)

尝试:

<style>
.titlewrap .dl, .titlewrap .dr{
    vertical-align:middle;
}
.titlewrap .title{
    display:inline-block;
    *display:inline;
}
</style>

答案 2 :(得分:1)

对我有用的是:

HTML标记:

<h1>
    <img src="img1.png" alt="back">
    This is the H1 text
    <img src="img2.png alt="logo">
</h1>

CSS标记:

h1 {
    position: relative;
}

img[alt="back"] {
    position: absolute;
    left: 20px /* Distance from the left side of the 
                  page where you want the image*/
}

img[alt="logo"] {
    position: absolute;
    right: 20px /* Distance from the right side of the
                   page where you want the image*/
}

答案 3 :(得分:0)

尝试:

.titlewrap { float: left; left: 50%; position: relative}
.titlewrap > * {float:left; left: -50%}​
相关问题