【发布时间】:2012-07-21 10:31:32
【问题描述】:
我想要box-sizing: border-box 用于div 标签。
对于 Mozila Firefox 我已经尝试过
-moz-box-sizing: border-box;
对于 IE(Internet Explorer) 我已经尝试过以下两种方法
-ms-box-sizing: border-box;
box-sizing: border-box;
但它无法在 IE(Internet Explorer) 中运行。
虽然我已经为 Internet Explorer 应用了box-sizing: border-box;,但它在元素宽度中添加了边框和填充。为什么会这样?
应该是什么问题?请帮助和建议我。
注意:我使用的是 Internet Explorer8 和 Windows7 Ultimate
页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MainPage.aspx.cs" Inherits="MainPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="x-ua-compatible" content="IE=8"/>
<title></title>
<style type="text/css">
*
{
box-sizing: border-box; /*it gives error:Validation (CSS 2.1): 'box-sizing' is not a known CSS property name. */
-ms-box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
body
{
background: lightblue;
color: #000000;
font-family: Trebuchet MS, Arial, Times New Roman;
font-size: 12px;
}
#header
{
background: #838283;
height: 200px;
width: 1200px;
}
#wrapper
{
background: #FFFFFF;
margin: 0px auto;
width: 1200px;
height: 1024px;
}
#navigation
{
background: #a2a2a2;
float: left;
margin: 0px 0px;
width: 1200px;
height: 25px;
padding: 3px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="wrapper">
<div id="header">
<h1>
Header goes here</h1>
<br />
<h2 style="font-size: 60px;">
ST ERP by Shanti Technology</h2>
</div>
<div id="navigation">
</div>
</div>
</form>
</body>
</html>
【问题讨论】:
-
验证错误无关紧要 -
box-sizing是 CSS3 的一部分,而不是 CSS2.1。如果您真的关心验证,请注意前缀也不会针对任何版本的 CSS 进行验证。 -
我可以更改 CSS 的版本吗?
-
你检查我的答案了吗? -ms-box-sizing:边框框;不需要
-
Visual Studio 允许您针对 CSS3 进行验证。见stackoverflow.com/questions/3931801/… 和stackoverflow.com/questions/4810401/…
-
Windows 7 和 IE8。哎呀。
标签: html internet-explorer css internet-explorer-8