使用位置最大的缺点是什么:绝对位置和绝对位置顶部/左侧浮动和margin+padding,如果网站是固定宽度(970px),居中?
使用 CSS 定位的最大缺点是什么(来自 Dreamweaver AP Div) 的所有内容,而不是固定宽度、居中网站的 Float
?
如果我不关心
- 移动用户
- 小屏幕用户(小于 1024 px 屏幕尺寸)
但我关心
- 屏幕阅读器用户
- 所有浏览器用户(包括 IE6)
What is the biggest disadvantage to use CSS positioning(From Dreamweaver AP Div) for everything instead Float
for fixed width, centered website?
if I don't care for
- Mobile users
- Small screen users (smaller than 1024
px screen size)
But I care for
- Screen reader user
- All browser user (including IE6)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不关心小分辨率,那么这只是灵活性问题:当您使用绝对定位时,就会破坏流程。因此,所有东西的尺寸都必须准确。
对于许多元素或情况(制作完美的图像标题...),这是最好的(有时是唯一的)选择。大多数时候,“相对”更好,因为它保持了流程(元素留在流程中),但您可以相对于定位的父级修改定位(不要忘记定位父级,即使您没有给出明确的位置;例如,只需添加位置:相对,没有顶部/左侧...)。而且,好的一点是,“position:relative”为 IE 中的元素提供了 haslayout !
例如,如果您想将页脚放在内容后面,绝对是一个坏主意,因为您可能不知道内容的高度。
但是,如果您想将菜单放在屏幕顶部,但又不想打扰使用屏幕阅读器的人(大菜单应该位于线性化文档的末尾),则绝对定位是完美的。
浮动并不是完美的解决方案,正如您在许多博客上看到的那样:这是一个非常特殊的定位,但它很有用,因为“内联块”并不总是有效。当然,当您确实想让元素浮动时,它也很有用。
当你英语说得不好时,解释起来就不那么容易了:)
If you don't care about small resolution, it's just a question of flexibility : when you use absolute positionning, you break the flow. So, everything must be exactly sized.
For many elements or situations (make a perfect image title...), it's the best (and sometimes unique) choice. Most of time, 'relative' is better because it kept the flow (element stay in the flow) but you can modify positionning relatively to is positionned parent (don't forget to position parent, even if you don't give explicit position ; for example just add position:relative, without top/left...). And, good point, "position: relative" give haslayout to element in IE !
For example, if you want to put footer after a content, absolute is a bad idea because you probably don't know content's height.
But if you want to put a menu at the top of screen but don't want to bother people who use screen reader (big menu should be at the end, on a linearized document), absolute positionning is perfect.
Float is not the perfect solution, as you can read on many blogs : it's a very particular postionning but it's usefull because 'inline-block' doesn't work all the time. And, of course, it's also usefull when you really want to have elements to be float.
Not so easy to explain when you don't speak english well :)
它不是一个/或者两者兼而有之...浮动对于某些情况和位置是有好处的:对于其他情况是绝对的,因此您可能需要在您的设计中使用两者。如果你真的想使用 CSS,我建议你购买并阅读这本书 http://www.transcendingcss.com/
It's not either/or it's both... Float is good for some situations and position:absolute for others, therefore you may need to use both for your design. If you are serious about using CSS I suggest you buy and read this book http://www.transcendingcss.com/
如果元素包含文本,您无法预测其高度(因为您不知道它实际呈现的字体和字体大小)。
这使得不可能将一个元素的顶部放置在另一个元素的底部。例如:忘记传统的“带有页眉和页脚的两列”布局。
If an element contains text, you can't predict its height (because you don't know what font and what font size it will actually be rendered at).
That makes it impossible to place the top of one element at the bottom of another element. For example: Forget about having a traditional "Two column with header and footer" layout.