Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

256
Visualizações
CSS rule not for SVG elements

Never thought I will ask something about CSS but here it is. When you develop a widget you can't rely on particular website's stylesheet so you want something like this:

.xxx-widget * {
  all:revert;
}

But in case your widget has SVG icons:

<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 19 16"><path fill-rule="evenodd" d="M.009 16l18.658-8L.009 0 0 6.222 13.333 8 0 9.778z"></path></svg>

reverting all removes also and d property from svg and icon disappears. Then I tried to modify reverting selector:

.xxx-widget *:not(svg) {
  all:revert;
}

Above snippet does not work and at the same time browser does not recognize it as incorrect and a lot of styles are getting broke. Is there any approach to compose selector for everything except svg?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Interesting question. First off, CSS affecting SVG d attributes (currently) happens in Chromium based browsers. Firefox is yet to follow. (But for most of rest SVG properties it holds that CSS reset affects them.)

I'd try invoking arcane knowledge of CSS @namespace:

<style>
/* "page" styles */
p {
 color: orange;
 border: darkorange solid;
}
circle {
 fill: orange;
 stroke: darkorange;
}
</style>

<style>
/* "your" styles not affecting SVG */
@namespace "http://www.w3.org/1999/xhtml";
body * {
 all: revert;
}
</style>

<body>

<p>
 This text should be black (or in default UA colour);<br>
 following circle should be orange:
</p>

<svg width="100" viewBox="-4 -4 8 8"
 xmlns="http://www.w3.org/2000/svg" >
 <circle r="2" stroke-width="1"></circle>
</svg>

Because historically HTML and SVG still possess different namespaces, you can still use it for your advantage.

More examples:

<style>
* { /* implicit namespace is not set, so affects both HTML and SVG */ }
</style>

<style>
@namespace "http://www.w3.org/1999/xhtml";
@namespace only_html "http://www.w3.org/1999/xhtml";
@namespace only_svg "http://www.w3.org/2000/svg";
* {
 /* implicit namespace is set to html, so affects only HTML, not SVG */
}
*|* {
 /* affects elements from any namespace */
}
only_html|* {
 /* affects only HTML elements due explicit namespace */
}
only_svg|* {
 /* affects only SVG elements due explicit namespace */
}
</style>
over 4 years ago · Santiago Trujillo Relatório

0

<head>
<style>
/* "page" styles */
p { color: red; border: solid; }
svg circle { fill: orange; }
</style>

<style>
 @namespace only_svg "http://www.w3.org/2000/svg";
*:not(only_svg|* )  {
 all: revert !important;
}
</style>
</head>
<body>
<p>
 This text should be black (or in default UA colour),
circle should be orange.
</p>
<svg width="100" viewBox="-4 -4 8 8"
 xmlns="http://www.w3.org/2000/svg" >
 <circle r="4"></circle>
</svg>
</body>

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda