简体   繁体   English

在Internet Explorer中填充背景图片

[英]background-image gets padded in Internet Explorer

I have a XHTML 1.0 Transitional web page with following main table: 我有一个带有以下主表的XHTML 1.0 Transitional网页:

<table>
<tr>
<!-- header -->
</tr>
<tr>
<td class="left"><!-- menu --></td>
<td class="content"><!-- content and header iamge --></td>
<td class="right"><!-- other stuff --></td>
</tr>
<tr>
<!-- footer -->
</tr>
</table>

The CSS looks like this: CSS看起来像这样:

#content {
    width:100%;

    vertical-align:top;
    background-color:white;

    /* desired padding of the content */
    padding-right:10px;
    padding-left:10px;
    padding-bottom:10px;

    background-image: url(bilder/pseudo-panorama3.jpg);
    background-repeat:no-repeat;
    background-position: center top;
    padding-top:213px; /* height of the picture + the desired 10px padding to the content */

}

The planned behavior is as follows: 计划的行为如下:

计划的行为

In Firefox 31, the page shows up as expected: 在Firefox 31中,页面按预期显示:

在Firefox中的外观

In Internet Explorer 11, there is a space between the background image and the cell-border: 在Internet Explorer 11中,背景图片和单元格边框之间有一个空格:

在IE中的外观

What can I do to remove this space? 我该怎么做才能删除该空间? I already tried background-clip , but it didn't work. 我已经尝试过background-clip ,但是没有用。

The URL of the web page is here: http://www.thrs-heidelberg.de/v2/htdoc/ 网页的URL在这里: http : //www.thrs-heidelberg.de/v2/htdoc/

You should add this to your table tag.. 您应该将此添加到表格标签中。

<table border="0" cellpadding="0" cellspacing="0">...</table>

Give it a try and lets see if you have the same issue. 试试看,看看是否有相同的问题。

By default tables have a default value for cellpadding and cellspacing of 2, even if you dont specify this at all. 默认情况下,表格的cellpadding和cellspacing的默认值为2,即使您完全没有指定也是如此。

with css you can control the padding for each cell, but not the cellspacing. 使用css,您可以控制每个单元格的填充,但不能控制cellspacing。

Edit. 编辑。

Also try this... 也试试这个...

#content {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -o-box-sizing: border-box;
    -khtml-box-sizing: border-box;
    box-sizing: border-box;

    /* Put the rest of your css here for this class */
}

here is the issue... 这是问题所在...

you have a box with 100px in size (width) you add 10px in padding (left and right) 您有一个大小(宽度)为100px的框,在填充区(左右)中添加了10px

you should expect that the box its still 100px, but this is not the case on some browsers. 您应该期望该框仍为100px,但是在某些浏览器中却并非如此。

a total of 20px will be added to your original 100px, so your box will be 120px, this also happens if you add a border. 总共20px将添加到原始100px,因此您的框将是120px,如果添加边框,也会发生这种情况。

The way to fix this is to apply to the affected object the previous mentioned css, that will fix the box model issue. 解决此问题的方法是将受影响的对象应用于先前提到的CSS,这将解决盒子模型问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM