Html CSS:当使用float:left将我的内容锚定到左侧的菜单时,菜单在IE中消失 我有一个左边的链接,中间有一个菜单。如果内容比链接长,它将环绕在链接下方,而不是整齐地保持在右侧
将Html CSS:当使用float:left将我的内容锚定到左侧的菜单时,菜单在IE中消失 我有一个左边的链接,中间有一个菜单。如果内容比链接长,它将环绕在链接下方,而不是整齐地保持在右侧,html,css,internet-explorer,Html,Css,Internet Explorer,将float:left添加到我的contentdiv可以解决这个问题,但在IE中,它会导致菜单(和页脚)完全消失 我需要解决float:left的问题,或者找到另一种方法将所有内容保留在菜单的右侧 下面是html和css代码的精简版本,它显示了实际的问题。将#content{float:left;}替换为#content{},以查看原始包装问题 content{margin:200px;}几乎解决了这个问题——但是以前应该包装的线条现在比上面的线条再左大约3个像素,同样只在IE中 html: 好
float:left
添加到我的content
div可以解决这个问题,但在IE中,它会导致菜单(和页脚)完全消失
我需要解决float:left
的问题,或者找到另一种方法将所有内容保留在菜单的右侧
下面是html和css代码的精简版本,它显示了实际的问题。将#content{float:left;}
替换为#content{}
,以查看原始包装问题
content{margin:200px;}
几乎解决了这个问题——但是以前应该包装的线条现在比上面的线条再左大约3个像素,同样只在IE中
html:
好吧,如果你对我以前的答案不满意,我会一步一步地看一遍 在HTML/CSS中,有很多事情你可能会做错,但也有一些事情你可以做对,如果你做对了,你就不用担心你做错了。因此,最好是学会你能做对的几件事,这就是为什么我告诉你阅读其他问题/答案的原因 我可以告诉你去掉你的#主分区中的“位置:相对”一行,你会发现问题已经解决了。。。但我不会,因为你一般不会改进你的CSS 首先使用doctype。如有可能,请使用严格的,如:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
fourth:不要在同一方向上浮动多个div,以避免出现某些IE问题。如果需要两个以上的div,请创建包装器div。例如,对于一个三列布局,您将第一列向左浮动,然后是一个带有float:right的包装div,其中第二列向左浮动(在包装内),第三列向右浮动(在包装内)。。。等等。简单但非常可控
前答复: 为所有div指定一个宽度(maxwidth resp.),将菜单向左浮动,将内容向右浮动。所有问题都解决了。也适用于百分比宽度 或 为主div指定内联属性,为菜单div指定固定宽度 或 使用网格(例如,或) 或 阅读有关stackoverflow主题的任何其他帖子(参见右侧) 找到另一种方法将我的所有内容保留在菜单右侧
考虑添加一个标准模式doctype,以减少IE的怪癖。当涉及到CSS和HTML中可以执行的无数组合时,很难判断哪些问题具有相同的原因和解决方案,哪些问题具有相似的症状和关键字。如果你知道另一个问题也有同样的问题,并且通过各种方式解决了,那就把它链接起来。content{float:right;width:500px;}并不能解决问题--它只是把内容进一步移到右边的“内联属性”——什么?我不需要知道本周CSS社区中哪种解决方案更“正确”,我现在没有时间花在更加熟悉CSS上。当我的CSS助手不可用时,我只需要修复页面中的一个bug。事实上,获取问题的答案也是如此。我问,“我怎样才能让X像Y一样工作”,而不是“教我为什么X不做Y。”
* {
padding: 0;
margin: 0;
text-decoration:none;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
color: #fff;
}
img { border:0px; }
body { background-color:#454547; padding: 4px; }
#main { position: relative; top: 20px; }
#nav {
position: relative;
left: 0px;
width: 200px;
float: left;
font-weight: bold;
padding: .25em;
line-height: 1.25em;
font-size: 1em;
}
#nav a { display: block; height: 35px; padding: 3px; color:#FFFFFF; }
#nav a:hover { background-color:#CCCCCC; color:#333; }
#footer { width: 100%; clear: both; margin: 0px 0px 10px 0px; padding: 10px; font-size:10px; }
#content { float:left; }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@charset "utf-8";
/*
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.6.0
Adapted by Markus Hausammann
*/
/* reset rules */ * {
font-size: 100.01%;
overflow: hidden
}
html, body
{
color: #313131;
background-color: #ffffff;
font-family: Geneva, Arial, Verdana, Helvetica, sans-serif;
line-height: 1.2em;
}
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, textarea, p, blockquote, th, td {
margin: 0;
padding: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
fieldset, img {
border: 0;
}
address, caption, cite, code, dfn, em, strong, th, var {
font-style: normal;
font-weight: normal;
}
li {
list-style: none;
}
caption, th {
text-align: left;
}
h1, h2, h3, h4, h5, h6 {
font-size: 100%;
font-weight: normal;
}
q:before, q:after {
content: '';
}
abbr, acronym {
border: 0;
font-variant: normal;
}
/* to preserve line-height and selector appearance */
sup {
vertical-align: text-top;
}
sub {
vertical-align: text-bottom;
}
input, textarea, select {
font-family: inherit;
font-size: inherit;
font-weight: inherit;
}
/*because legend doesn't inherit in IE */
legend {
color: #000;
}
del, ins {
text-decoration: none;
}
/* clearing methods */
/* clearfix method for clearing floats */ .clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
/* essential for Safari browser !! */ .clearfix {
display: block;
}
/* removes ugly mozilla dotted link borders */
a:active
{
outline: none;
}
#content { margin-left: 200px; }