向右浮动 div,不影响设计

发布于 2024-07-09 09:32:11 字数 241 浏览 4 评论 0原文

我想将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌生 2024-07-16 09:32:11

你所说的影响是什么意思? 内容将围绕浮动体流动。 他们就是这样工作的。

如果您希望它出现在您的设计上方,请尝试设置:

z-index: 10;  
position: absolute;  
right: 0;  
top: 0;

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:

z-index: 10;  
position: absolute;  
right: 0;  
top: 0;
枕梦 2024-07-16 09:32:11

如果您不希望图像根本影响布局(并浮动在其他内容之上),您可以将以下 CSS 应用于图像:

position:absolute;
right:0;
top:0;

如果您希望它浮动在特定父部分的右侧,您可以将 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:

position:absolute;
right:0;
top:0;

If you want it to float at the right of a particular parent section, you can add position: relative to that section.

辞旧 2024-07-16 09:32:11

尝试将其位置设置为绝对。 这将其从文档流程中删除。

Try setting its position to absolute. That takes it out of the flow of the document.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文