CSS of nested selector is not being applied to div - css

I utilised the BEM method and my <div> is showing the css from the Block and Modifier, but not the Element
i.e. the css for c-banner(block) and --warning(modifier) is appearing but not __icon(element).
I know that the color of the modifier is appearing because I tried changing it to another color and it appears on the UI.
Eg:
Currently:
&--warning {
color: #D9822B
}
Edited:
&--warning {
color: black
}
Once changed, the icon of --warning will show up with a black color on the UI.
However, the padding-right of __icon doesn't ever get applied.
c-banner {
/* Block CSS Properties */
&__icon {
padding-right: 12px;
&--warning { /* Used for warning purposes */
color: #D9822B;
}
&--primary { /* Used for general information */
color: #137CBD;
}
&--success { /* Used for verified access */
color: #0F9960;
}
&--danger { /* Used as a hard stop */
color: #DB3737;
}
}
}
I'm genuinely perplexed as to why the padding-right of __icon does not get applied but the color of --warning is

All you are missing is:
.c-banner ..... the dot before the classname
Also, for padding to work they have to be inside --warning because you are chaining to form the full selector and there is no selector that ends with __icon
You can style material-icons if you want to affect multiple:
.c-banner {
.material-icons { padding-right: 12px; }
/* can also do [class*="__icon"] but may be less predictable */
&__icon {
/* rest of the scss */
}
}

Related

Polymer: --paper-item-selected-weight not working

I want to apply a background color but not bold the paper-item when its selected. I notice the weight property does not do anything ...
paper-item {
--paper-item-selected-weight: normal; /* its still bold */
--paper-item-selected: {
background: #3f9c35; /* no issues here */
}
}
The HTML
<paper-menu selected="0">
<paper-item>TEST</paper-item>
The same happens if I use paper-icon-item

Proper CSS syntax for assigning style attributes to a pseudo-class for multiple classes'?

I am trying to set the color (font-color) attribute for the placholder pseudo class for a multiple classes of inputs.
(So I want all inputs with class .red-va or .blue-va to have placeholder text of a given color)
I can (and have) done this:
.red-va::-webkit-input-placeholder {
color: white;
}
.red-va:-moz-placeholder { /* Firefox 18- */
color: white;
}
.red-va::-moz-placeholder { /* Firefox 19+ */
color: white;
}
.red-va:-ms-input-placeholder {
color: white;
}
.blue-va::-webkit-input-placeholder {
color: white;
}
.blue-va:-moz-placeholder { /* Firefox 18- */
color: white;
}
.blue-va::-moz-placeholder { /* Firefox 19+ */
color: white;
}
.blue-va:-ms-input-placeholder {
color: white;
}
Basically two sets of CSS for each input class, with browser support requiring four different approaches for each.
Is there a more elegant / streamlined way of doing this?
Unfortunately, without making use of a preprocessor (since this is CSS), the best you can do is to group each set of vendor prefixes for both .red-va and .blue-va, but not all of them into a single ruleset:
.red-va::-webkit-input-placeholder, .blue-va::-webkit-input-placeholder {
color: white;
}
.red-va:-moz-placeholder, .blue-va:-moz-placeholder { /* Firefox 18- */
color: white;
}
.red-va::-moz-placeholder, .blue-va::-moz-placeholder { /* Firefox 19+ */
color: white;
}
.red-va:-ms-input-placeholder, .blue-va:-ms-input-placeholder {
color: white;
}
Or if you can afford to change the markup you can go further by adding a common class to both .red-va and .blue-va so you don't have to duplicate your selectors for both — effectively halving the CSS that you currently have.
The reason you can't group them all into one ruleset is covered here. In short, it's because browsers are required to drop an entire ruleset if they don't recognize any part of the selector list, which will be caused by the vendor prefixes (and in the case of Firefox, also by the fact that versions older than 19 don't recognize the pseudo-element syntax).
Thankfully, prefixed pseudos will soon be a thing of the past.

CSS Changing Logo Hover Color

I've managed to change the Logo the way I want it using Logo using CSS but I'm struggling to figure out how to change the hover color of it.
I want to change the TEST color on hover from blue to something else
http://test.peterstavrou.com/
At the moment my CSS code is
header#top #logo {
letter-spacing: 2px;
font-size: 35px;
}
your Logo-Text is a link so you should use css-syntax for styling links:
a#logo:link { color: #fff; } /* a Link that has not been clicked yet */
a#logo:visited { color: #fff; } /* a link that has been clicked before */
a#logo:hover { color: #ff0; } /* a link on hover/rollover */
a#logo:active { color: #ff0; } /* a link that is just clicked */
Just do something like:
Solutions 1 Find the logo hover css and change the color property value to whatever color you want
color: red!important; /* change the property value to the color you want */
Solution 2 Create another hover CSS and force a change as shown below, if the above doesn't work
#logo:hover {
color: red!important;
}
Note: Make sure the code above is at the very bottom of your css file. that way, it will override the previous hover property defined, even if it has important
Add this below the code for header#top #logo { ... } that your sample is showing in the CSS.
header#top #logo:hover
{
color:red;
}

Does wkhtmltopdf respect css font color?

I'm using wkhtmltopdf to generate a pdf of a page but it doesn't display any of the fonts in the correct colour, they all are presented black.
The colour is defined as you'd expect:
.panel-dashboard p.stat {
color: #bed000;
}
and displays correctly when viewed in the browser.
I'm calling it as
wkhtmltopdf path/to/page filename
Does wkhtmltopdf just not render font colours correctly? I've not been able to find any issues relating to this.
Appears this was a problem with wkhtmltopdf 0.9.9, 0.11 renders css font colors correctly.
Using version 0.12.2.4 specifying a white font inside the CSS (inside a grey background) worked, but a colored font (red, orange) did not:
.header { background-color: #888; color: #fff; } /* works */
.orange { color: f80; } /* doesn't work in wkhtmltopdf */
Using a style directly on the div did work:
<div style="color:#f60;">My Orange Text</div>
It may be because there is no background?? I don't know.
So if you try CSS and it fails this may work...
You are probably using this proposed CSS which has defined #media print { * { color: black !important; } }
Using version 0.12.6 here. Results look like following:
[pandoc.css] #media print { * { color: black !important; } }
[my.css] TODO2 { color: #700 !important; }
TODO3 { color: #700; }
[file.md] <TODO1 style="color: #700 !important;">black</TODO1>
<TODO1 style="color: #700;"> black</TODO1>
<TODO2> red</TODO2>
<TODO3> black</TODO3>
and
[pandoc.css] #media print { * { color: black; /* not important */ } }
/* or not using proposed pandoc.css at all */
[my.css] TODO2 { color: #700 !important; }
TODO3 { color: #700; }
[file.md] <TODO1 style="color: #700 !important;">red</TODO1>
<TODO1 style="color: #700;"> red</TODO1>
<TODO2> red</TODO2>
<TODO3> red</TODO3>

fail to change placeholder color with Bootstrap 3

Two questions:
I am trying to make the placeholder text white. But it doesn't work. I am using Bootstrap 3. JSFiddle demo
Another question is how do I change placeholder color not globally. That is, I have multiple fields, I want only one field to have white placeholder, all the others remain in default color.
html:
<form id="search-form" class="navbar-form navbar-left" role="search">
<div class="">
<div class="right-inner-addon"> <i class="icon-search search-submit"></i>
<input type="search" class="form-control" placeholder="search" />
</div>
</div>
</form>
css:
.right-inner-addon {
position: relative;
}
.right-inner-addon input {
padding-right: 30px;
background-color:#303030;
font-size: 13px;
color:white;
}
.right-inner-addon i {
position: absolute;
right: 0px;
padding: 10px 12px;
/* pointer-events: none; */
cursor: pointer;
color:white;
}
/* do not group these rules*/
::-webkit-input-placeholder { color: white; }
FF 4-18
:-moz-placeholder { color: white; }
FF 19+
::-moz-placeholder { color: white; }
IE 10+
:-ms-input-placeholder { color: white; }
Assign the placeholder to a class selector like this:
.form-control::-webkit-input-placeholder { color: white; } /* WebKit, Blink, Edge */
.form-control:-moz-placeholder { color: white; } /* Mozilla Firefox 4 to 18 */
.form-control::-moz-placeholder { color: white; } /* Mozilla Firefox 19+ */
.form-control:-ms-input-placeholder { color: white; } /* Internet Explorer 10-11 */
.form-control::-ms-input-placeholder { color: white; } /* Microsoft Edge */
It will work then since a stronger selector was probably overriding your global. I'm on a tablet so i cant inspect and confirm which stronger selector it was :) But it does work I tried it in your fiddle.
This also answers your second question. By assigning it to a class or id and giving an input only that class you can control what inputs to style.
There was an issue posted here about this: https://github.com/twbs/bootstrap/issues/14107
The issue was solved by this commit: https://github.com/twbs/bootstrap/commit/bd292ca3b89da982abf34473318c77ace3417fb5
The solution therefore is to override it back to #999 and not white as suggested (and also overriding all bootstraps styles, not just for webkit-styles):
.form-control::-moz-placeholder {
color: #999;
}
.form-control:-ms-input-placeholder {
color: #999;
}
.form-control::-webkit-input-placeholder {
color: #999;
}
A Possible Gotcha
Recommended Sanity Check - Make sure to add the form-control class to your inputs.
If you have bootstrap css loaded on your page, but your inputs don't have the
class="form-control" then placeholder CSS selector won't apply to them.
Example markup from the docs:
I know this didn't apply to the OP's markup but as I missed this at first and spent a little bit of effort trying to debug it, I'm posting this answer to help others.
I'm using Bootstrap 4 and Dennis Puzak's solution does not work for me.
The next solution works for me
.form-control::placeholder { color: white;} /* Chrome, Firefox, Opera*/
:-ms-input-placeholder.form-control { color: white; } /* Internet Explorer*/
.form-control::-ms-input-placeholder { color: white; } /* Microsoft Edge*/
Bootstrap has 3 lines of CSS, within your bootstrap.css generated file that control the placeholder text color:
.form-control::-moz-placeholder {
color: #999999;
opacity: 1;
}
.form-control:-ms-input-placeholder {
color: #999999;
}
.form-control::-webkit-input-placeholder {
color: #999999;
}
Now if you add this to your own CSS file it won't override bootstrap's because it is less specific. So assmuning your form inside a then add that to your CSS:
form .form-control::-moz-placeholder {
color: #fff;
opacity: 1;
}
form .form-control:-ms-input-placeholder {
color: #fff;
}
form .form-control::-webkit-input-placeholder {
color: #fff;
}
Voila that will override bootstrap's CSS.
The others did not work in my case (Bootstrap 4). Here is the solution I used.
html .form-control::-webkit-input-placeholder { color:white; }
html .form-control:-moz-placeholder { color:white; }
html .form-control::-moz-placeholder { color:white; }
html .form-control:-ms-input-placeholder { color:white; }
If we use a stronger selector (html first), we don't need to use the hacky value !important.
This overrides bootstraps CSS as we use a higher level of specificity to target .form-control elements (html first instead of .form-control first).
I think qwertzman is on the right track for the best solution to this.
If you only wanted to style a specific placeholder, then his answer still holds true.
But if you want to override the colour of all placeholders, (which is more probable) and if you are already compiling your own custom Bootstrap LESS, the answer is even simpler!
Override this LESS variable:
#input-color-placeholder
Boostrap Placeholder Mixin:
#mixin placeholder($color: $input-color-placeholder) {
// Firefox
&::-moz-placeholder {
color: $color;
opacity: 1; // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526
}
&:-ms-input-placeholder { color: $color; } // Internet Explorer 10+
&::-webkit-input-placeholder { color: $color; } // Safari and Chrome
}
now call it:
#include placeholder($white);
You should check out this answer : Change an HTML5 input's placeholder color with CSS
Work on most browser, the solution in this thread is not working on FF 30+ for example
With LESS the actual mixin is in vendor-prefixes.less
.placeholder(#color: #input-color-placeholder) {
...
}
This mixin is called in forms.less on line 133:
.placeholder();
Your solution in LESS is:
.placeholder(#fff);
Imho the best way to go. Just use Winless or a composer compiler like Gulp/Grunt works, too and even better/faster.

Resources