向右浮动 div,不影响设计
我想将 div 浮动到页面顶部的右侧。 它包含一个 50px 的方形图像,但目前它影响页面上顶部 50px 的布局。
目前是:
<div style="float: right;">
...
</div>
我尝试了 z-index,因为我认为这就是答案,但我无法让它继续下去。
我知道我错过了一些简单的事情,但我似乎无法解决它。
I want to float a div to the right at the top of my page. It contains a 50px square image, but currently it impacts on the layout of the top 50px on the page.
Currently its:
<div style="float: right;">
...
</div>
I tried z-index as I thought that would be the answer, but I couldn't get it going.
I know it's something simple I'm missing, but I just can't seem to nail it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你所说的影响是什么意思? 内容将围绕浮动体流动。 他们就是这样工作的。
如果您希望它出现在您的设计上方,请尝试设置:
What do you mean by impacts? Content will flow around a float. That's how they work.
If you want it to appear above your design, try setting:
如果您不希望图像根本影响布局(并浮动在其他内容之上),您可以将以下 CSS 应用于图像:
如果您希望它浮动在特定父部分的右侧,您可以将
position:relative
添加到该部分。If you don't want the image to affect the layout at all (and float on top of other content) you can apply the following CSS to the image:
If you want it to float at the right of a particular parent section, you can add
position: relative
to that section.尝试将其
位置
设置为绝对。 这将其从文档流程中删除。Try setting its
position
to absolute. That takes it out of the flow of the document.