Html 如何将文本和图像放在同一行中?

Html 如何将文本和图像放在同一行中?,html,css,Html,Css,如何将文本和图像放在同一行中,例如居中到图像? 我尝试了一些方法,比如垂直对齐:中间对齐;显示:内联;但是不工作。。。我的错在哪里 现在: 我的css代码: <style> .entryDetailX { float: right; background: #2B587A; -moz-border-radius-topleft: 8px; -webkit-border-top-left-radius: 8px;

如何将文本和图像放在同一行中,例如居中到图像? 我尝试了一些方法,比如垂直对齐:中间对齐;显示:内联;但是不工作。。。我的错在哪里

现在:

我的css代码:

<style>
    .entryDetailX {
        float: right;
        background: #2B587A;
        -moz-border-radius-topleft: 8px;
        -webkit-border-top-left-radius: 8px;
        -moz-border-radius-bottomright: 8px;
        -webkit-border-bottom-right-radius: 8px;
        font-weight: bold;
        color: #FFF;
        padding: 6px;
    }
    .date {
        float: right;
        font-size: 9px;
        padding-top: 1px;
        background: url(/content/themes/mavi/img/custom/icon_time16x16.png) top left no-repeat;
        padding-left: 20px;
        margin-right: 10px;
    }
    .nick {
        float: right;
        margin-right: 20px;
        color: #cc9900;
        background: url(/content/themes/mavi/img/custom/icon_user16x16.png) top left no-repeat;
        padding-left: 20px;
    }
</style>

.entryDetailX{
浮动:对;
背景#2B587A;
-左上角moz边界半径:8px;
-webkit边框左上半径:8px;
-moz边框半径右下角:8px;
-webkit边框右下半径:8px;
字体大小:粗体;
颜色:#FFF;
填充:6px;
}
.日期{
浮动:对;
字体大小:9px;
垫面:1px;
背景:url(/content/themes/mavi/img/custom/icon_time16x16.png)左上角不重复;
左侧填充:20px;
右边距:10px;
}
尼克先生{
浮动:对;
右边距:20px;
颜色:#cc9900;
背景:url(/content/themes/mavi/img/custom/icon_user16x16.png)左上角不重复;
左侧填充:20px;
}
HTML:


18.01.2011 00:50:55
幻觉

谢谢

您只需添加

 background-position:left center;

您只需添加

 background-position:left center;

图像是背景图像,您需要在
background
css属性中设置它们的位置。因此,您可以设置
center
,而不是
top

.date {
    background: url(/content/themes/mavi/img/custom/icon_time16x16.png) left center no-repeat;
}
.nick {
    background: url(/content/themes/mavi/img/custom/icon_user16x16.png) left center no-repeat;
}
如果上述方法不起作用,您可以设置图像的像素值。所以,如果你想把图像降低8像素,你可以设置

.date {
    background: url(/content/themes/mavi/img/custom/icon_time16x16.png) left 8px no-repeat;
}
.nick {
    background: url(/content/themes/mavi/img/custom/icon_user16x16.png) left 8px no-repeat;
}

这些图像是背景图像,您需要在
background
css属性中设置它们的位置。因此,您可以设置
center
,而不是
top

.date {
    background: url(/content/themes/mavi/img/custom/icon_time16x16.png) left center no-repeat;
}
.nick {
    background: url(/content/themes/mavi/img/custom/icon_user16x16.png) left center no-repeat;
}
如果上述方法不起作用,您可以设置图像的像素值。所以,如果你想把图像降低8像素,你可以设置

.date {
    background: url(/content/themes/mavi/img/custom/icon_time16x16.png) left 8px no-repeat;
}
.nick {
    background: url(/content/themes/mavi/img/custom/icon_user16x16.png) left 8px no-repeat;
}

有一个名为
背景位置
的属性来确定背景位置。它有两个值,一个表示水平位置,一个表示垂直位置。这两个值都可能需要
center

编写以下代码行时,使用速记
背景设置
背景位置
。您明确要求在左上角对齐背景

background: <background-image> <background-position> <background-repeat>;
background: url() top left no-repeat;
您可以在上玩此属性

干杯,
托马斯。

有一个属性,名为
背景位置
,用于确定背景位置。它有两个值,一个表示水平位置,一个表示垂直位置。这两个值都可能需要
center

编写以下代码行时,使用速记
背景设置
背景位置
。您明确要求在左上角对齐背景

background: <background-image> <background-position> <background-repeat>;
background: url() top left no-repeat;
您可以在上玩此属性

干杯, 托马斯