Remove specific rules from tailwind base - tailwind-css

I want to remove the img rule from tailwind base, is there anyway to do that?
Tailwind base adds this:
img, video {
max-width: 100%;
height: auto;
}
I want to remove that rule. Overrideing it with initial will not get my expected result.
So unfortunately i cannot do:
img, video {
max-width: initial;
height: initial;
}
height: initial doesnt seems to be the same as having no height attribute at all. If i override height to initial the height will be the source of the image and height attributes on the <img height="200"> will not be respected.

Yes, it's
As the documentation says, you can override the base properties by using #layer base.
It's available from v1.9.0.
#tailwind base;
#tailwind components;
#tailwind utilities;
#layer base {
img, video {
max-width: initial;
height: initial;
}
}

Related

CSS styling precedence when using React and CSS modules

I have a css module which apply styling to an existing component. The css module works fine but the styling was always overwritten by the default style of component.
Supposed I have this markup.
<Header className={styles.header}>
<Row type="flex" justify="space-between">
<Col>
<Link to="/">
<Title className={styles.brand}>Shiritori</Title>
</Link>
</Col>
</Row>
</Header>
Then uses the styles declare in the css module:
.header {
background: rgb(75, 191, 107);
margin-bottom: 1rem;
> div {
align-items: center;
}
}
I expect that the background css property of the default style will be overwritten but instead the styles in my css module was canceled out.
Actual result:
.ant-layout-header {
height: 64px;
padding: 0 50px;
line-height: 64px;
background: #001529;
}
.ant-layout-header, .ant-layout-footer {
-ms-flex: 0 0 auto;
flex: 0 0 auto;
}
.ant-layout, .ant-layout * {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.App_header__37gyT {
background: #4bbf6b; <- this property was overwritten by the .ant-layout-header background property
margin-bottom: 1rem;
}
I also consider the order of css/scss import but same result.
import "../../../node_modules/antd/dist/antd.css";
import styles from "./App.module.scss";
Is there a way to overwrite existing style of a component. I use antd for the UI toolkit and components.
Unable to replicate your issue. Seems to be working fine:
That said, when dealing with CSS specificity, you can do one of several things:
Overwrite a child class style from a parent class style.
Use the id property: <Header id="header-id">Header</Header> (then use the # to refer to header: #header-id { ... })
Overwrite the .ant-layout class name within a separate CSS/SCSS file.
Add an !important declaration after the style property, for example: background: pink !important;
That said, I'd avoid importing the entire CSS library and instead use the babel plugin to import only what's needed.

How to style a PrimeNG Chips?

I have a form in my application where I use the following code from Primafaces:
...other inputs...
<label for="workshopTags">Tags</label>
<p-chips
[(ngModel)]="values"
name="workshopTags"
id="workshopTags"
></p-chips>
I am able to display the Chip element correctly but I would like to style it putting its width to 100% and the height to 100px, but nothing seems to work to change those. This solution didn't work for me. I tried to set a styleClass or an inline style as the documentation suggest but they didn't work either. If I write inline:
style="width: 100%"
The following error is thrown:
Error: Cannot find a differ supporting object 'width: 100%;'
How can I make it work?
there are tow methos to style primeng component overwrite the original style or by create a custom style base on custome class
overwrite
add the style to global style.css or style.scss , this method for overwrite primeng component style without add extra class to the component.
.ui-chips {
display: inline-block
}
.ui-chips ul {
border:2px dashed green !important; /* 👈 I have use important */
}
.ui-chips > ul.ui-inputtext .ui-chips-token {
font-size: 14px;
background: green !important; /* 👈 I have use important */
border:1px solid #005555;
box-shadow: 0 0 25px #ccc;
}
stackblitz demo 🍏🍏
custome style
the method above will change the style of all p-chips component in the entier project , by this method you need to set styleClass property so you can create different style like the example here 👇 , but you need to set styleClass property for every component
<p-chips [(ngModel)]="values" styleClass="p-chips"></p-chips>
style.css
.p-chips.ui-chips {
/* border:1px solid #ff2200; */
display: inline-block
}
.p-chips.ui-chips ul {
border:2px dashed orange;
}
.p-chips.ui-chips > ul.ui-inputtext .ui-chips-token {
font-size: 14px;
background: orange;
border:1px solid #ff5555;
box-shadow: 0 0 25px #ccc;
}
stackblitz demo 🍊🍊
You can use ht /deep/ modifier ,add this inside your app.component.css and delete it from your style.css, and you don't need !important to force the style here, delete it. here is what you are looking for
p {
font-family: Lato;
}
/deep/ .p-chips > .ui-inputtext {
width: 100%;
height: 100px;
}
check it here https://stackblitz.com/edit/angular-primeng-startup-kmm7xw
You could try encapsulation: ViewEncapsulation.None in your override component decorator:
#Component({
selector: 'app-chip',
templateUrl: 'path-to-template where you use ui-chips',
styleUrls: ['path-to-styles where you could override ui-chips styles'],
encapsulation: ViewEncapsulation.None
})
export class AppChipComponent { }
To set the width to 100%, you have to use the style or styleClass attribute and set the css property display: block.
As an example using the styleClass attribute
<p-chips
[(ngModel)]="interests"
styleClass="block">
</p-chips>
Here I am using Prime Flex v3 with PrimeNg.

CSS applied to element being overwritten by global css attribute

I am setting the width on an image:
<img class="someImageClass" src="someImage.jpg">
I use the following css styles:
.someImageClass {
max-width: 30px;
}
But I also have a global css style for images as well:
img {
max-width: 100%;
}
The max-width in the someImageClass style is being overwritten by the one that is global and I don't understand why. If I apply the css class directly on the element, it should take precedence over any global style.
try
img.someImageClass {
max-width: 30px;
}
There must be another rule using img.className somewhere. But in normal cases you can calculate the specificity of CSS rules. How is explained here https://www.w3.org/wiki/Inheritance_and_cascade#Specificity
Are you aware of the term important ?
.someImageClass {
max-width: 30px !important;
}

Material 2 dialog change style

I'm trying to change the style of the md-dialog.
in my main.scss i'm importing the prebuild pink-bluegrey theme...
then in my component I import the following -->
#import "#angular/material/dialog/dialog.scss";
$mat-dialog-padding: 0;
$mat-dialog-border-radius: 0.5rem;
$background: #ffffff;
#mixin mat-dialog-container {
padding: $mat-dialog-padding;
border-radius: $mat-dialog-border-radius;
background: $background;
}
#include mat-dialog-container;
The padding and border radius is correctly applied to the dialog window.
But the background is not working... also tried the !important statement.
I'm using this in a single component...
Is there also a change to apply those styles globally?
in chrome dev tools I see those applied style changes. The background gets overwritten by the pink-bluegrey theme..
hope anyone can help.
thanks
It is better practice to add a wrapper class around your dialog, and then add styling to the children. Have a look at this article for more information.
When you open your Angular dialog, you can add a panelClass
attribute, like this:
this.dialog.open(MyDialogComponent, {panelClass: 'my-panel'}).
then, in your css (e.g. in the root styles.css file), you can add the following:
.my-panel .mat-dialog-container {
overflow: hidden;
border-radius: 5px;
padding: 5px;
}
EDIT Warning
It is also possible to add the css to another file than the root styles.css, but then you have to use ::ng-deep in the css (e.g. ::ng-deep .my-panel{ // ... }). This is not advised, as ::ng-deep is deprecated in Angular
EDIT2 Good alternative
If you are using scss, then you can place your .my-panel-style in your mydialog.component.scss file, by using a #mixin, and #import the file in styles.scss. You can then use #include to load the defined mixin.
in your mydialog.component.scss file
#mixin myPanel(){
.my-panel .mat-dialog-container {
// css here
}
}
in your styles.scss
#import 'path/to/mydialog.component.scss' // you don't need the .scss suffix
#include myPanel();
I solved this problem by including this css block in the end of file material2-app-theme.scss
.mat-dialog-container {
overflow: hidden !important;
border-radius: 5px !important;
padding: 5px !important;
}
can you use css then change background in mat dilog, at i used color transparent
mat-dialog-container {
padding: 0px !important;
background: transparent !important;
}

Override Inline Styles with CSS for the google Ad div

<div id='div-gpt-ad-131415161-0' style='height:250px; width:300px;'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-131415161-0'); });
</script>
</div>
I would like to override the above inline css with set to auto for both. I tried with the followings but not working ...
#div-gpt-ad-131415161-0 div[style] {
height: auto !important;
width: auto !important;
}
OR
div[style]#div-gpt-ad-131415161-0 {
height: auto !important;
width: auto !important;
}
When the style is defined in html, override any definition from external css. And uses only this definition.
So if you cand remove, style from html, will works. the las definition of css external about this div.
You can try to override the styles with javascript directly, this will change the inline css

Resources