Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge two button elements as one

I was wondering how to go about making a button that looks like a normal button, but the right side does X and the right side does Y.

For example, when I click the left side of this button it runs one form. I click the right side and it runs another form. The button needs to look like a normal button, so the user would only see one button.

like image 230
Toby Mellor Avatar asked Dec 05 '22 06:12

Toby Mellor


2 Answers

This sounds like horrible UI. The user should be able to see the difference between the buttons. You should create two buttons in a 'pill' formation as such:

split button

By applying a negative margin to the second button:

#second-button {
    margin-left: -4px;
}

JSFiddle

If you still want to, you can remove the borders to make them merge in to one:

JSFiddle

like image 151
SomeKittens Avatar answered Dec 09 '22 15:12

SomeKittens


Something like this would work:

<button>
    <span class="left-part">Button</span>
    <span class="right-part">value</span>
</button>

Then you can bind different event listeners to the left and right spans.

Demo: http://jsfiddle.net/2L8uN/ (and version with styled span padding's)

like image 28
dfsq Avatar answered Dec 09 '22 15:12

dfsq