I would approach it the same as Lucas - Try this fiddle: http://jsfiddle.net/rockmandew/ddow1nd9/
Basically, I took the button and set its styles to the following:
.test {
position: absolute;
left: 50%;
-moz-transform: translate(-50%, 0);
-ms-transform: translate(-50%, 0);
-webkit-transform: translate(-50%, 0);
transform: translate(-50%, 0);
height:25px;
}
However, this won't work alone - you need to wrap the button in a container (div) and set its position to relative. Which you can see in the following styles:
.button-contain {
position:relative;
height:25px;
}
The only issue with this solution is the fact that you have to set an explicit height on your button and set the same height on your button-container, this will allow the other content to respond to the height of the button. When you set the button Absolute, it removes it from the normal flow, thus if you don't set a height on the containing div, the div will have a height of 0 - hopefully, that makes sense to you. If you need further clarification, just ask!
First Update:
Okay, take a look at: https://jsfiddle.net/rockmandew/fhceb7dv/1/ (you will need to replace 'test' with your "$(element)" selector.)
I have adjusted the code for Jquery implementation - since the code is autogenerated, I have included a line of code which will wrap your target element with the "button-contain" I mentioned earlier. I then chained the CSS properties on top of that:
$('.test').wrap("<div class='button-contain'></div>").css({
"position":"absolute",
"left":"50%",
/* My understanding is that the jQuery .css() will add browser prefixes automatically
"-moz-transform":"translate(-50%, 0)",
"-ms-transform":"translate(-50%, 0)",
"-webkit-transform":"translate(-50%, 0)",
*/
"transform":"translate(-50%, 0)",
"height":"25px"
});
As you can see, the Jquery takes care of the browser prefixes. So this will wrap your $(element) in a div with the class of "button-contain", it will then set the CSS of the button according to the styles applied. Finally, you will need to add one class to your CSS (unless you want to handle the "button-contain" styles with Jquery as well). So your button-contain will have the same styles as mentioned before:
.button-contain {
position:relative;
height:25px;
}
Hopefully, this works for you. I'm not to sure what is going on with the padding though. Lets see where this gets you and go from there.
Second Update:
Try using a similar application of the following code:
$("#elem").css("cssText", "width: 100px !important;");
So instead of:
$(element).css({"padding-left": "0 !important"});
Try using it like so:
$('.test').wrap("<div class='button-contain'></div>").css({
"position":"absolute",
"left":"50%",
/* My understanding is that the jQuery .css() will add browser prefixes automatically
"-moz-transform":"translate(-50%, 0)",
"-ms-transform":"translate(-50%, 0)",
"-webkit-transform":"translate(-50%, 0)",
*/
"transform":"translate(-50%, 0)",
"height":"25px",
"cssText", "padding-left:0 !important;"
});
I haven't tested this because I don't want to take the time to set up an example but I believe it will work. Give it a shot and let me know.
Third Update:
As the OP pointed out, the code in my second update has an error - the "cssText" should be followed with a ':' not a ','
Furthermore, in response to the OP additional comments, I have adjusted my solution to override the initial padding and apply all new (desired) styles. To do this, you will need to create a variable that contains all the styles you want to apply (this is because cssText will replace any existing 'style' tags):
var csstxt = $('.testTwo').css('cssText') + ';position:absolute;left:50%;transform:translate(-50%, 0);-moz-transform:translate(-50%, 0);-ms-transform:translate(-50%, 0);-webkit-transform:translate(-50%, 0);height:25px;padding-left:0 !important;';
As you can see, I had to re-include the Browser prefixes because we are no-longer handling the solution with .css() - Once you have the variable with your desired styles, you will want to run it through the following function:
$('.testTwo').css('cssText', csstxt);
This will now produce your desired results. Here is an updated Fiddle with everything I have touched on: https://jsfiddle.net/rockmandew/fhceb7dv/13/