框大小:边框框=>为IE8? [英] box-sizing: border-box => for IE8?

查看:29
本文介绍了框大小:边框框=>为IE8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要 box-sizing: border-box 用于 div 标签.

对于 Mozila Firefox 我已经尝试过

 -moz-box-sizing: border-box;

对于 IE(Internet Explorer) 我已经尝试了以下两种方法

 -ms-box-sizing: border-box;box-sizing: 边框框;

但它不能在 IE(Internet Explorer) 中工作.虽然我已经为 Internet Explorer 应用了 box-sizing: border-box; 它添加了边框和元素宽度的填充.为什么会这样?

应该是什么问题?请帮助和建议我.

注意:我使用的是 Internet Explorer8Windows7 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="服务器"><meta http-equiv="x-ua-compatible" content="IE=8"/><title></title><style type="text/css">*{box-sizing: 边框框;/* 它给出错误:Validation (CSS 2.1): 'box-sizing' is not a known CSS property name.*/-ms-box-sizing: 边框框;-moz-box-sizing: 边框框;-webkit-box-sizing: 边框框;}身体{背景:浅蓝色;颜色:#000000;字体系列:Trebuchet MS、Arial、Times New Roman;字体大小:12px;}#header{背景:#838283;高度:200px;宽度:1200px;}#包装器{背景:#FFFFFF;边距:0px 自动;宽度:1200px;高度:1024px;}#导航{背景:#a2a2a2;向左飘浮;边距:0px 0px;宽度:1200px;高度:25px;填充:3px;}</风格><身体><form id="form1" runat="server"><div id="包装器"><div id="标题"><h1>标题在这里<br/><h2 style="font-size: 60px;">ST ERP by Shanti Technology</h2>

<div id="导航">

</表单>

解决方案

IE8 支持 box-sizing 的无前缀版本,但与所有新"CSS 特性一样,它只在标准模式下支持.-ms-box-sizing 从未被任何版本的 IE 使用过.

确保您的页面具有 doctype 声明以在浏览器中触发标准模式.您还应该将无前缀的 box-sizing after 放在所有前缀之后,而不是 before 它们,并去掉 -ms-box-sizing 因为它真的不需要.

i want box-sizing: border-box for div tag.

For Mozila Firefox i have tried

        -moz-box-sizing: border-box; 

For IE(Internet Explorer) i have tried both of below alternatively

        -ms-box-sizing: border-box; 
            box-sizing: border-box;

but it couldn't works in IE(Internet Explorer). Though i have apply box-sizing: border-box; for Internet Explorer it adds with of border and padding in width of element. why does it happen?

what should be the problem? please help and sugest me.

NOTE: i am using Internet Explorer8 and Windows7 ultimate

PAGE CODE:

<%@ 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>

解决方案

IE8 supports the unprefixed version of box-sizing, but as with all "new" CSS features it only does so in standards mode. -ms-box-sizing has never been used by any version of IE.

Make sure your page has a doctype declaration to trigger standards mode in browsers. You should also place your unprefixed box-sizing after all the prefixes, not before them, and get rid of -ms-box-sizing as it's really not needed.

这篇关于框大小:边框框=>为IE8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆