在所有浏览器中将包装器高度设置为相等

发布于 2024-12-23 18:36:02 字数 499 浏览 4 评论 0原文

我有一个包装器,我需要在所有浏览器中将其高度设置为相等。

我该怎么做? 实际上我尝试过使用 min-height 和 height:100% 但它不起作用。

这是它在不同浏览器中的实际显示方式:

在此处输入图像描述 这是我的CSS:

    body
{
    background: #99CCFF;
    margin: 20px 0;
    padding: 0;
    width: 100%;
}

    #wrapper
{
    position: relative;
    margin:-20px auto;
    width:auto;
    height:450px;
    background-image: url('../images/bg.jpg');
    background-repeat: repeat;
}       

I have a wrapper and I need to set it's height equal in all browsers.

How do I do that?
Actually I have tried by using min-height and height:100% but it's not working.

This is how it actually shows in different browsers:

enter image description here
Here is my CSS:

    body
{
    background: #99CCFF;
    margin: 20px 0;
    padding: 0;
    width: 100%;
}

    #wrapper
{
    position: relative;
    margin:-20px auto;
    width:auto;
    height:450px;
    background-image: url('../images/bg.jpg');
    background-repeat: repeat;
}       

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别念他 2024-12-30 18:36:02

@Kiran

,首先你应该摆脱你的负边距。如果您发现某个浏览器存在布局问题,您可以稍后使用 conditional css 语句来处理该问题你的标题和一个单独的 css 文件。

但要回答你的主要问题。确保始终使用 margin:0;和填充:0;在进行初始布局时。这将在一开始就消除很多布局错误。某些版本的 IE 不符合 Web 标准,因此有时除了解决方法之外您无能为力。 (即条件CSS)

看看为您创建的这个示例页面。
我拿走了你的位置:相对,并添加了浮动和显示属性,以及将正文和#wrapper上的边距和填充更改为零。我还将包装器的宽度从自动更改为 100%。

http://www.albatrossfonts.com/heightcss/wrapperHeight.html

我使用白色作为包装纸的背景颜色也是如此,因为我无权访问您的图像。

这是代码:

body
{
    background: #99CCFF;
    margin: 0;
    padding: 0;
    width: 100%;
}

#wrapper
{
    margin: 0;
    padding: 0;
    width: 100%;
    height: 450px;
    display: block;
    float: left;
    background-image: url('../images/bg.jpg');
    background-repeat: repeat;
    background-color: #ffffff;
}

@Kiran

You should get rid of your negative margin, first of all. If you see one browser has a layout issue, you can deal with that later using a conditional css statement in your header, and a separate css file.

But to answer your main question. make sure you always use margin:0; and padding:0; when doing initial layout. this will take away a lot of layout bugs in the very beginning. Some versions of IE don't conform to web standards, so there isn't much you can do sometimes, other than workarounds. (i.e. conditional css)

Have a look at this sample page a created for you.
I took away you position:relative, and added the float and display properties, as well as changed your margins and padding to zero on BOTH body and #wrapper. I also changed the width of your wrapper from auto, to 100%.

http://www.albatrossfonts.com/heightcss/wrapperHeight.html

I used white as a background color for the wrapper as well, since I don't have access to your image.

Here's the code:

body
{
    background: #99CCFF;
    margin: 0;
    padding: 0;
    width: 100%;
}

#wrapper
{
    margin: 0;
    padding: 0;
    width: 100%;
    height: 450px;
    display: block;
    float: left;
    background-image: url('../images/bg.jpg');
    background-repeat: repeat;
    background-color: #ffffff;
}

使用 CSS 重置 http://meyerweb.com/eric/tools/css/reset/ 每个浏览器对内边距、边距和其他属性的处理方式不同。

/* http://meyerweb.com/eric/tools/css/reset/ 
       v2.0 | 20110126
       License: none (public domain)
    */

    html, body, div, span, applet, object, iframe,
    h1, h2, h3, h4, h5, h6, p, blockquote, pre,
    a, abbr, acronym, address, big, cite, code,
    del, dfn, em, img, ins, kbd, q, s, samp,
    small, strike, strong, sub, sup, tt, var,
    b, u, i, center,
    dl, dt, dd, ol, ul, li,
    fieldset, form, label, legend,
    table, caption, tbody, tfoot, thead, tr, th, td,
    article, aside, canvas, details, embed, 
    figure, figcaption, footer, header, hgroup, 
    menu, nav, output, ruby, section, summary,
    time, mark, audio, video {
        margin: 0;
        padding: 0;
        border: 0;
        font-size: 100%;
        font: inherit;
        vertical-align: baseline;
    }
    /* HTML5 display-role reset for older browsers */
    article, aside, details, figcaption, figure, 
    footer, header, hgroup, menu, nav, section {
        display: block;
    }
    body {
        line-height: 1;
    }
    ol, ul {
        list-style: none;
    }
    blockquote, q {
        quotes: none;
    }
    blockquote:before, blockquote:after,
    q:before, q:after {
        content: '';
        content: none;
    }
    table {
        border-collapse: collapse;
        border-spacing: 0;
    }

Use CSS reset http://meyerweb.com/eric/tools/css/reset/ Each browser treats padding, margin and other properties differently.

/* http://meyerweb.com/eric/tools/css/reset/ 
       v2.0 | 20110126
       License: none (public domain)
    */

    html, body, div, span, applet, object, iframe,
    h1, h2, h3, h4, h5, h6, p, blockquote, pre,
    a, abbr, acronym, address, big, cite, code,
    del, dfn, em, img, ins, kbd, q, s, samp,
    small, strike, strong, sub, sup, tt, var,
    b, u, i, center,
    dl, dt, dd, ol, ul, li,
    fieldset, form, label, legend,
    table, caption, tbody, tfoot, thead, tr, th, td,
    article, aside, canvas, details, embed, 
    figure, figcaption, footer, header, hgroup, 
    menu, nav, output, ruby, section, summary,
    time, mark, audio, video {
        margin: 0;
        padding: 0;
        border: 0;
        font-size: 100%;
        font: inherit;
        vertical-align: baseline;
    }
    /* HTML5 display-role reset for older browsers */
    article, aside, details, figcaption, figure, 
    footer, header, hgroup, menu, nav, section {
        display: block;
    }
    body {
        line-height: 1;
    }
    ol, ul {
        list-style: none;
    }
    blockquote, q {
        quotes: none;
    }
    blockquote:before, blockquote:after,
    q:before, q:after {
        content: '';
        content: none;
    }
    table {
        border-collapse: collapse;
        border-spacing: 0;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文