Category Archives: Bootstrap Questions And Answers

Bootstrap Remove padding from column


Bootstrap Remove padding from column : Bootstrap by default adds some padding in columns and other elements.
There are many ways to remove padding from column in bootstrap. Here in this tutorial we are going to create custom class to remove padding from columns. We will explain this with example and demo.


Bootstrap Remove padding from column Example

You can remove padding from column in bootstrap using the following css-

Bootstrap Remove padding from column : Example


Try it »

If you run the above example it will produce output something like this –

Remove padding from column in bootstrap Example

Tip : Always try to add the(custom css) like this in a separate file which is good practice.

Pass Data to Bootstrap Modal


Pass Data to Bootstrap Modal : Some times we need to pass dynamic data to bootstrap modal. There are many ways to pass data in bootstrap modal. Here in this tutorial we are going to explain how you can pass dynamic data in bootstrap modal. We will explain each method with example and demo.


Pass Data to Bootstrap Modal

Here is an example to pass the data in bootstrap modal –

Html Part

Here is html part which contains the modal structure-

Pass Data to Bootstrap Modal JavaScript Example

  




The above example contains the Modal and link to launch the modal.

Now let us create the JavaScript Part For this –

JavaScript Part

JavaScript Part Contains the following part –



Pass Data to Bootstrap Modal JavaScript Example & Demo


Try it »

Here in this example we have passed data to bootstrap modal in myHeading variable which will be added in the content body element. $(“#modal-body”).html(myHeading + x); will add the data in modal body element which has id “modal-body”. Thus you can pass any data you want in the modal body. You can also use ajax to pull the data from server and pass into the bootstrap modal.

If you run the above example it will produce the output something like this –

Pass Data to Bootstrap Modal

Launch Bootstrap Modal on page load


Launch Bootstrap Modal on page load – Sometimes we need to open bootstrap modal on page load for some reasons. We can trigger the modal event on page load using the javascript. Here in this tutorial we are going to explain how you can launch bootstrap modal when page is loaded. We will explain this with demo.


Launch Bootstrap Modal on page load | Show After Page Load | Open After few Seconds | jQuery | Example

You can launch modal on page load simply as below –

Launch Bootstrap Modal on page load: JavaScript Example

  



Try it »

The above method will be called on window load as soon as it is triggered modal is launched. If you run the above example it will show modal on page load-

Launch Bootstrap Modal on page load

Bootstrap modal on page load once | JavaScript

You can load modal only one time after page load using the jQuery cookie. Here is an example –

Launch Bootstrap Modal on page load: JavaScript Example

 
            

Open Modal Automatically after 2 Seconds

Sometimes we need to trigger modal automatically after 2 seconds, 3 seconds or few second of page load. You can do it easily using the jQuery simply as below-

Bootstrap Open Modal After few seconds of page Load Example:

Try it »

Bind function with Bootstrap Modal Close


Bind function with Bootstrap Modal Close : Sometimes we need to bind function with Modal close event. $(‘#modal’).on(); is used to bind a function with the close event. This method can be used to trigger the function when the close event occurs. Here in this tutorial we are going to explain how you can call function on modal close event. We will explain this with online demo.


Bind function with Bootstrap Modal Close

You can call function on bootstrap modal close event as below –

Bootstrap 3 : Call Function On Modal Close Event

If you are using the bootstrap 3 you can call a function on close event as below –

Bind function with Bootstrap Modal Close : Example


Try it »

If you run the above example and click on the modal popup to close it trigger the alert on close event.

Bind function with Bootstrap Modal Close : Example

Bootstrap 2.3.3 : Call Function On Modal Close Event

If you are using the bootstrap 2.3.3 you can call a function on close event as below –

Call function on Bootstrap Modal Close Button Click : Example


This will work same as the above example .

Bootstrap change icon size and color


Bootstrap change icon size and color : Sometimes we need to change the color and size of icons in twitter bootstrap. You can change the icon color by overriding the default css or you can add your own css. Here in this tutorial we are going to explain how to change the icon color and size in twitter bootstrap with example and demo.


Bootstrap change icon size and color

Here is an example to change the default icon color and size to the custom color as below-

Bootstrap change icon default color:

.mycolor{
color:blue !important;
}

Try it »

Now add this css to the icon. Thus you can add your own color to the bootstrap icons.

If you run the above example it produce the following output-

Bootstrap change icon color

Note : Please do not modify the core css because it will not work in future if you upgrade the bootstrap to latest version.

More Examples

Let’s have look over more example and demo here.

Bootstrap change icon size

Here is an example to change the default icon size to the customized size –

Bootstrap change icon size:

.mysize{
color:blue !important;
font-size:100px !important;
}

Try it »

Now add this css to the icon. This will change the icon size to the given size.

If you run the above example it will produce output like this –

Bootstrap change icon size

Align center column using Twitter Bootstrap


Align center column using Twitter Bootstrap – Sometimes we need a column to align center in twitter bootstrap. There are many ways to align center in twitter bootstrap. In this tutorial we are going to explain the different approaches to align center column in twitter bootstrap. We will explain this with example and demo.


Align center column using Twitter Bootstrap

You can align center in bootstrap column as –

Bootstarp 3.1.1 And Above

If you are using bootstrap 3.1.1 and above version you can directly use the class class=”center-block” to align the column content. Here is an example and demo.

Align center column using Twitter Bootstrap:

1 Column center block
2 Column center block
2 Column center block

Try it »

If you run the above example it will give the following result –

Align center column using Twitter Bootstrap

More About Column Align Center

Bootstrap align center using offsets

You can also align center the columns using the offsets in bootstrap which will work with all versions-

Bootstrap align center using offsets:

I m centered Aligned.

Try it »

If you run the above example it will produce the following output-

Align center column using Twitter Bootstrap

Bootstrap align center using custom css

You can also create your own css to align center the column content as below –

Bootstrap align center using offsets:

.custom-center{
text-align:center;
display: inline-block
}

If you want to create your custom css you can create css as above and add this to the div to align column contents in bootstrap.

Tip : Always try to use bootstrap’s default classes to align center the contents.

Bootstrap change button color


Bootstrap change button color: We sometimes need to customize the bootstrap colors button color or sometimes we need to change some other styles. All these can be done very easily if you go to the thing in proper manner. For this override the bootstrap’s default classes css. Here we are going to explain how to override the bootstrap’s default classes to change the style as per our need.


Bootstrap change button color

Here is a simple example of changing the background color.

Bootstrap change button color

.btn-danger { border-color: #E85757; background-color: #FDA2A2; color:#FFF;}

.btn-danger:hover { border-color: #FC0D0D; background-color: #D20606; }

Add this class to change the behavior of danger button.

Bootstrap change icon color using css


Bootstrap change icon color using css: You can change the icon color in bootstrap by adding the custom css class. Icon adopts the color of it’s parent element. Here we are going to change the default color of icon by our own class.


Bootstrap change icon color using css

Here is an example of change background color-

Bootstrap change icon color using style css:


Or you can add the class as below

Bootstrap change icon color using css:



Bootstrap color picker


Bootstrap color picker Example : You can integrate the Bootstrap color picker plugin as below.


Bootstrap color picker Example

You need following js and css for bootstrap color picker.
We have loaded it from the cdn as below :





Try it »


Output
Bootstrap color picker

Bootstrap color picker