保证金首要问题
<img src="/test.png" style="margin-top:20px;margin-left:20px" title="Hello" border="1" height="100" width="110" />
<span style="text-shadow: 1px 1px 17px #347235;margin-left:20px;margin-top:-20px">Test span</span>
发生的情况是,图像已显示,但“测试跨度”消息根据 margin-left:20px 打印在图像的右侧,但 margin-top 没有执行任何操作,因为标签显示在底部的图像。我希望它显示在顶部,就像图像出现一样,但标签显示在底部。
您可以在这里看到它: http://jsfiddle.net/AMWjH/
请帮忙
<img src="/test.png" style="margin-top:20px;margin-left:20px" title="Hello" border="1" height="100" width="110" />
<span style="text-shadow: 1px 1px 17px #347235;margin-left:20px;margin-top:-20px">Test span</span>
What happens is that the image is displayed but the "Test span" message is printed on the right side of the image according to the margin-left:20px but the the margin-top doesn't do anything as the label shows towards the bottom of the image. I want it to show on the top like the image comes up but the label is showing at the bottom.
You can see it right here: http://jsfiddle.net/AMWjH/
Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以更改垂直对齐属性来更改元素的显示方式。我认为对图像应用
vertical-align: top
可以解决您的问题:Preview: http://jsfiddle.net/Wexcode/AMWjH/23/
另外,margin-top 和 margin-bottom 不影响你的 span 元素的原因是因为 span 是一个内联元素。您可以将其更改为 inline-block 或 block 来应用此边距(将其更改为 block 将覆盖垂直对齐)。
You can change the vertical-align property to change how the elements display. I think that applying
vertical-align: top
to the image solves your problem:Preview: http://jsfiddle.net/Wexcode/AMWjH/23/
Also, the reason why the margin-top and margin-bottom aren't affecting your span element is because span is an inline element. You can change it to inline-block or block to apply this margin (changing it to block will override vertical-align).
我不确定您要什么,但听起来您希望标题位于图像的右侧,但与顶部对齐。我理解这个问题吗?试试这个:
HTML:
CSS:
I'm not certain what you're asking for, but it sounds like you want the title to go to the right of the image, but aligned to the top. Am I understanding the question? Try this:
HTML:
CSS:
根据我收集的信息,您希望将文本环绕在图像周围。您只需向
标记添加
align
属性即可:From what I gather, you want to wrap the text around the image. You just need to add an
align
attribute to you<img>
tag:为什么要以这种特殊方式构建代码?在完全了解您的局限性的情况下,我强烈建议您执行以下操作:(当然,取出内联样式并将它们放入样式表中)。
如果这能为您解决问题,请告诉我。没有理由使用边距和边距。负利润。不过,在这种特殊情况下,边距或填充将在图像上起作用。通常,尽可能避免负边距,并且仅在绝对必要时才使用它们。
我希望这有帮助。
Why are you structuring your code this particular way? Without fully knowing your limitations I'd strongly recommend doing something like this: (of course, take the inline styles out and put them in a stylesheet).
Let me know if this solves it for you. There is no reason to use margins & negative margins. In this particular case margin or padding would work on the image, though. As a rule, avoid negative margins if possible and only use them when absolutely necessary.
I hope this helps.