简体   繁体   English

具有DIV top属性的CSS跨浏览器问题

[英]CSS cross-browser issue with DIV top property

There is one issue that drives me nuts for several days. 有一个问题使我发疯了好几天。 I created a theme for Wordpress especially CSS http://fabienmischler.com/ . 我为Wordpress创建了一个主题,尤其是CSS http://fabienmischler.com/ The problem is the DIV line on the right side is only aligned within Chrome Mac-version and Safari. 问题是右侧的DIV线仅在Chrome Mac版本和Safari中对齐。 All other Browser (INCLUDING CHROME Win-version) render it differently. 所有其他浏览器(包括CHROME Win版本)都以不同的方式呈现它。 The same happens with the Contact form on the right (that is a modified plugin from slick-form). 右侧的Contact表单(这是slick-form的修改后的插件)也会发生同样的情况。 Is there any elegant way to fix this issue or do I need to use CSS hacks? 有什么优雅的方法可以解决此问题,还是我需要使用CSS hacks? and if yes how for Chrome Windows version? 如果可以,Chrome Windows版本如何?

The container is absolute, the DIV (with the line) too. 容器是绝对的,DIV(带线)也是。

Here is the DIV 这是DIV

#hr-title {
position: absolute;
right: 0;
top: 100px;
width: 14%;
height: 1px;
z-index: 9999;
background-color: black; }

This DIV is part of the Container-Div (standard in Wordpress): 此DIV是Container-Div(Wordpress中的标准)的一部分:

div#container {
margin: 0;
position: absolute;
left: 300px;
height: 100%;
right: 0;
top: 0; }

All this is packed in the standard stylesheet (style.css) from Wordpress. 所有这些都打包在Wordpress的标准样式表(style.css)中。

I CSS reset the sheet according to Eric Meyer http://meyerweb.com/eric/tools/css/reset/ 我根据Eric Meyer的http://meyerweb.com/eric/tools/css/reset/

Thanks in advance!!!! 提前致谢!!!!

The problem here is the rendering of the text on the different browser, especially the line-height and vertical-alignment on texts. 这里的问题是在不同的浏览器上呈现文本,尤其是文本的line-heightvertical-alignment They are never identical ... 他们从不一样...

A possible solution would be to not use the underlined text decoration for your line under title but to draw it as a separate element using the same top position as your other line. 一种可能的解决方案是,不对标题行使用underlined text decoration ,而是使用与其他行相同的top位置将其绘制为单独的元素。 This way, it will always be correctly aligned on each browser. 这样,它将始终在每个浏览器上正确对齐。

Here is some sample CSS code to achieve it: 这是一些实现它的示例CSS代码:

h1 { float: right; text-decoration: none; }
h1:before { content: " "; position: absolute; width: 100%; height: 1px; top: 101px; background: #000; }

Update 更新

Another solution would be to absolute position the line relative to the title. 另一种解决方案是将行相对于标题绝对定位。 Setting the line relative to the title to a top of 16px aligns equally with the outer line which is positioned on 96px 将与标题相对的行设置为16px的顶部与位于96px的外部行平均对齐

#hr-title { top: 96px; }
h1.entry-title { float: right; position: relative; text-decoration: none; margin-bottom: 15px; }
h1:before { background: #000; width: 100%; height: 1px; top: 16px; position: absolute; content: " "; }

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

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