Tag Archives: buttons

Twitter Bootstrap Dropdown Button

Dropdown Button – Twitter Bootstrap

Hey everyone,

Just a quick post on how to create a dropdown button using Twitter Bootstrap. It’s pretty straight forward, once you’ve included all your CSS etc just add the following code:

Once you save that you should see something similar to the image below:

Twitter Bootstrap Dropdown Button

A standard twitter bootstrap dropdown button.

Change list item text alignment

To change the text alignment of this list items, all you need to do is adjust the text-align style assigned to the wrapper div.

Change dropdown button color

Once again, this is fairly simple, all you need to do is switch the button type. For instance, if you were after an orange button, you can swap btn-success with btn-warning. A list of the default styles is available on the Twitter Bootstrap site.

Let me know if you have any issues.

Modal Popup – Twitter Bootstrap

Just a quick post on how to create a modal popup using twitter bootstrap:

Step #1:

Add the following to a page element such as a link or button in order to open the modal:



Add Image

Step #2:
Create a content div i.e.

And that’s all there is to it, just make sure you’ve included the bootstrap-modal.js file.

Modal Popup - Twitter Bootstrap

Modal Popup - Twitter Bootstrap

Open Twitter Bootstrap Modal Popup on Page Load:
In order to open the modal dialog on page load simply add the following JavaScript:

You can also close the modal popup manually by using the following JavaScript:

Adjust Modal Width:
In order to adjust the modal width you have two options, Javascript or CSS. You can use the following JavaScript mentioned on GitHub:

Or this CSS from StackOverflow:

body .modal-admin {
    //new custom width
    width: 750px;
    //must be half of the width, minus scrollbar on the left (30px)
    margin: -345px 0 0 -375px;

Show modal when the user scrolls past certain div
I’ve received another request on how to show the modal when a user scrolls to a certain div. The following should work, but please let me know if you have any issues.

/* Wait for document to load */


//Retrieve scroll distance from top
var top = $(window).scrollTop();

//Retrieve the divs distance from top of page
var div_distance = $('my_div').offset().top;

//Use this if you want a bit of a variable distance, for instance if they scroll 150 pixels past the div
var buffer_distance = 150;

//Check if scrolled past div
if(top >= div_distance && top <= (div_distance + buffer_distance)){

//Show modal - you may want to add checks etc to see if it's already show

} else {

//Hide the modal, have scrolled past - you may want to add some checks to see if it's already hidden etc

Create Button which does not Submit – Ruby on Rails

Just another quick post – how to create a button which does not submit a form when it’s clicked:

<%= submit_tag 'My Button',  :type => 'button', :onclick => 'alert('Button not Submitted - Hopefully!!!!'), :class => "my_class" %>

Let me know if you have any problems.

Custom Form Submit Button Text – Ruby on Rails

Just a quick post on how to set the text of a form submit button. By default, the tag will appear as follows:

<%= f.submit %>

In order to change the text all you have to do is the following, where ‘Set Location’ is your new text:

<%= f.submit 'Set Location' %>

Good Luck!

Placing Multiple Button_To on the Same Line – Ruby on Rails

This is a problem that had me confused for an embarrassingly long time. Rails wraps button_to elements within a form and a div. Unfortunately this will take up 100% of the available width. Thankfully the solution is pretty straight forward – simply wrap buttons in a div and float them left like so:

<%= f.submit 'Place Order', :class => 'button'%>
<%= button_to 'Cancel', :root, :class => 'button' %>

A wrapper div isn’t strictly necessary however I usually add one just to be safe. While this will probably give a bunch of designers another reason to hate developers, I find that wrapping floated elements seems to save a lot of headaches when making changes down the track.

Using the code above you may also find that the divs aren’t filling as expected, simply add a div with a ‘clear:both’ style to the bottom of the wrapper:

<%= f.submit 'Place Order', :class => 'button'%>
<%= button_to 'Cancel', :root, :class => 'button' %>

Hopefully that doesn’t take anywhere near as long for you guys to figure out as it did me, time for a coffee break I think. Good luck!