问题描述
我的网络应用程序中有面板,我正在设置样式属性,如下所示:
panel.setStyleAttribute('margin 'left','auto')。setStyleAttribute('margin-right','auto');
这在铬中非常完美,可以按照预期将元素居中。但是在IE中,这些元素粘在屏幕的左侧。
有没有办法解决这个问题?
浏览器,保证金:如果您强制使用标准模式而不是怪癖模式,则自动仅适用于Internet Explorer。
$ b UiApp默认使用CSS规则,除非(a) GuiBuilder组件在最初的应用程序创建过程中强制执行标准模式,或者(b)您明确要求标准模式。
这将使您处于标准模式, IE也是:
函数doGet(){
var app = UiApp.createApplication()。setStandardsMode(true);
return app.add(app.createLabel('centered')。setStyleAttributes(
{marginLeft:'auto',
marginRight:'auto',
width:'100px' }));
请注意 setStandardsMode(true) - 没有这个它不会在IE中工作。要小心,因为标准模式样式的解释有别于怪癖模式,所以这可能会改变布局的其他方面。
一些注释:
- setStandardsMode仅在初始应用程序创建时(即,在doGet中)受到尊重,如果您稍后尝试在处理程序中设置它,则忽略它。
- GuiBuilder的布局规则采用标准模式,这就是为什么这会隐式强制标准模式。如果在doGet期间(无论是显式还是加载另一个组件)在未设置为标准模式的应用程序中将回调函数中的GuiBuilder组件加载到回调函数中,由于处于怪癖模式,布局和样式可能会发生微妙的更改。
I have panels in my web app, and I am setting style attributes like so:
panel.setStyleAttribute('margin-left', 'auto').setStyleAttribute('margin-right','auto');
This wors perfectly in chrome, centering the element as expected. However in IE, the elements are stuck to the left of the screen.
Is there any way around this issue ?
Unlike other browsers, margin:auto only works in Internet Explorer if you force standards mode rather than quirks mode.
UiApp defaults to quirks mode CSS rules, unless (a) you load a GuiBuilder component in the initial app creation, which forces standards mode, or (b) you explicitly ask for standards mode.
This will set you in standards mode and therefore work in IE too:
function doGet() {
var app = UiApp.createApplication().setStandardsMode(true);
return app.add(app.createLabel('centered').setStyleAttributes(
{marginLeft: 'auto',
marginRight: 'auto',
width: '100px'}));
}
Note the setStandardsMode(true) - without this it won't work in IE. Be careful though because standards mode styles are interpreted differently sometimes than quirks mode, so this might change other aspects of your layout.
Some notes:
- setStandardsMode is only respected on initial app creation (i.e., in doGet) and is ignored if you try to set it in a handler later.
- the GuiBuilder's layout rules assume standards mode, which is why that implicitly forces standards mode. If you load a GuiBuilder component in a callback in an app that was not set to standards mode during doGet (either explicitly or because you loaded another component) there might be subtle changes to the layout and styles due to it being in quirks mode.
这篇关于Google应用程序脚本UiApp不会在Internet Explorer中集中元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!