广告不会在 ie 中居中,除非正文是 text-align:center
我有一个加载脚本的广告,它位于居中的 div 内。 无论我做什么,ie6、ie7 和 ie8 都不会居中,除非 body 有
text-align:center;
现在 div 的 css 设置如下,仅适用于 chrome/firefox:
#header{
width:730px;
margin:0px auto;
text-align:center;}
我尝试使用 .getScript 和如下链:
.css('text-align', 'center');
但该脚本不会在 Chrome 中从外部加载,然后它将整个页面的 CSS 设置为脚本的宽度。我还尝试将其放入 html 页面中,并在居中的 div 内使用 jquery 加载该页面,但它只是位于页面的左侧。
我也尝试等到 $(document).ready 然后将 div 居中,但这也不起作用。
主要问题是页面中的所有文本都没有被任何其他 div 包裹,我可以在其中将文本向左对齐,并且这已应用于大约 1000 多个网页。
I have an advertisement that loads a script, and its inside a centered div.
No matter what I do ie6, ie7, and ie8 won't center it unless body has
text-align:center;
Right now the css for the div is set like this, which works only on chrome/firefox:
#header{
width:730px;
margin:0px auto;
text-align:center;}
I tried using .getScript with a chain like this:
.css('text-align', 'center');
But the script won't load externally in chrome and it then sets the CSS for the entire page to the width of the script. I also tried putting it in an html page and loading that with jquery inside of a centered div, but it just sits on the left side of the page.
I also tried waiting till $(document).ready and then centering the div, but that didn't work either.
The main problem is all of the text in the page isn't wrapped by any other div where I can align the text left, and this is being applied to about 1000+ web pages.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
澄清一下:除了 之外,还有什么东西包裹着内容吗?如果没有,只需将正文文本居中对齐,按照 Jules 的建议在广告 div 上使用 margin 0 auto,然后在内容上将文本向左对齐。如果您的 DOM 缺少内容方面的任何内容,您可能不得不妥协。
To clarify: is there nothing wrapping the content other than ? If not, just text-align center on the body, use margin 0 auto on the ad div as Jules suggested, and text-align left on the content. If your DOM is lacking anything around the content, you may have to live with a compromise.