如何将控件浮动在图像顶部(使用图像背景)

发布于 2024-08-05 09:49:41 字数 499 浏览 2 评论 0原文

我的网站页面的整个顶部都有一个徽标图像。徽标本身仅占左侧约三分之一。该条的右侧三分之二是普通的深蓝色。我有几个链接和用户名显示在右侧,并且希望将它们浮动在图像上。

最初,我的图像占据了栏 (div) 左侧的三分之二,还有一个单独的 div,链接位于右侧。问题是该方法在两个 div 之间留下了明显的边界线,即使它们具有相同的颜色。

透明度会有帮助吗?我该如何设置?

    _________________________________________________________________
    |  LOGO HERE                              User: David Troy      |
    |  LOGO HERE                          Home | FAQ | Contact Us   |
    |_______________________________________________________________| 

I have a logo image across the entire top of my website page. The logo itself only takes up about one third of the left hand side. The right two thirds of this bar is plain and dark blue in color. I have several links and the user name displayed on the right side and would like to float those over the image.

Originally, I had the image taking up the left two thirds of the bar (div) and a separate div with my links on the right. The problem is that that method leaves a noticeable boundary line between the two divs even though they are the same color.

Is transparency going to help? How do I set this up?

    _________________________________________________________________
    |  LOGO HERE                              User: David Troy      |
    |  LOGO HERE                          Home | FAQ | Contact Us   |
    |_______________________________________________________________| 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

落日海湾 2024-08-12 09:49:41

关于“细线空间”:如果您使用 Internet Explorer,则必须省略 div 之间的空格,如下所示:

<div class="left">Logo</div><div class="right">Links</div>

我相信这是由于 Quirks 模式造成的;它在 XHTML 严格模式下按预期显示。

然后,CSS 看起来像这样:

div.left {
  float : left;
}
div.left, div.right {
  margin : 0px;
  padding : 0px;
}

Concerning the "hairline space": if you are using Internet Explorer, you will have to omit spaces between the divs as follows:

<div class="left">Logo</div><div class="right">Links</div>

This is due to Quirks mode, I believe; it displays as expected in XHTML Strict mode.

Then, the CSS looks like this:

div.left {
  float : left;
}
div.left, div.right {
  margin : 0px;
  padding : 0px;
}
零度℉ 2024-08-12 09:49:41

尝试:

div.left, div.right {
  margin : 0px;
  padding : 0px;
}

假设您的左侧 div 有一个 class="left" ,右侧 div 有一个 class="right"

这将消除 div 之间的间距。

try :

div.left, div.right {
  margin : 0px;
  padding : 0px;
}

Assuming your left div has a class="left" and the right one has a class="right"

That will remove the spacing between the divs.

陪你搞怪i 2024-08-12 09:49:41

我对你想要实现的目标有点困惑。

如果您使用浮动,请确保为每个 div 指定宽度。

如果您只想将文本显示在图像上方,那么两个简单的 div 块就可以了。

<div>
Your links here
</div>
<div>
<img src="yourimg.gif" />
</div>

如果你想让它们并排,这应该可行:

<div style="float: left; width: 400px">
<img src="yourimg.gif" />
</div>
<div style="float: left; width: 400px">
Link 1
Username
</div>

I'm somewhat confused as to what you're trying to accomplish.

If you're using float, then make sure that you're specifying a width to each div.

If you just want the text to be on top of the image, two simple div blocks should work.

<div>
Your links here
</div>
<div>
<img src="yourimg.gif" />
</div>

If you want them to be side by side, this should work:

<div style="float: left; width: 400px">
<img src="yourimg.gif" />
</div>
<div style="float: left; width: 400px">
Link 1
Username
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文