【发布时间】:2010-10-27 12:22:46
【问题描述】:
我非常头疼试图让包含在 div 中的图像看起来漂浮在其包含元素之外。
虽然我很确定这是不可能的,但我想确保在告诉设计师和客户他们不会让它看起来与设计中概述的完全一样之前,我已经用尽了所有途径规格。
所需(指定)设计looks like this。您可以看到在标题的圆角背景上方有一个地球图标。该位置也位于页面最左侧和最右侧的其他内容块的上边距之上(您也可以在部分屏幕截图中看到)。
我目前能够达到的结果looks like this。如您所见,如果您尝试将图像放置在其定义的边距之外,它将“滑入”任何重叠的位置。
我尝试过绝对定位、浮动和任何其他想到的东西。我受限于<h1> 元素的边距,您可以在第一个屏幕截图中看到它的最后几个字母。
可根据要求提供代码/CSS。谁告诉我这实际上可以实现以及如何实现。
代码sn-ps: HTML
.icon
{
background: transparent none no-repeat scroll 0 -0.2em;
padding: 1.8em 0 1em 4em;
}
.icon-globe
{
background-image: url('images/icons/globe.gif');
}
/* **************** GRIDS ***************** */
.line, .last-column
{
overflow: hidden;
_overflow:visible;
_zoom:1;
}
.column
{
float:left;
_zoom:1;
}
.col-fullwidth {float:none;}
.col-halfwidth {width:50%;}
.col-onethird {width:33%;}
.col-last
{
float:none;
_position:relative;
_left:-3px;
_margin-right: -3px;
overflow: hidden;
width:auto;
}
.padded-sides
{
padding: 0 1em;
}
.section-heading
{
background: transparent url('images/type/section-head.gif') no-repeat top right;
position: relative;
margin-left: 1.4em;
}
.section-heading-cap
{
background: transparent url('images/type/section-head-cap.gif') no-repeat top left;
padding: 0.4em 1em 1.6em;
margin: 0 0 0 -1em;
}
<h1>Contact Us</h1>
<div class="line">
<div class="column col-threequarters">
<div class="line">
<div class="column col-threefifths contact-panel-top">
Unrelated stuff...
</div>
</div>
<div class="column col-last padded-sides">
<div class="section-heading">
<h4 class="section-heading-cap"><img src="/App_Themes/Common/images/icons/globe.gif" alt="International" />International Contacts</h4>
</div>
... and so on.
【问题讨论】:
-
您可能想在此处发布代码。如果直接嵌入到您的帖子中太多,也许可以使用 pastebin 或其他东西?
-
在上面提供的 sn-p 中,我将我们的图标封装在 span 标签中,但我真的(真的)不再关心我如何达到预期的结果。
-
对不起,菲尔,我帮不上忙;我找不到任何会使它不起作用的东西。我唯一的建议是尝试将零件拿走,直到您发现导致它无法按预期工作的原因。不过,肯定有办法让它发挥作用。再次抱歉。