My html page structure is like this
<div id="myPage">
<div class="input-group bootstrap-touchspin">
<input id="784069" class="form-control my-class touchspin" type="text" value="0" name="784069" default-field="True" style="display: block;">
</div>
</div>
I tried to fetch this element with css like this
#myPage .input-group .bootstrap-touchspin {
}
It has to be #myPage .input-group.bootstrap-touchspin because the space indicates the next class is a child of the previous. No space means both classes belong to the same element.
Targeting the <input> element
If you want to target the actual <input> element, you should use this CSS :
#myPage .bootstrap-touchspin .touchspin {
/* properties go here */
}
The following alternatives also all target the <input> element :
#myPage .bootstrap-touchspin input.my-class {
/* properties go here */
}
#myPage .bootstrap-touchspin input {
/* properties go here */
}
#myPage input.touchspin {
/* properties go here */
}
#myPage .my-class {
/* properties go here */
}
#784069 {
/* properties go here */
}
...
Targeting the <div> element
If you want to target the <div> element surrounding the <input> element, you should use this CSS :
#myPage .bootstrap-touchspin {
/* properties go here */
}
The following alternative should also work :
#myPage .input-group {
/* properties go here */
}
Notes :
There are many ways to combine different selectors, that each have their own meaning. For an overview, take a look at the W3Schools CSS Selector Reference.
In the latter case (targeting the <div> element), you could use #myPage .input-group.bootstrap-touchspin { ... } (without the space). However, you don't really need the extra .input-group class because #myPage .bootstrap-touchspin { ... } is already pretty specific. See this article for an introduction to CSS specificity.
Related
I have two sets of radio buttons that I want to style differently. One is in a table the other is in a div. The parent is in the table the children the div.
So it looks like this
<td class="lblcontainer">
<input type"radio" name="advSearch[puborpost]" value="Published">
<input type"radio" name="advSearch[puborpost]" value="Posted">
<div class="calChooser">
<input type"radio" name="cal[puborpost]" value="24 Hours">
<input type"radio" name="cal[puborpost]" value="1 Week">
</div>
</td>
My css looks like this
td.lblcontainer input[type="radio"]{
*css values*
}
div.calChooser input[type="radio"]{
*css values*
}
When I open my dev tools the td.lblcontainer is being applied to the div.calChooser for all my radio buttons inside my div.
What am I missing that prevents the radio buttons in div.calChooser from bubbling up and taking the styles for td.lblcontainer?
Rules that appear later in the code override earlier rules if both have the same specificity.
I presume you got td.lblcontainer input[type="radio"] defined later in your CSS file. Either put it above, or instead do
td.lblcontainer > input[type="radio"]{
*css values*
}
div.calChooser input[type="radio"]{
*css values*
}
Note the > selector only targets first-level children, therefore won't affect the input inside your div.
.lblcontainer input {
/* Style all inputs inside .lblcontainer, if you have any shared styles */
}
.lblcontainer > input {
/* Style inputs that are direct children of .lblcontainer */
}
.calChooser input {
/* Style inputs that are children of .calChooser */
}
use !important attribute in div.calChooser like
.calChooser input[type="radio"]{
property : value!important;
}
I search for all solutions but nothing help me.
my simple problem is to set a style for a link ( a Tag ) with a class:
<a class="logo"></a>
I don't want a general style for links or for active ones but for a selected Class.
Thank you.
I think you're looking for the CSS class selector.
To apply a style to just a single class you should prefix the class name with a dot (.) in your CSS selector.
In this particular case you would do it like this:
.logo {
/* Styles here */
}
You can also ensure that only link elements are affected by adding the element selector:
a.logo {
/* Styles here */
}
PS. The CSS id selector is # and it works in a similar manner.
There are three different ways to solute this. Since you do not want a global styling for a link this example will not be it:
a{
/* STYLE HERE */
}
Since you simply want to style a link with a surtain class use this example:
a.logo {
/* STYLE HERE */
}
or
logo {
/* STYLE HERE */
}
or
a[class="logo"] {
/* STYLE HERE */
}
The last example is a new way of making this happen, some very old browser wont understand this, so you better stick to the first or second example.
Use like this
<style>
a[class="logo"] {
background-color: yellow;
}
</style>
<a class="logo">test</a>
you can add style rules by targeting class :
a.logo { color: #aeaeae; }
I have the following code:
<div class = "badge">
<div class = "badge-header">
</div>
</div>
What's the proper way to style badge-header in css?
Is it
.badge .badge-header {
}
or
.badge-header {
}
also how do we structure our css names? How do we structure our divs and what selectors should we use for each above?
If you have a div inside a div, what is the naming convention that we should stick to in CSS?
Both
but the first will apply the style only when the "badge-header" is inside of a "badge"
in the second will apply for all "badge-header" elements.
See example: https://jsfiddle.net/6bvLtqLw/
CSS
.badge-header{
color:blue;
}
.badge .badge-header{
background-color: yellow;
}
HTML
<div class="badge">
<div class="badge-header">
inside
</div>
</div>
<div class="badge-header">
outside
</div>
Both work
.badge .badge-header {
}
above one applies style to those elements with class '.badge-header' AND are under elements with class '.badge'
.badge-header {
}
and the above one applies style to all the elements with class '.badge-header' regardless of element's position in DOM.
Both
but the first will apply the style only when the "badge-header" is inside of a "badge"
.badge .badge-header {
}
in the second will apply for all "badge-header" elements.
.badge-header {
}
The first variant obviously will only style .badge-header if used in the context of a .badge. The second will apply to all .badge-headerregardless of their context.
If you are certain .badge-header will never need to be used outside of .badge, you go with variant two as it is shorter and more concise.
If it might be useful to reuse the .badge-header in different context than only .badge, then use *both variants. Put all styles that all .badge-header have in common in .badge-header { ... }. Put the context-dependent styles in .badge .badge-header { ... }.
How do I hide this "Data tracking area" which is in the footer? This is the code. I'm on WordPress so I can't edit the CSS but add extra. I tried hiding it using the display:none; but did not work.
<div id="footer" data-tracking-area="footer">
I tried this code but did not work.
.data-tracking-area{
display:none;
}
You can add following css
#footer{
display:none;
}
You can use an attribute selector. Like this:
[data-tracking-area="footer"] {
display:none;
}
Attribute selectors are case-sensitive, and are written inside
brackets [].
There are seven different types of matches you can find with an
attribute selector, and the syntax is different for each. Each of the
more complex attribute selectors build on the syntax of the exact
match selector — they all start with the attribute name and end with
an equals sign followed by the attribute value(s), usually in quotes.
What goes between the attribute name and equals sign is what makes the
difference among the selectors.
[data-tracking-area] {
/* Attribute exists */
}
[data-tracking-area="footer"] {
/* Attribute has this exact value */
}
[data-tracking-area=*"footer"] {
/* Attribute value contains this value somewhere in it */
}
[data-tracking-area=~"footer""] {
/* Attribute has this value in a space-separated list somewhere */
}
[data-tracking-area=^"footer"] {
/* Attribute value starts with this */
}
[data-tracking-area=|"footer"] {
/*Attribute value starts with this in a dash-separated list */
}
[data-tracking-area=$"footer"] {
/* Attribute value ends with this */
}
Here a basic example:
[data-tracking-area="footer"]{
height: 50px;
background: green;
}
[data-tracking-area*="foo"]{
color: #fff;
text-align: center;
}
[data-tracking-area$="footer"]{
text-transform: uppercase;
padding-top: 10px;
}
<div id="footer" data-tracking-area="footer">select me by atrtibute selector</div>
You can use the one that best suits your needs.
Docs: https://css-tricks.com/almanac/selectors/a/attribute/
You can provide styling inline too. As below:
<div id="footer" data-tracking-area="footer" style="display:none;">
Try this, hope gonna work.
I have this div:
<div dir="ltr"></div>
That is generated automatically via imap_ function, and therefore I am not able to assign any style to it with the style="" tag.
My question is, how can I assign styles to the div above?
An attribute selector works well if you just want to style this specific element:
div[dir="ltr"] {
/* Styles */
}
Have you tried to use CSS for this?
div {
color: #cecece; /* change the color */
}
http://jsfiddle.net/afzaal_ahmad_zeeshan/wxft9/
[dir='ltr'] {
color: #cecece;
}
or with div - div[dir='ltr']
http://jsfiddle.net/aLvZk/
Try this:
CSS:
div[dir='ltr']
{
/*Styles*/
}
Fiddle