【问题标题】:Why do html items display differently in IE and Firefox and Chrome?为什么 html 项目在 IE 和 Firefox 和 Chrome 中显示不同?
【发布时间】:2017-03-02 19:58:17
【问题描述】:

我在 html 页面上为我的视频设置了一组自定义控件。它在 Chrome 中或多或少地以我想要的方式显示,但是当我在 Edge 或 Firefox 中查看它时,显示的位置太高、不够高、位置完全错误。我花了一个周末的时间试图弄清楚这一点,但我的运气为零。这是他们的样子:

这是我当前的代码:

<div id ="video-container">
                  <video class = "jack7" width="450" height="230" id = "video">
                    <source src="<?php echo($videourl); ?>" type="video/mp4">  
                    Your browser does not support this video. Try chrome!
                  </video>
                  <div id="video-controls">
                    <button type="button" id="play-pause" ><img id = "playbtn" src="img/icons/play.png"></button>
                    <input type="range" id="seek-bar" step="0.01" value="0">
                    <button type="button" id="mute"><img id = "mutebtn" src="img/icons/unmute.png"></button>
                    <input type="range" id="volume-bar" min="0" max="1" step="0.01" value="1">
                    <button type="button" id="full-screen"><img id = "fsbtn" src="img/icons/fullscreen.png"></button>
                  </div>

              </div>

这是我的 CSS:

    .jack7{
    margin-left: 0px;
    margin-top: 0px;
    margin-bottom: 0px;
}
#video-container {
    margin-left: 234px;
    margin-top: -150px;
    margin-bottom: 30px;
    width: 450px;
    height: 230px;
    position: relative;
    background-color: #000000;
}

#video-controls {
    background: linear-gradient(rgba(255,255,255,0),#222222);
    position: relative;
    margin-top: -31px;
    opacity:0;
    padding: 5px;
    -webkit-transition: opacity .3s;
    -moz-transition: opacity .3s;
    -o-transition: opacity .3s;
    -ms-transition: opacity .3s;
    transition: opacity .3s;


}

#video-container:hover #video-controls {
    opacity:.9;
}

button {
    outline:none;
    background: none;
    border:0;
    font: inherit;
    line-height: normal;
    overflow: visible;
    padding: 0;
    -webkit-appearance: button; /* for input */
    -webkit-user-select: none; /* for button */
       -moz-user-select: none;
        -ms-user-select: none;

}

button:hover {
    cursor: pointer;
}

#seek-bar {
    outline:none;
    width: 295px;
    -webkit-appearance:none;
    background:transparent;

}
#seek-bar::-webkit-slider-thumb{
-webkit-appearance:none;
}
#seek-bar::-webkit-slider-thumb{

    width:7;
    height:5;
    background:#FF6000;
    outline:none;
    cursor:pointer;
}
#seek-bar::-moz-range-thumb{
    -webkit-appearance:none;
    width:7;
    height:5;
    background:#FF6000;
    outline:none;
    cursor:pointer;
}
#seek-bar::-ms-thumb{
    -webkit-appearance:none;
    width:7;
    height:5;
    background:#FF6000;
    outline:none;
    cursor:pointer;
}
#seek-bar::-webkit-slider-runnable-track{
  cursor:pointer;
  height:5;
  background:#8C8C8C;

}
#seek-bar::-moz-range-track{
  cursor:pointer;
  height:5;

  background:#8C8C8C;
}
#seek-bar::-ms-track{
  cursor:pointer;
  height:5;
  background:#8C8C8C;
}
#seek-bar::-ms-fill-lower{
    background:#FF9B2F;
    height:5;
}
#seek-bar::-ms-fill-upper{
    background:#8C8C8C;
    height:5;
}


#volume-bar {
    outline:none;
    width: 60;
    -webkit-appearance:none;
    background:transparent;

}
#volume-bar::-webkit-slider-thumb{
-webkit-appearance:none;
}
#volume-bar::-webkit-slider-thumb{

    width:7;
    height:5;
    background:#FF6000;
    outline:none;
    cursor:pointer;
}
#volume-bar::-moz-range-thumb{
    -webkit-appearance:none;
    width:7;
    height:5;
    background:#FF6000;
    outline:none;
    cursor:pointer;
}
#volume-bar::-ms-thumb{
    -webkit-appearance:none;
    width:7;
    height:5;
    background:#FF6000;
    outline:none;
    cursor:pointer;
}
#volume-bar::-webkit-slider-runnable-track{
  cursor:pointer;
  height:5;
  background:#8C8C8C;

}
#volume-bar::-moz-range-track{
  cursor:pointer;
  height:5;
  background:#8C8C8C;
}
#volume-bar::-ms-track{
  cursor:pointer;
  height:5;
  background:#8C8C8C;
}
#volume-bar::-ms-fill-lower{
    background:#FF9B2F;
    height:5;
}
#volume-bar::-ms-fill-upper{
    background:#8C8C8C;
    height:5;
}

我真的希望有人能帮我弄清楚为什么它们在不同的浏览器中显示不同。谢谢。

【问题讨论】:

  • 请提供您的DOCTYPE 规范,因为每个浏览器供应商和版本的呈现方式不同。例如,IE 有一个quirks mode,当 html 不符合规范时它会转换到它,从而导致其他设计含义。 en.wikipedia.org/wiki/Quirks_mode
  • @fyrye 你说的文档类型是什么意思?
  • 它在链接中有所描述,但是当您使用video 标签时,我假设&lt;!DOCTYPE html&gt; 在您的页面顶部指定。我想确保它是,并且您没有指定其他规范,例如 &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"&gt;
  • 尝试将&lt;!DOCTYPE html&gt; 规范直接添加到您的&lt;html&gt; 标记上方,然后查看其呈现方式是否有所不同。如下所示:w3schools.com/TAGS/tag_doctype.asp 这将告诉浏览器在其html5 渲染引擎上标准化渲染,而不是在怪癖模式下渲染。

标签: html css browser cross-browser compatibility


【解决方案1】:

这可能是因为浏览器的默认样式略有不同。

一个非常简单的解决方案是在您的项目中包含Reset,其目的是消除任何特定于浏览器的样式,并为您留下一个干净的工作表。

如果这不能解决问题,取决于您希望 browser compatibility 回溯多远,我建议使用 Flexbox。

Flexbox 可以处理您想要制作的布局,使其非常适合用于不需要大量向后兼容性的任何项目。

【讨论】:

  • 不仅仅是风格不同,而是浏览器的渲染引擎完全不同。
【解决方案2】:

归咎于每个框架和浏览器特定样式使用的边框模型。如果他们真的就一套规范达成一致,我们就不必面对跨浏览器兼容性的噩梦了。

【讨论】:

  • 在标准模式下会这样做。
猜你喜欢
  • 1970-01-01
  • 2019-06-08
  • 1970-01-01
  • 2018-10-09
  • 1970-01-01
  • 1970-01-01
  • 2014-01-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多