将最后一个 div 浮动到第一个 div 旁边
这是我的 HTML
<div class="one">...</div>
<div class="two">...</div>
<div class="three">...</div>
<div class="four">...</div>
<div class="five">...</div>
如何仅使用 CSS 来获取此图像?我猜是用 float
,但是我怎样才能得到第一个 div 旁边的第五个 div 呢? 更改 HTML 不是(!)一个选项。
This is my HTML
<div class="one">...</div>
<div class="two">...</div>
<div class="three">...</div>
<div class="four">...</div>
<div class="five">...</div>
How can I get this image by using only CSS? I guess with float
, but how can I get the fifth div next to the first one?
Changing the HTML is NOT (!) an option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我的第一条评论是类名不能以数字开头,所以我真的希望您可以为此编辑 HTML。要回答您的问题,忽略这个事实,如果每个元素都有一个类,那么这非常简单。只需这样做:
预览:http://jsfiddle.net/Wexcode/mvwSL/
My first comment would be that class names can't start with a number, so I really hope that you can edit the HTML for that. To answer your question ignoring this fact, if each element has a class, this is pretty simple. Just do this:
Preview: http://jsfiddle.net/Wexcode/mvwSL/
您有几个选项:
浮动和负边距:
. Five{float:right; margin-top:-500px;}
演示
或仅边距
< code>. Five{margin:-500px 0 0 200px;}
演示
或者相对定位:
. Five{position:relative;顶部:-500px; left:200px;}
演示
或绝对定位:
.五个{位置:绝对;顶部:0; right:0;}
(确保容器设置为
position:relative;
)演示
You have a few options:
Float and negative margins:
.five{float:right; margin-top:-500px;}
Demo
Or margins only
.five{margin:-500px 0 0 200px;}
Demo
Or relative positioning:
.five{position:relative; top:-500px; left:200px;}
Demo
Or absolute positioning:
.five{position:absolute; top:0; right:0;}
(Make sure the container is set to
position:relative;
)Demo
首先,具有数值的类无效。如果你不能改变它们,你就完蛋了......有了适当的类,解决方案可能是:
CSS :
jQuery
参见这个 小提琴
First, classes with numeric values are not valid. You're quite screwed if you can't change them... With proper classes, a solution might be:
CSS :
jQuery
See this fiddle
@Wex
@Wex
请尝试以下操作:它可以按照您的要求工作,但是水平方向,您想要垂直方向。但我确信它可能对你有帮助。
Try below: It works as you required but horizontally, you want vertically. But am sure it might help you.