Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I customize twitter bootstrap's various input sizes without using !important?

Bootstrap's input sizes only expand by width, whereas the buttons expand by both height and font size. (see pic) I'm trying to customize the inputs to expand by height and font size as well. (Note: they're fixing this for the next version, but I'm too impatient to wait)

enter image description here

So far I can only achieve this by using the !important hack to override the input css. I want to avoid using !important at all costs, because it is awful practice.

Currently, this is the code I have for expanding the height of .input-large. It does not work when I remove !important. I assume this is because inputs are given higher priority than classes (which I find absolutely silly, but correct me if I'm wrong).

.input-large {
width: 210px;
height: 44px !important;
margin-bottom: 10px !important;
line-height: 30px !important;
padding: 11px 19px !important;
font-size: 17.5px !important;
}

Is there any way I can achieve this without removing the default input styling and not declaring !important?

Here's a fiddle: http://jsfiddle.net/xryQK/

like image 251
Michelle Avatar asked Dec 24 '12 14:12

Michelle


People also ask

What is twitter bootstrap used for?

Twitter Bootstrap is a front end framework to develop web apps and sites fast. In modern web development, there are several components which are required in almost all web projects. Bootstrap provides you with all those basic modules - Grid, Typography, Tables, Forms, Buttons, and Responsiveness.

Is bootstrap the same as twitter bootstrap?

There's no difference. Twitter Bootstrap was the official name for version 1.0 (Twitter Bootstrap). Later the name has been shortened.

How do I get Bootstrap CSS?

In order to use Bootstrap CSS, you need to integrate it into your development environment. To do that, you simply need to create a folder on your computer. In that folder, save your compiled CSS and JS files and a new HTML file where you'll load Bootstrap.


3 Answers

Instead of using !important, you can use an attribute selector which will override the default as it will be more specific than simply using a class. Not good with specificity concept? Refer this article.

For calculating the specificity of your selectors, you can use this website.

[1] Using class[attr=class]

.input-large[class="input-large"] {
    width: 400px;
}

OR

[2] Using tag[attr=class]

input[class="input-large"] {
    width: 400px;
}

And using !important is not an awful practice if you use it in the right place.


Note that above selectors, [1] will make all elements width to 400px having a class of input-large and in case of selector [2], it will set width to 400px for all input elements having class of input-large, so if you want, you can call multiple classes i.e .class.class on input tag and use the selector below..

.input-large.input-large-altered {
    width: 400px;
}

So this will select any element having both of these classes set, if you want to be more specific, and want to set only for input type="text" than you can always write even a more specific selector like

input[type="text"].input-large.input-large-altered {
   width: 400px;
}

So the above one will only target to input element whose type attribute is holding a value of text AND having both the classes i.e .input-large .input-large-altered

Demo

Demo 2

Demo 3 (Multiple classes)

like image 165
Mr. Alien Avatar answered Oct 16 '22 11:10

Mr. Alien


AFAIK you just put your own customized css after the bootstrap's

example:

... Some codes here ...

<link type="text/css" rel="stylesheet" href="bootstrap.css">
<style>
.input-large {
    width: 210px;
    height: 44px;
    margin-bottom: 10px;
    line-height: 30px;
    padding: 11px 19px;
    font-size: 17.5px;
}
</style>

... another code ...

Sorry, i forgot to delete the !important The !important is not needed

like image 6
gamehelp16 Avatar answered Oct 16 '22 11:10

gamehelp16


If you're working off of the bootstrap .less files

an easy solution would be to add an extra entry like:

.form-fatter {
  // Set font for forms
  label,
  input,
  button,
  select,
  textarea {
    // Increase the default with 20%
    #font > .shorthand(@baseFontSize*1.2,normal,@baseLineHeight*1.2); 
  }
}

in your html

<form class="form-horizontal form-fatter">
...
</form>
like image 1
Vincent Theeten Avatar answered Oct 16 '22 10:10

Vincent Theeten