Apply bootstrap form styling to div elements without changing class - html

I'm building a screen with many form elements using the convention below; it saves me from adding class='...' to every input, button, and select box.
.formDiv button {
font-family: verdana;
font-size: 10px;
border: 1px solid #999;
border-radius:3px;
}
.formDiv input {
font-family: verdana;
border: 1px solid #999;
width: 110px;
}
Now I want to use bootstrap; I've got everything configured; confirmed it's working.
Is it possible to apply bootstrap3 styling without adding class='some-bs-style' to each form element? Ideally, I want to do something like this:
.myDiv input {
//use bs3 input styling
}
.myDiv select {
//use bs3 select styling
}
I see bootstrap uses form-control, so I tried setting that on the parent div using:
<div id='#formdiv' class='form-control'>
..but it did not work; I suck at css, so no surprise there.

Copy the rules from form-control and just apply the rules to input and select if you want to use it automatically for your formdiv class:
.formdiv input, select {
RULES FROM FORM CONTROL
}
DEMO HERE
Updated DEMO + CSS is here: http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.css
Copying is necessary because you cannot inherit rules from other classes. Therefore if you want to avoid applying form-control style to each input and select, you have to use approach above. But this is still faster than putting "form-control" to each input in each form.

Related

remove all inherited css properties

I have a popup that will be added to websites via javascript. I have no clue on what sort of styles will be applied on these websites.
Example website has the current styles added:
h3 {
color: blue;
border: 5px solid red;
font-size: 24px;
}
My Popup which is added to the body of the website has:
PopupText = styled.h3`
font-size: 16px;
color: black;
`;
This means that font size and color are what i've declared but the border will be added regardless, is there any way to remove the added extra css properties, or to protect from additional styling added by the website?
To sum up, I want my popup to look the same, no matter where it is added. As of right now, when i add it to a website it changes depending on what styling is on the website
You can use all attribute like this :
.class {
all: unset;
}
Check it here
I think you need use iframe tag for wrap
You can use the :not() selector to achieve that: If your popup element has a class (which is probably the case) you can modify your regular css rule for h3 as follows:
*:not(.yourpopupclass) h3 {
color: blue;
border: 5px solid red;
font-size: 24px;
}
This will affect any h3 element that is a child element of anything (i.e. also of body), except if it's a child of an element that has class .yourpopupclass (i.e. is inside your popup).
The same woud be possible with an ID if the popup has no class, but an ID.

Over right styles of jQuery CSS framework

So I have an app that uses jQuery for certain parts. Such as the Autocomplete and Calendar Date Picker. I'm introducing a new style called .more-compact that will implement a smaller version of the app. This class is currently sitting in the div encompassing the entire app. This class works in reducing the heights, widths, and font sizes of almost everything. But when I try to do it for any jQuery elements, it won't work. This is how a typical style on the css doc looks:
.more-compact ul li {
font-size: 12px;
}
But for the jQuery autocomplete element, it will only work if I remove the ".more-complete" part. I don't want this though because this is part of a single stylesheet, and I only want the font to be that size when the .more-compact version is being used.
Any ideas what is causing this nesting not to work? Is the jQuery stylesheet over righting my own? The for this stylesheet is the lowest on the doc, so it should take priority.
Try use !important
.more-compact ul li {
font-size: 12px !important;
}
But try using more specific rules. By indicating one or more elements before the element you're selecting, the rule becomes more specific and gets higher priority
HTML
<div id="test">
<span>Text</span>
</div>
CSS
div#test span { color: green; }
div span { color: blue; }
span { color: red; }

Targeting something which has the same class as something else with css

I'd like to target a button which seems to have the same class as another button. Is there a way to differenciate using css when I can't change the html?
On this page the submit button has disappeared but I think it's because I've hidden a button which shares the same class here
Html:
<button type="submit" class="btn button ur-submit-
button">
<span></span>Submit</button>
I could see common class .btn having following properties:
.btn.btn {
color: transparent! important;
background: transparent! important;
border: none! important;
}
Try adding your class selector which is .ur-submit-button to override hidden property for your class, by adding the following CSS:
button.btn.button.ur-submit-button {
color: initial !important;
/* background: initial !important; */
/* border: initial !important; */
}
It will display the button and then you can further modify its look and feel using same selector.
Although usage of !important is not a good practice, but it seems to be already used by plugin.
I agree with the suggestion by Travis Acton to identify a parent on your create-account page that is different from the homepage. It looks like the form on the create-account page has the class register, which doesn't appear to be used on the homepage. I would try this:
.register .btn.ur-submit-button {
color: black;
}
If you're new to CSS, "parent" just means an HTML element that contains the element you're trying to target.

Inside div css settings

I created a div with "commonDiv" id (example), then is create multiple divs inside it, div, div in divs etc. All divs contains button(s). I want to add a common style for the buttons. I'd like to add a css only one settings for it.
I tried the following but it's not worked:
div#commonDiv .button{
background-color: #4CAF50;
border: none;
color: white;
}
What's the right way?
Well the best way is mentioning class for all of your <div>s and then adding style in the CSS code using your class.
.your_class_name {write any style you want for all of them !}
Try it this way:
div#commonDiv button{
background-color: #4CAF50;
border: none;
color: white;
}
I removed the period before .button.
The rules you declared didn't match the <button> tag but any element that has class "button"...
If it doesn't solve your issue feel free to leave a comment.
You can see a very good document about CSS selectors here. And if your buttons have not any class may be this code fix your problem:
div#commonDiv button{
...
}
I figured out the solution which is the following: div#commonDiv input[type=button]

Input boxes with different styles on the same page

I have the following style for an input box
input[type="text"] {
height:16px ;
font-size:14 ;
border-radius: 5px ;
}
What I want to do is have this style on most of the inputs but I want to make a class of input so I can add background color, etc. How can I do this in the syle sheet?
Use classes
Define a class with the different style
input[type="text"].different {
background-color:red;
}
and apply it to the input element in the html
<input type="text" class="different" />
This input will have all the properties of the generic rule input[type="text"] and then apply all the properties of input[type="text"].different class.
The input[type="text"].different is more important so in case of overlapping properties the ones in the .different class will prevail.
Read https://developer.mozilla.org/en-US/docs/CSS/Class_selectors and https://developer.mozilla.org/en-US/docs/CSS/Specificity
input[type="text"].yellow {
background-color: yellow;
}