So, I'm using display: table-cell
to put two buttons next to each other so that if text from one overflows to the next line, both buttons are the same height. I have border-collapse: separate
and am using border-spacing
to put space between them. It works just fine if I'm using something like <div class="button">
, but as soon as I use the <button>
element, the middle space disappears.
JSFiddle: http://jsfiddle.net/uASbb/
Now, using the <div>
is fine for now (if not semantically as accurate), so I'm mostly just curious if anyone knows what exactly is going on here.
Note: I've also noticed some (different) weird behavior with using <input>
elements in this same situation: http://jsfiddle.net/G5SFX/1/
Is display: table-cell
just not supported in these instances? Is this a bug?
Thanks!
EDIT: It seems like you just can't apply a display: table-cell
to a button; it just defaults back to inline-block
. See this screenshot from Chrome WebInspector:
Now the questions remain: Is this intentional? Is it the specification or is it just the browser? Can we get it changed?
Inserting the
button
element into adiv
is a good solution (in your place I would have choose it, too), but if you want to display bothbutton
elements side by side with space in between without the help from adiv
you can try this for your.item
class:Width
is reduced to46%
to allow amargin
of1%
around everybutton
element. You have a space between them now, and also if you resize the window the secondbutton
element won't fall under the first one.Example: http://jsfiddle.net/codenighter/H7TZU/
Hope it helps.
EDIT: It seems that
border-spacing
(in fact none ofblock
styling is working) doesn't work withbutton
orinput
. But it does working with other inline elements likespan
,h1
orb
. So, forinput
andbutton
thedisplay: table-cell
property can't be properly applied (I've changed thewidth
value forbutton
andinput
and it showed, while forspan
andb
thewidth
remained actually at 50%).Examples: http://jsfiddle.net/codenighter/HrTZS/