ngClass and print media query not working together - css

I am making an angular component to make a bunch of qr codes and print them. I have a component just for the qr code and want to make it possible to delete a qr code from the list and undo-delete a previously deleted code. I Before adding the undo-delete functionality, everything was working well because I was just removing that particular component from the list. However, now I don't want to completely remove it, I just want to fade it out until print time. I am using ngClass on my div and the "deleted" class does work. Anything that has class noPrint just gets display:none, however when I try to use ngClass to dynamically give a code noPrint, it doesn't set display: none on that particular code.
My qr-code html: The issue is in the first div tag at the top. I have tried adding single quotes on the class names to see if that works as well.
<div
fxLayout="column"
class="qrobj"
[ngClass]="{
deleted: !this.shouldExist,
noPrint: !this.shouldExist
}"
>
<button *ngIf="this.shouldExist" class="noPrint" mat-icon-button>
<mat-icon
matTooltip="Delete this Person?"
matTooltipPosition="after"
color="warn"
(click)="sendDelete()"
>block</mat-icon
>
</button>
<button *ngIf="!this.shouldExist" class="noPrint" mat-icon-button>
<mat-icon
matTooltip="Undo Delete?"
matTooltipPosition="after"
color="primary"
(click)="undoDelete()"
>undo
</mat-icon>
</button>
<div fxLayout="row" class="text">
<p>{{ person.Name }}</p>
<p>{{ person.Name }}</p>
</div>
<div fxLayout="row" class="images">
<img [src]="this.qrlink" (error)="getDefaultUrl()" />
<img [src]="this.piclink" (error)="getDefaultUrl()" />
</div>
</div>
Here is the part of my css that matters:
.deleted {
opacity: 0.3;
}
#media print {
.noPrint {
display: none;
}
}
This is what it looks like
before I delete a Code
This is what it looks like
after I delete a Code:
This is what shows up in the print preview:

Related

How to apply styles to a shadow element from within a css file

I've got the following code, that's basically an Auth0 login form and it includes the logo image as an img element, which has it's own shadown tree: It looks like this:
<div class="auth0-lock-header-welcome">
<img alt="" class="auth0-lock-header-logo" src="/supp/pixel.png">
#shadow-root (user-agent)
<span>
<img />
</span>
<div class="auth0-lock-name" title="Log in">Log in</div>
</div>
How do I select the <span> in the #shadow-root, the <img> or even both in a classic .css file? Or do I have to write some React code for it?
Here's what I tried (none worked):
.auth0-lock-header .auth0-lock-header-logo::shadow #shadow-rootspan{
display: none;
}
:host(.auth0-lock-header .auth0-lock-header-logo #alttext-image) {
display: none;
}
PS: Sorry if it's a stupid question.

How to overwrite child element style with ngStyle

I need to set a style for entire div but it doesn't work for child components:
<div class=“myClass” [ngStyle]="{'cursor': 'not-allowed'}">
<button class=“myButton”>
OK
</button>
</div>
How can I do that? And same for this case:
<div class=“myClass” [ngStyle]="{'cursor': 'not-allowed'}">
<button class=“myButton” [ngStyle]="{'cursor': 'default'}">
OK
</button>
</div>
Edit
In your first example, the problem is just that the browser's default CSS style for the button is more specific than your div's not-allowed cursor. If you want the not-allowed cursor to apply to both div and child elements, you can apply a notAllowed class to your div and have a rule like this
component.css
.notAllowed, .notAllowed *
{
cursor: not-allowed;
}
Now, if you want to be able to change the cursor dynamically, depending on some condition, just add the class dynamically by binding it to the condition variable
component.html
<div class="myClass" [class.notAllowed]="notAllowed ">
<button class="myButton">
OK
</button>
</div>
component.ts
public notAllowed = true;
I created a stackblitz for this
https://stackblitz.com/edit/angular-5z9ru4?file=app%2Fapp.component.html
Initial answer
Why don't you set it in your css?
myClass, myClass>*{ cursor: not-allowed;}
Or using
<div [style.cursor]="'not-allowed'"

ng-class not responding to model update

This is very straightforward: My angular view displays rows of printOrders generated via ng-repeat. If a print order has been printed, it applies the class 'panel-pink'
<div class="col-md-12" ng-repeat="printOrder in printOrders | filter: statuses">
<div class='panel mb20 panel-primary panel-hovered' ng-class="{'panel-pink' : {{printOrder.Printed}}}">
<div class="panel-body">
<div style="text-align: center; margin-top: 10px; margin-bottom: 10px;">
<div>{{printOrder.GcodePath}},{{printOrder.Flavor}},{{printOrder.Finishing}}</div>
</div>
<div>
<a class="btn btn-small btn-success btn-sm" ng-click="doPrintOrder(printOrder)">Print</a>
</div>
</div>
</div>
</div>
When it loads the page, it correclty applies the 'panel-pink' class for those that are printed, but when I change the printOrder status via ng-click it doesn't
When a users click on a "print" button the following code on the print order controller executes:
$scope.doPrintOrder = function (printOrder) {
PrintOrdersAPIService.printOrder(printOrder.Id, printOrder.UserId, printOrder.GcodePath).then(function (data) {
printOrder.Printed = true; //this line should change the model
});
}
Everything works ok, the only problem is that the ng-class dosen't get appied when the model changes (printOrder.Printed = true;)
What should I do in order to make the styling work dynamically?
Change your ng-class to this:
ng-class="{'panel-pink' : printOrder.Printed}"
You don't need the curly braces.

CSS to specify pseudo element :after following input

I have html code that I cannot change.
I cannot use JS for help. So the only option is CSS. example here:
https://jsfiddle.net/4gKPL/
HTML:
<!-- code for input -->
<div class="form-group complete">
<label>label for text input</label>
<input type="text"/> <span class="error-message">This is an error message</span>
</div>
<!-- code for dropdown -->
<div class="form-group complete">
<label>label for select input</label>
<div class="custom-selectbox custom-selectbox-form">
<select name="sth" required>
<option>a</option>
<option>b</option>
<option>c</option>
<option>d</option>
</select> <span class="selectedValue"> </span>
<span class="is-visually-hidden">select to open the list</span>
</div> <span class="error-message">This is an error message</span>
</div>
CSS:
.complete:after {
content:'OK';
}
I need to display additional content (in this example 'OK') for input fields but not for select.
Spans after interactive components are optional so don't have to exist.
Any idea about how define this selector?
Since you can't use :after on input elements, all I can think of is a really hackish solution: select the element following and insert a :before pseudo element in front of it.
.complete input[type="text"] + .error-message:before {
content:'OK';
}
See this jsFiddle for a working example.
EDIT
The .error-message element's not always being present throws a wrench in this plan. You can make an unprefixed call to :before (+ :before), but then if the following element is hidden in some way, so will your OK message. And even if it is present, it picks up the styles of the element following. See this updated jsFiddle.
I'll leave this idea up so people can see it, but it doesn't look like it will work for your purposes.

How can I style .class-0, .class-1, .class-2 with a common selector?

I want to style the following CSS classes; is there any short styling technique for this?
.test-0 { }
.test-2 { }
.test-3 { }
/* etc. */
I am looking for something like:
.test-%d% { }
I want to dynamically create many test-* classes with different numbers and common styles.
Update
here is my actual situation
<input type="button" value="click" class="button_class" />
<h1 class="ui-widget-header">Question - 1 </h1>
<div class="ui-widget-content">
<div id="form_container-0">
<div class="placeholder">Add your form fields here</div>
<div style="clear: both;"></div>
</div>
</div>
When user click the above button then same structure will clone and append to the end of the form
so the form will be as
<h1 class="ui-widget-header">Question - 1 </h1>
<div class="ui-widget-content">
<div id="form_container-0">
<div class="placeholder">Add your form fields here</div>
</div>
<div id="form_container-1">
<div class="placeholder">Add your form fields here</div>
</div>
</div>
the css class form_container-[%d] will be created dynamically by jquery.
so i want to add style to this class.
also it would be great if you share optimised code for cloning the structure with
different ID.
Please do let me know if you still have doubt.
thanks
You can use an attribute selector.
div[class*='test-'] {...}
I think #Ed W have the right solution BUT I have an extra idea while is not straight forward is shorter than what you have. And will help to make different testing that is waht I think you want... fiddel http://jsfiddle.net/ncubica/2sj9W/
css
.test-1,
.test-2,
.test-3,
.test-4,
.test-5{
color:#F60;
display:block;
}
.test-5{
color:blue
}
html
<span class="test-1">One</span>
<span class="test-2">Two</span>
<span class="test-3">Three</span>
<span class="test-4">Four</span>
<span class="test-5">Five</span>
span five will be in blue color... so you can override the class you want to test and play with it.
Also you can use selectors like
HTML
<div>
<span>I'm pink</span>
<span>I'm pink</span>
<span>I'm pink</span>
<span>I'm pink</span>
<span class="test-1">I'm red</span>
</div>
CSS
div > span{
color:pink;
display:block;
}
div > span.test-1{
color:red;
}
and the last span will be red. I hope this help.
My two cents...

Resources