Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I override the style of a popover? #1707

Closed
hesparza opened this issue Mar 3, 2017 · 14 comments · Fixed by #2190
Closed

How can I override the style of a popover? #1707

hesparza opened this issue Mar 3, 2017 · 14 comments · Fixed by #2190

Comments

@hesparza
Copy link

hesparza commented Mar 3, 2017

I have a popover in my component but it doesn't display correctly when I include the text on it. The text is overflowing the popover, I need the text not to be wrapped.

By doing my search on the internet, this is a common problem which gets solved by overriding the popover property "max-width" to be 100%, I proved that in the browser's debugger and it works. The problem is that I don't seem to be able to set/override this property from my component's css file.

I have tried:
.popover { max-width: 100%; }

and

.popover-content { width: 100%; }

and

.popover-content, .popover-content .body { width: 100%; }

None of them have worked, any thoughts?

@hesparza
Copy link
Author

hesparza commented Mar 3, 2017

Ok, I managed to do it by setting the body as the container of the popover:

container="body"

Then I added the next css to the global style of my application:

.popover { max-width: 100% !important; }

I really don't like the idea of using !important in any of my app's css though, that's like the last resource. I would appreciate if you guys have better ideas.

@exedor
Copy link

exedor commented Mar 12, 2017

Lucky you. I can't get it to work even with container="body" AND using !important.

@mechu
Copy link

mechu commented Mar 14, 2017

Try to use

@Component({
    selector: "your-component",
    templateUrl: "your-template.component.html",
    styles: [`
        :host >>> .popover {
          color: #000;
          max-width: 100%;
        }
    `]
})

@RaviNags
Copy link

RaviNags commented Mar 29, 2017

@mechu solution is working (solution write on the documentation).

but how to do if you are using an external styling file ?

@Component({
  selector: 'pr-test',
  templateUrl: './pr-test.component.html',
  styleUrls: ['./pr-test.component.scss']

})

my pr-test.component.scss file ->

:host >>> .popover {
  background-color: #009688;
  color: #fff;
}
:host >>> .popover>.arrow:after {
  border-top-color: #009688;
}

Thanks

@1-0-1
Copy link

1-0-1 commented May 12, 2017

:host doesn't help when container is body. :host gets applied to the container of the link used to initiate the popover. There is no way to apply styles to multiple popovers on a page.
An older popover had a popover-class that assigned a class to the popover container. Can you bring that back?

valorkin pushed a commit that referenced this issue Jul 18, 2017
* feat(tooltip): add containerClass

* feat(popover): add containerClass

* refactor(popover & tooltip): string setters, no reserved keywords
fixes #1707
fixes #1395
@h6784rfg6
Copy link

h6784rfg6 commented Sep 6, 2017

RaviNags, use

:host {
   /deep/ .popover {
     background-color: #009688;
     color: #fff;
   }
}

Had also some issues with >>> it is somehow not more supported, but /deep/ works like a charm.

@mkeith121
Copy link

@h6784rfg6 That worked well for me.

Does anyone know if there is a more supported way at this point? I see that there is a "containerClass" input, but I wasn't able to successfully access that class from a "styleUrl" linked .scss doc.

@KellyVillalobos
Copy link

@mechu awesome!! couldn't figure out how to target a class created after compilation in Angular. Your solution hit the spot. Now I know how to do it. 🙌🏻

@GautamPanickar
Copy link

Try to use

@Component({
    selector: "your-component",
    templateUrl: "your-template.component.html",
    styles: [`
        :host >>> .popover {
          color: #000;
          max-width: 100%;
        }
    `]
})

This worked for me. Thanks.

@robtong21
Copy link

/deep/ did not work for me using .scss file in Angular 9. Anything else???

@charlenebuena
Copy link

Nothing is working for me from the aforementioned as well. Working with Angular 9

@KokalaBhanusri
Copy link

@robtong21 you can try

:host ::ng-deep .popover {
background-color: #009688;
color: #fff;
}

/deep/ is not working now.

@1-0-1
Copy link

1-0-1 commented Apr 15, 2020

Have you tried using "containerClass" and setting a custom class for it?

@Mohd-umair
Copy link

Mohd-umair commented Feb 23, 2023

@component({
selector: 'app-message-report',
templateUrl: './message-report.component.html',
styleUrls: ['./message-report.component.scss'],
encapsulation: ViewEncapsulation.None,
styles: [.popover { width:500px; }]})

Use Encapsulation => ViewEncapsulation.None in the Ts file like the example showing above, this will 100% work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.