【问题标题】:How do I make CSS button widths be the same in MSIE and Chrome?如何使 MSIE 和 Chrome 中的 CSS 按钮宽度相同?
【发布时间】:2013-03-25 01:14:39
【问题描述】:

我无法让最新版本的 Internet Explorer (9) 看起来与 Google Chrome (26.0.1) 相同。

总结 我有两个按钮,一个是使用一个名为:.linkBtn 的类 另一个按钮正在使用一个名为:.buynowBtn 的类 我尝试使用“min-width:85px;”将它们设置为 85px 宽 然而,在 MSIE 中,两个按钮都是 104 像素宽……而在 Google Chrome 中,虽然 LinkBtn 是 104 像素,buynowBtn 是 106 像素!

代码 以下是相关的 CSS 代码行:

    .lot .lotDesc .linkBtn, .lot .lotDesc .linkBtnFinal{ /* (TJ-NEW) new style ".lot .lotDesc .linkBtnFinal" added for finalise button */
    position:absolute;
    left:8px;
    bottom:0;
    }
    .linkBtn,.linkBtnFinal{ /* (TJ-NEW) new style ".linkBtnFinal" added for finalise button */
    position:relative;
    display:inline-block; /* (TJ-NEW) required to standardise button widths */
    float:left;/* (TJ-NEW) required to standardise button widths */
    }
    .linkBtn a{
    min-width:85px;
    margin-bottom:3px;
    }
    .buynowBtn{
    position:relative;
    display:inline-block; /* (TJ-NEW) required to standardise button widths */
    float:left; /* (TJ-NEW-180313) */
    }
    .buynowBtn a{
    /* CSS3 Corner Radius */
    -webkit-border-radius: 1em;
    -moz-border-radius: 1em;
    border-radius: 1em;
    /* (TJ-NEW) the following has been added to standardise button widths */
    min-width:85px;
    display:block;
    text-align:center;
    }
    .linkBtn a{
    color:#fff!important;
    font-size:12px!important;
    padding:0.1em 1em; /* (TJ-NEW) ? padding adjustment previously entered had been rolled back! */
    font-weight:normal;
    text-decoration:none!important;
    background:#BF2A48 ; /* Old browsers */
    /* CSS3 Gradient Background */
    background:-moz-linear-gradient(top, #BF2A48 0%, #BF2A48 49%, #9B0624 51%, #9B0624 100%); /* FF3.6+ */
    background:-webkit-gradient(linear, left top, left bottom, color-stop(0%,#BF2A48 ), color-stop(49%,#BF2A48 ), color-stop(51%,#9B0624), color-stop(100%,#9B0624)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #BF2A48 0%,#BF2A48 49%,#9B0624 51%,#9B0624 100%); /* Chrome10+,Safari5.1+ */
    background:-o-linear-gradient(top, #BF2A48 0%,#BF2A48 49%,#9B0624 51%,#9B0624 100%); /* Opera 11.10+ */
    background:-ms-linear-gradient(top, #BF2A48 0%,#BF2A48 49%,#9B0624 51%,#9B0624 100%); /* IE10+ */
    background:linear-gradient(to bottom, #BF2A48 0%,#BF2A48 49%,#9B0624 51%,#9B0624 100%); /* W3C */
    /*filterrogidXImageTransform.Microsoft.gradient( startColorstr='#BF2A48 ', endColorstr='#9B0624',GradientType=0 ); *//*IE6-8 */ /* (TJ-NEW) commented out IE style, as not working anyway and causes issue with fixed width */
    /* CSS3 Corner Radius */
    -webkit-border-radius: 1em;
    -moz-border-radius: 1em;
    border-radius: 1em;
    /* (TJ-NEW) the following has been added to standardise button widths */
    display:block;
    text-align:center;
    }
    .linkBtn a:hover{
    color:#fff;
    text-decoration:none;
    background: #9B0624;
    }



    .buynowBtn a{
    color:#fff!important;
    font-size:12px!important;
    padding:0.1em 1em; /* ******* Updated to match place bid (TJ) ******* */
    font-weight:normal;
    text-decoration:none!important;
    background:#888; /* Old browsers */
    /* CSS3 Gradient Background */
    background:-moz-linear-gradient(top, #888 0%, #888 49%, #666 51%, #666 100%); /* FF3.6+ */
    background:-webkit-gradient(linear, left top, left bottom, color-stop(0%,#888), color-stop(49%,#888), color-stop(51%,#666), color-stop(100%,#666)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #888 0%,#888 49%,#666 51%,#666 100%); /* Chrome10+,Safari5.1+ */
    background:-o-linear-gradient(top, #888 0%,#888 49%,#666 51%,#666 100%); /* Opera 11.10+ */
    background:-ms-linear-gradient(top, #888 0%,#888 49%,#666 51%,#666 100%); /* IE10+ */
    background:linear-gradient(to bottom, #888 0%,#888 49%,#666 51%,#666 100%); /* W3C */
    /* filterrogidXImageTransform.Microsoft.gradient( startColorstr='#888', endColorstr='#666',GradientType=0 ); *//* IE6-8 */ /* (TJ-NEW) commented out IE style, as not working anyway and causes issue with fixed width */
    }
    .buynowBtn a:hover{
    color:#fff;
    text-decoration:none;
    background: #444;
    }
    .buynowBtn{
    position:relative;
    display:inline-block; /* (TJ-NEW) required to standardise button widths */
    float:left; /* (TJ-NEW-180313) */
    }
    .buynowBtn a{
    /* CSS3 Corner Radius */
    -webkit-border-radius: 1em;
    -moz-border-radius: 1em;
    border-radius: 1em;
    /* (TJ-NEW) the following has been added to standardise button widths */
    min-width:85px;
    display:block;
    text-align:center;
    }

有什么想法吗? - 我尝试使用“width:”而不是“min-width”,但文本似乎换成了两行,这是一场灾难。

感谢

J

【问题讨论】:

  • 你能添加相关的 html - 只是关于按钮的特定位......
  • 如果你在 js fiddle 中设置它,我们都可以使用你的 CSS/HTML ... 像这样:jsfiddle.net/CWt4c/2
  • 元素的实际宽度为[width of content box (width)] + [left/right paddings] + [left/right border-widths]:css-tricks.com/the-css-box-model

标签: button width css


【解决方案1】:

发生这种情况的原因有很多种,从盒子模型的差异到正在使用的字体的差异。

你仍然可以像这样做 IE-only CSS:

<!--[if IE 9]--><link to your CSS /><!--[endif]-->

那里有几个选项可让您定位特定版本的 IE(例如)

<!--[if IE]-->targets all versions of IE<!--[endif]-->
<!--[if IE 9]-->targets IE 9 only<!--[endif]-->
<!--[if lt IE 8]-->targets versions 7 and below of IE (lt: <)<!--[endif]-->
<!--[if gte IE 8]-->targets versions 8 and up of IE (gte: >=)<!--[endif]-->

但是,如果按钮绝对必须是像素完美的,请尝试改用图像。

【讨论】:

  • 我只针对不同版本的 IE 作为最后的手段——你真的想维护那么多特定于浏览器的样式表吗?我会尝试去掉所有有问题的按钮的 CSS 并逐渐建立它,直到你看到导致差异的原因。这样一来,它的可维护性就会大大提高(您将了解如何使其跨浏览器兼容)。还给您一个重构 CSS 的机会 - 例如,您有多个对“.buynowBtn a”的引用。
猜你喜欢
  • 2018-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-01
  • 2016-08-11
  • 1970-01-01
相关资源
最近更新 更多