Can someone explain the purpose of `svg:not(:root) {overflow: hidden}` in simple

I am facing an issue with displaying my .svg file in my next-js project. It seems that the CSS code svg:not(:root) { overflow: hidden; } is causing the problem.

Could someone explain what this particular CSS rule is for?

After changing the code to svg:not(:root) { overflow: visible; }, the SVG icons are now showing. However, I have another website where the SVG icons display fine despite using svg:not(:root) { overflow: hidden; }. I can't seem to find any significant differences in the CSS of these two websites, leaving me confused about the purpose of svg:not(:root).

Below is how I am using the SVG in HTML:

<svg aria-label="check" style="width: 24px; height: 24px; position: relative;" role="presentation">
  <use xlink:href="/assets/icons/test.svg?v=130#check" style="fill: currentcolor;"></use>
</svg>

And here is a snippet from the content of test.svg:

<svg viewBox="0 0 750 500" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

  <style>
    :root>svg {
      display: none
    }

    :root>svg:target {
      display: block
    }
  </style>

  ...

  <svg viewBox="0 0 24 24" id="check" xmlns="http://www.w3.org/2000/svg">
    <path d="M0 0h24v24H0z" fill="none" />
    <path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
  </svg>

  ...

</svg>

Answer №1

The CSS rule being referenced here comes from the user agent stylesheet, which is automatically applied by the browser. It simply follows the guidelines laid out in the SVG 2 specification: the default value for the CSS overflow property is visible, but for certain <svg> elements that are not the root of a DOM tree, it should be set to hidden. This results in a clip-path being created around the element's layout box, with everything inside the box visible and everything outside hidden.

Now, how does this relate to displaying an icon that clearly fits within the layout box? Apparently, not much. I have not been able to replicate the issue you described – for me, the icons remain visible regardless of the overflow setting.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Methods to maintain the select2 dropdown event open while interacting with another select2 dropdown

I have a situation where I need to dynamically add a class to a div whenever a select2 dropdown is open. To achieve this functionality, I am utilizing the open and close events of select2. The current code successfully adds the class when opening a selec ...

Issue with Z-index and wmode when using YouTube embed code on IE10

I am currently working on developing a div element that will prevent a YouTube video embedded in an iframe from playing when clicked. Instead, I want to trigger a JavaScript function upon user interaction. I have added the wmode=opaque parameter to the src ...

Manipulate children in Material UI components based on their class

My Goal I am looking to apply styles to the class button within the state of the class root, such as on :hover. My Approach I am attempting to have the button display on root:hover. const styles = { root: { '&:hover' { ...

Using DraftJS to swap text while preserving formatting

Currently, I am implementing Draftjs with draft-js-plugins-editor and utilizing two plugins: draft-js-mathjax-plugin and draft-js-mention-plugin My goal is to replace all mentions with their corresponding values when the user uses '@' to mention ...

Minimal Space Separating Footer Division and Body Element

While there are numerous discussions online about fixing footer alignment issues, I've encountered a unique problem that needs addressing. The issue at hand is a 29px gap between the bottom of the footer and the <body> tag on my webpage, which ...

Is there a more efficient method for integrating useParams within my context provider?

Currently, I am exploring context and working with a route: /show/:id In my context, I need to access the params ID of /show/:id. To achieve this, I initialized a state to an empty string in my context and utilized useParams in /show/:id to set the id. A ...

Personalizing the Navigation Bar

I am in the process of designing the navigation bar for my website that will work seamlessly on both desktop and mobile devices. To view my progress so far, check out this JS Fiddle link Here is the HTML code I have created: <div class="container-flu ...

React - Material UI - Custom input component with controlled TextField not functioning correctly leading to focus loss

I am experimenting with creating a customized input element for the TextField component in Material UI For example: export const InputsPage: React.FC = () => { const [value, setValue] = useState(''); return ( <Paper> < ...

I have the ability to shift text 50 pixels to the left

My navigation bar is currently aligned to the left, but I'm looking to move the text 50px from the left. Is there a way to achieve this? .navigation { width: 100%; height:35px; background-color: #f1b500; /*f2c255*/ margin-top: 4.4em; } .navig ...

Is there a reason why I need to rename the CSS file in order for it to function properly?

I recently completed editing the css file and saved it, but unfortunately, my css file isn't functioning properly. The display remains unchanged and the css files are not being loaded. However, when I decided to rename the css file, everything started ...

The spacing between the rows of the ListItem is excessively tall

Currently, I am working with Material UI to design a list. It seems that the height of my list elements needs to be reduced. I have attempted using <List dense={dense}>, but it appears to still be too spaced out. Is this issue related to padding or s ...

Illustration of `assign value` in material-ui calendar-selector

Struggling to set a default value in the DatePicker component from material-ui. The material-ui docs state: value object Sets the date for the Date Picker programmatically. source: http://www.material-ui.com/#/components/date-picker However, thi ...

What is the best way to create a select box in React that allows for both single and multiple selections?

I recently started utilizing a new package for generating dynamic forms, which can be found at this link. Upon reading through the documentation, I attempted to create a select box as outlined in the instructions provided here. Despite following the step ...

Tips for using unique fonts in email text display

As I was editing a Mailer template in core php, I found myself wanting to set a custom font for the text displayed in the mail template similar to how we do it for websites using CSS and imported fonts. Below is the code snippet that I have been using: & ...

Avoiding setting state before useEffect is important to ensure that the component's initial

I have a React/Next component that retrieves data from firebase storage based on the route. For example, if the route is http://localhost:3000/training/javascript, the component will fetch data from the /training/javascript route in firebase storage. // Re ...

The issue of onClick failing to function when paired with the addEventListener for the

Looking into a react component for a profile button that opens a menu with three options: My Profile, Settings, and Logout. The issue seems to be with the onClick event on the a tags not working as expected (the console.log is not being printed). Interes ...

Troubleshooting cross-origin resource sharing problem with Express NodeJS server running on localhost

Utilizing the fetch web API to send a POST request from ReactJS to an Express NodeJS server running on localhost with different ports. Using Client Fetch API fetch("http://localhost:8081/test", { method: "post", mode:"no-cors", headers: { ...

Applying CSS borders with circular corners

Can this unique border style be achieved using only CSS? https://i.sstatic.net/wMtbG.png ...

Do the last block in the table occupy the remaining space in the row?

Trying to create an HTML email calendar and struggling with getting the last td to fill the remaining space without affecting the width of other rows. Is there a way to increase the width of just the 4th block on the last row to fill the empty space? Here ...

Transform a Mobx observable map into a JavaScript array

I am working with a component that receives the value of "form.$('userProfile').fields" as a prop, which is an observable map. The structure of this map can be seen in the console.log screenshot below: class Location extends React.Component<* ...