CSS float:none 和 margin-right
我刚刚学习了一些有关响应式网页设计或流畅布局的教程。
在示例中,在较小的屏幕尺寸下,3 列布局会自动转换为 2 列布局。他们通过 2 个 CSS 属性使这成为可能;
float:none
margin-right:0
您能帮我理解这是如何发生的以及保证金权利是根据什么计算的吗?
链接到示例 http://www.alistapart.com/articles/responsive-web-design /
I was just going through some tutorial on responsive web design or fluid layouts.
In the example, a 3-column layout automatically converts to a 2-column layout at lower screen sizes. They have made that possible through 2 CSS properties;
float:none
margin-right:0
Could you please help me understand how this happens and margin-right is calculated based on what?
Link to example http://www.alistapart.com/articles/responsive-web-design/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这篇文章无疑是向您展示我如何做到这一点的示例,因此您可以根据您的特定需求进行调整。你必须更进一步。希望以下解释和@Wesley 的回答能帮助您做到这一点。
float:none
通过在元素(之前是浮动的)上设置 float:none,这会导致这些元素在屏幕尺寸的情况下彼此堆叠。浮动过去导致元素并排排列。
margin-right:0
在此示例中,他们设置 margin-right:0 以便这些图像在右侧很好地排列。如果您注意到的话,这些图像是对于这些尺寸的屏幕来说最右边的图像。如果 margin-right 未设置为零,它将继承
.figure
的样式,该样式确实应用了 margin-right。The article definately is a show you an example of how I do it, so you can take it an adapt it to your particular needs. You will have to go a step beyond. Hopefully the following explanations and @Wesley's answer will help you do that.
float:none
By setting float:none on the elements (that were previously floated), this causes these elements to stack on top of each other for those sizes of screens. The floating perviously caused the elements to line up side-to-side.
margin-right:0
In this example, they are setting margin-right:0 so that those imagines line up nicely on the right hand side. If you notice, those images are the ones that are the furthest right for those sizes of screens. If margin-right wasn't set to zero, it would inherit the style of
.figure
which does have a margin-right applied.您链接到的示例包含对答案的详尽解释,超出了我在这里所能提供的范围。他们使用 CSS 媒体查询来确定视口的大小:
http://www.w3。 org/TR/css3-mediaqueries/
CSS 文件中的示例:
使用
标记的
media
属性的示例:The example you linked to contains a thorough explanation of the answer, more than I can provide here. They are using CSS media queries to determine the size of the viewport:
http://www.w3.org/TR/css3-mediaqueries/
Example in a CSS file:
Example using the
media
attribute of the<link>
tag: