css右对齐内跨元素

时间:2014-01-06 02:53:10

标签: css html right-align

我想在span元素的右侧对齐图像。

我在td元素中运行良好,但现在我已经将它移动到了一个范围内。非常感谢任何建议。

<div style="width:400px;">
    <span style="display:inline-block;width:50%;" onclick="location.href='http://www.google.com'">Go to Google</span><span style="display:inline-block;width:50%;float:right;weight:bold;" onclick="location.href='http://www.yahoo.com';><img src="test.gif" width=40 height=40 border=0>Go to Yahoo</span>
</div>

http://jsfiddle.net/sVdE3/

1 个答案:

答案 0 :(得分:5)

这个怎么样?

<div>
    <span onclick="location.href='http://www.google.com';">Go to Google
        <img src="https://www.google.com/images/srpr/logo11w.png" width="40" height="40" border="0" />
    </span>
    <span onclick="location.href='http://www.yahoo.com';">Go to Yahoo
        <img src="https://www.google.com/images/srpr/logo11w.png" width="40" height="40" border="0" />
    </span>
</div>

CSS的以下内容:

div {
    width: 400px;
}
span {
    display: inline-block;
    width: 50%;
    float: left;
}
img {
    float: right;
}

http://jsfiddle.net/grim/sVdE3/2/

请注意,您的标记中存在一些错误,例如您未关闭的引号(“)。