Using Angular 9 Material Styles Locally - css

I am implementing very basic tables following the examples given in the official docs.
In those examples, the tables have nice styling which is seemingly localized to each sample table. The main style I want to use is mat-elevation-z8 (from what I can tell). Unfortunately, when I embed that table in my page it styles the entire page, all the way up to the body. Here is a stackblitz which shows what I mean:
https://stackblitz.com/edit/angular-5oe5jz
The divs above and below the table are styled to match the table. I want the table to be styled in isolation as in the samples. Is my only option to go override every property I don't want to be affected by Material?

1) You don't need to override every property, but you just use material CSS classes where you require otherwise don't add the classes.
2) For example in your stackblitz link the page is looking with material design, because you applied class 'mat-app-background basic-container' to the div in your index.html file. so that the entire page is looking with material design.
3) Remove that mat-app-background basic-container from index.html file, and use material CSS classes to for tables only.
4) I have just updated the index.html file for your reference. check here

Related

How do I customize the styles within an Angular Material Input?

I am working with a freelance client on the side that wants to utilize Angular Material throughout the project. However, they do not like the way that the underline looks in the angular material input. I have tried a variety of approaches to change this, but I haven't found any success yet.
To be honest, I haven't even been able to find the tag in the DOM that would let me alter that border.
Here are the Angular Material docs, as you can see all of the available options have at least some form of a bottom border.
Some approaches I've tried:
This one is from the old angular material and no longer works for the new angular material
The accepted answer here is for the new angular material, but I was not able to get it to work. I implemented exactly as described and no styling changed.
This approach looked like it would work. Unfortunately, I could not get it to work either.
Any help or input on this topic would be appreciated.
For reference, the client said that any changes that deviated from the desired design would be denied. So I have to get this to work. I believe I could maybe, possibly lobby to build a custom input component as a solution, but I know that they are dead set on Angular Material.
Edit. Added a pic of desired look:
this little code did it for me. I didn't want to display it and just set height and width to 0.
::ng-deep .mat-form-field-underline{
height:0 !important;
width:0 !important;
}
However I think its kinda hard to style the Angular Material Components and for me its sometimes better to built my own.
First of all, you'll need a .scss to be imported either within the default theme.scss or after the import of the material stylesheet in main.scss.
Now, Material offers you the option of customising colours and some of the styles by overriding their #mixins found somewhere in the Material folder ( I don't have the folder in front of me.. very sorry for the vague pointing... ).
Back to the newly added file; You can override material's default styling by checking the DOM for certain classes and then adding them in said file with the desired changes. Because the file is loaded after Material's, the default styling in overridden. Same thing applies for the #mixin you chose to override. Just have a look in the file, copy-paste the whole #mixin and change accordingly.
Now if you wish to go even further, my colleagues and I have a custom library that uses Material BUT the whole styling is stripped off leaving you with the bear input within the mat-form-group and then using a <input disabled/> with a position:absolute over it. That way you get to benefit from material without using their style.

Style elements in HTML in Angular Material

May be it is a common way of working of libraries but i dont understand why i have so many style elements in my index.html where i use angular material. Here you see my header element that contains different classes for angular material components.
Is that working correctly? Is it slow downing my html file?
Yes, it's normal.
Each registered theme results in 16 <style> tags being generated.
And it's not slowing down your website. As a matter of fact, from all forms of adding CSS to a page, <style> is fastest.

How to apply bootstrap css to Primefaces custom compoents

I am using Primefaces 5.0.I want to use or bootstrap css to Primefaces custom components like List, table, selectOneListbox.
I am to apply css to normal component like button, link etc.
It's possible, but due to reason that a internal structure of Primefaces's components are different from a plain HTML components with which Bootstrap supposed to work you will need to make hard job to accomplish that. You will need to debug every Primefaces component to see its internal structure and change Bootstrap's css file that it will correspond to internal classes of Primefaces's component.
Actually you have three alternatives (maybe more):
Like BalusC mentioned, Primefaces has its own implementation of Bootstrap theme: you can see it here: http://www.primefaces.org/themes IMHO, best option
Use Bootfaces JSF library: http://www.bootsfaces.net/ Pay attention that it's pretty new library and possible buggy. There isn't big community support like for Primefaces library.
Make you own Composite (or Custom) Components with desired structure and styling.

How to handle cq component with same html structure and different css?

I have 2 jsps for 2 cq components that have the same html structure but the css is different.
What are the best practices for refactoring in this case?
One scenario would be to have a single component and set the css classes based on some input provided by the author in the dialog (component type 1, component type 2), but this gets messy cause I need to do the if checks and set different values for the css classes. It becomes even more complicated if I add a 3rd component with the same html structure and different css.
I would suggest to use one of next approaches:
Create base component with html structure and for each design create components which have sling:resourceSuperType of base component. And in child components you can override css file with specific one.
Base component should be made of (at least) 2 jsp files:
container with some class (unique among different designs) which contains include of actual component content. This class then should be used in you selectors in css file. Like .container-design-1 .title {}. This container also can be overwritten in child components.
jsp with content.
Also you can still use component dialogue, but populate dropdown menu with available designs dynamically. For example, you can have some servlet+service which looks into repository and collects available clientlib categories for this component. And during rendering you will include selected clientlib category, set unique class for your container and use it in css selectors (like in previous approach).
Also in both cases html and id/class names of elements should be the same, and only styles implementation is different.

apply external CSS to specific area

I'd like to import an external CSS (eg. Bootstrap) into my site-- the problem is I'd like to apply the Bootstrap styles only to a specific region of the page. When I include Bootstrap, it applies its styles to the entire page, restyling all tables, divs, etc.
Is it possible to only apply Bootstrap to a region (say a parent div or something?)
Thanks
The only way to do this is to have a separate iframe for the content you want to style with Bootstrap (unless you want to edit the Bootstrap CSS, and add your outer div's selector to the beginning of EVERY rule).
HTML5 introduced the new scoped attribute, which is made specifically for your use case, but has not yet been implemented by any one of the major browsers.
If you are using jQuery (which you probably are, since all of Bootstrap's Javascript functionality is dependent upon jQuery), you might wanna try Simon Madine's jQuery Scoped CSS plugin.
Import Bootstrap before your own styles. That way your own styles will overwrite the changes made by Bootstrap where applicable.
I've only tried this locally and not given it any thorough testing but it seems to work fine. I created a div around the content and assigned it an id. Then prefixed all of the bootstrap selectors with the id I assigned the surrounding div. The prefixing was done with a couple of search and replace operations. Perhaps it can be done easier with less
Forgot to mention that the body selector of the bootstrap.css has to be replaced with the id and not prefixed like the other selectors.

Resources