将元素定位到块元素的右侧
有没有办法使用 CSS 将元素(块或内联)定位到块元素的右侧,而不更改块元素或包含元素的 CSS?
<div>Block</div>
<span class="someCSS">Inline</span>
结果:
块内联
Is there a way using CSS to position an element (block or inline) to the right of a block element without changing the CSS of the block element or of the containing element?
<div>Block</div>
<span class="someCSS">Inline</span>
Result:
BlockInline
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有更多信息,我唯一可以建议的是:
Without any more information, the only thing I can suggest is this:
我更倾向于建议您这样做:
预览: http://jsfiddle.net/Wexcode/9DCDN/< /a>
I would be more inclined to suggest that you do:
Preview: http://jsfiddle.net/Wexcode/9DCDN/
老实说,我花了一段时间才明白你想要什么,但我想我现在明白了。当您说内联元素是动态的时,您可能也使用动态语言,因此您可以只使用一些条件语句向内联对象添加一些 css 样式。
根据您的项目,另一种选择可能只是将跨度包含到块元素中。还有一种方法是将整个内容包装成另外两个块元素,这样就可以避免对其他后续元素产生
floating
效果。抱歉,内联CSS。如果您可以的话,如果将内联设置为
display:block
,您会得到相同的效果。或者避免对以下元素产生floating
效果的另一种选择:在所有内容之后使用类似的内容。
但大多数人不知道的是,CSS 已经有了自己的“条件语句”,但在 CSS 4 之前,无法直接选择祖先。但据我所知,没有其他方法可以以任何其他方式实现预期结果。
Well honestly it took me a while till I understood what you wanted, but I think I do now. When you say the inline element is dynamic, you probably use a dynamic language as well, so you could just use some conditional statements to add some css-styling to the inline object.
Another option, depending on your project, might be just to include the span into the block element. And one more would be to wrap the whole thing into two more block elements, so you avoid having a
floating
effect to other following elements.Sorry for the inline-css. You got the same effect if you set the inline to
display:block
if that's possible for you. Or another option to avoid having afloating
effect to following elements: Use something like<div style="clear:both"></div>
after everything.What most people don't know though is that CSS has it's own "conditional statements" already, but up to CSS 4 it won't be possible to select an ancestor directly. But there's no other way (as far as I know) to achieve the wished outcome any other way.