Such code works for Label:
function doGet() {
var app = UiApp.createApplication().setStandardsMode(true);
return app.add(app.createLabel('centered').setStyleAttributes(
{marginLeft: 'auto',
marginRight: 'auto',
width: '100px'}));
}
But it for button it doesn’t work. It doesn’t center the button. Why and how make it works?
Try adding display:block to the styles
Just to add: these aren’t Apps Script specific hacks per se… this is just standard CSS. You can use the Mozilla Developer Network as a resource for learning more about how different elements react to different CSS.
Also, all Gui Builder components have display:block implicitly set for them (that’s how it does the layouts).