问题
I need to add border-radius
to ion-img
but it seems shadow DOM
won't let me modify.
HTML
<ion-img [src]="img-url" [alt]="alt"></ion-img>
CSS
ion-img {
border-radius: 10px !important;
}
回答1:
HTML
<ion-img [src]="img-url" class="your-img"></ion-img>
CSS
.your-img {
border-radius: 10px !important;
overflow: hidden;
}
回答2:
It's tricky to encapsulate style with Shadow DOM, but there are ways.
In this case, does it work for you with an inline style attribute?
<ion-img [src]="img-url" [alt]="alt" [style]="border-radius: 10px;"></ion-img>
Otherwise you might try adding a <style></style>
tag to the inner HTML of the Shadow DOM with the border radius.
A modified example from the attached link:
const host = document.getElementById('shadow-host');
host.shadowRoot.innerHTML = `
<style>
img {
border-radius: 10px;
}
</style>
`
来源:https://stackoverflow.com/questions/58640790/how-to-add-border-radius-to-ion-img-in-ionic-4