Html css在span元素内右对齐
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20942197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
css right align inside span element
提问by user1904273
I want to align an image in the right side of a span element.
我想在 span 元素的右侧对齐图像。
I had this working fine inside a td element but it is not working now that I've moved it into a a span. Would appreciate any suggestions.
我在 td 元素中运行良好,但现在我已将其移入 aa span 后无法正常工作。将不胜感激任何建议。
<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>
回答by grim
How about this?
这个怎么样?
<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>
And the following for the CSS:
CSS 的以下内容:
div {
width: 400px;
}
span {
display: inline-block;
width: 50%;
float: left;
}
img {
float: right;
}
http://jsfiddle.net/grim/sVdE3/2/
http://jsfiddle.net/grim/sVdE3/2/
Note that you have some errors in your markup such as quotes (") that you didn't close.
请注意,您的标记中有一些错误,例如您没有关闭的引号 (")。