Is it possible to make a JButton
take exactly the size of its text? Since by default, a JButton
will have a small amount of padding (both horizontal and vertical) around its text. I would like to remove that padding.
Making Divi Buttons the Same Size Normally the Call-to-Action (CTA) buttons in the Divi Theme adjust in size to fit the text they contain. If you'd prefer to have a standard button width throughout your site, here's how to do it. Setting the Minimum Button Width using CSS
Is there a way of forcing the buttons to all be the same size, regardless of the text label? yep. Basically, if you want them the same size, you have to give the same width. First, in your html put the items in a list, and put the list inside a division (for this example I’ll call the div “navigation”)
To have a standard button width throughout your site, you can use the following CSS:.et_pb_button { min-width: 180px; text-align :center; } Should you wish to apply it only to certain Divi Builder modules, you can give the module a CSS class (in the module settings). Then you can set the CSS as follows:
Just replace your-css-class with the CSS class you specify in the module settings. This tip actually works by setting a minimum size on the buttons, so that if you do have any buttons longer than the standard width, they'll still display correctly.
Clear out the margins in the button with setMargin
.
Removing the border has the side-effect of removing the border. If you only want to clear out the margins, use the setMargin
method to set the margins all to zero.
button.setMargin(new Insets(0,0,0,0));
JButton
has a border by default, you can remove it:
button.setBorder(null);
If you want to keep the border, reduce the margin (see Eugenes answer)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With