图像流出div
我正在尝试实现从 div 中流出的图像。基本上,在我的标题中,我的固定宽度为 960 像素,徽标图像有一些东西从其中脱落,我想将其放置在 960 像素之外。
有没有一种很好的干净方法来实现这一目标?
I'm trying to achieve an image flowing out of a div. Basically, in my heading I have a fixed width of 960px, the logo image has something coming off of it, which I would like to sit outside that 960px.
Is there a nice clean method of achieving this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
执行此操作的简单方法(适用于大多数浏览器)是让主包装器具有
position:relative
,并使 div(您想要向外流动的)具有位置:绝对;左:-25px;顶部:-25px;
。将
position:relative
作为包装器使得position:absolute
在父容器内相对。The simple method of doing it (that works in most browsers), is that you make your main wrapper have
position:relative
, and the make the div (that you want to flow outside) haveposition: absolute; left: -25px; top: -25px;
.Having
position:relative
as the wrapper makes theposition:absolute
relative inside the parent container.将您的徽标放在固定 div 中,并为该 div 指定样式
overflow:hidden
put your logo in fixed div and give that div a style
overflow:hidden
您也可以通过绝对定位来实现这一点。下面是简单的示例:
http://jsfiddle.net/spacebeers/9QJ4w/1/
You could also absolute positioning to achieve this. Quick example below:
http://jsfiddle.net/spacebeers/9QJ4w/1/
您可以使用 CSS 的
position
属性来完成此操作:HTML:
CSS:
http://jsfiddle .net/FpTDc/
You can use the
position
property of CSS to accomplish this:HTML:
CSS:
http://jsfiddle.net/FpTDc/
你的朋友将会溢出:可见。
您的包含 div 将具有 960px 宽度,并且溢出:可见。在内部,您将有一个相对或绝对定位的图像(您需要向“左”偏移以使其居中)
Your friend will be overflow:visible.
Your containing div will have the 960px width with overflow:visible. Inside, you will have a relatively or absolutely positioned image (you will need to offset 'left' to center it)
代码: http://jsfiddle.net/cSQrR/
code: http://jsfiddle.net/cSQrR/
这是由于图像具有不同的尺寸和纵横比。
试试这个:
it's due to the images having different sizes and aspect ratios.
try this: