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

Issue with ::before and ::after pseudo elements #24

Open
qqilihq opened this issue Dec 19, 2019 · 10 comments
Open

Issue with ::before and ::after pseudo elements #24

qqilihq opened this issue Dec 19, 2019 · 10 comments

Comments

@qqilihq
Copy link

qqilihq commented Dec 19, 2019

First: Many thanks for making this -- looks like this will save us quite some time!

I'm encountering a problem with CSS ::before and ::after elements. Minimal example follows using the latest version from the master branch:

index.html:

<html>
<head>
  <script src="https://rawcdn.githack.com/nuxodin/ie11CustomProperties/40dddac11e14fda350d0f918f6039f80cde090e3/ie11CustomProperties.js"></script>
  <link href="./styles.css" rel="stylesheet"></head>
</head>
<body>
  <div></div>
</body>
</html>

styles.css:

:root {
  --red: red;
  --green: green;
  --blue: blue;
}

div {
  position: relative;
  width: 600px;
  height: 200px;
  background-color: var(--red);
}

div::before,
div::after {
  content: "";
  position: absolute;
  width: 33.4%;
  height: 100%;
}

div::before {
  left: 33.4%;
  background-color: var(--green);
}

div::after {
  left: 66.6%;
  background-color: var(--blue);
}

This is supposed to create three squares in red, green, and blue. Screenshot from Chrome, Edge, etc. looks as follows:

image

When rendering in IE with the polyfill, I see the following:

image

The generated CSS code looks as follows:

image

Any ideas what's wrong here?

@nuxodin
Copy link
Owner

nuxodin commented Dec 19, 2019

Thank you for your feedback!

Yes, IE has a bug, where unknown properties at pseudo-selectors are computed at the element and not at the pseudoelement.
This meens, you can set propertys for pseudo-elements, but the property is used by ::before, ::after and the Element itself.

Its complicated to fix this issue, at the moment I do not have enough time and nerves to fix it.

@qqilihq
Copy link
Author

qqilihq commented Dec 20, 2019

I understand -- thank you for the clarification!

In the end I went for a different polyfill which worked for my use case. Anyways, I’d suggest to keep this ticket open as it might be helpful for others and contains the test case?

@karungn1
Copy link

karungn1 commented Jan 21, 2020

@qqilihq I have similar problem and problem with SVG path's fill and stroke (sample attached below). Please suggest the polyfill you have used.

			```

path {
&.stroke {
stroke: var(--agentMsgDisabledBorder);
}
&:not(.stroke) {
fill: var(--agentMsgBg);
}
}
}

@nuxodin
Copy link
Owner

nuxodin commented Jan 23, 2020

@karungn1
Maybe your issue is this one fixed resently?
#15
Do you have the latest version?

@3SCadmin
Copy link

3SCadmin commented Mar 13, 2020

This issue had me guessing for a whole afternoon.

  • You can create pseudo elements with JS,
  • but you can't manipulate them afterwards (not part of DOM)

One way around this is:

  • declare CSS variables on elements you can manipulate (body)
  • in the pseudo element styling reference these variables
  • use document.querySelector("body").style.setProperty() to change the CSS variables

That's where I was at when I tested this polyfill. I could see that .setProperty() was supported and working in your example. I just couldn't replicate the functionality in my test scenario... because my scenario had psuedo elements in it :)

Please please add this piece of the puzzle to ie11CustomProperties.js

@nuxodin
Copy link
Owner

nuxodin commented Mar 31, 2020

Sorry, at the moment, its a too big puzzle for my spare time....

@happy2deepak
Copy link

happy2deepak commented Sep 18, 2020

In the end I went for a different polyfill that worked for my use case

@qqilihq - can you please help me with the Polyfill you used? Even I'm facing the exact same issue.

@qqilihq
Copy link
Author

qqilihq commented Sep 19, 2020

@happy2deepak We used https://github.com/jhildenbiddle/css-vars-ponyfill

@happy2deepak
Copy link

happy2deepak commented Sep 21, 2020

Thanks a lot @qqilihq . But yes 11000 websites are using this current polyfill and there's a no fix on this since last year. It is strange.
cc: @nuxodin - can you help us out buddy ?

Update:
Just found out that if you use an !important on the parent of psuedo-element (::after, &::before), it doesn't cause this issue on IE. But it is not a good practice for bigger projects. Though won't harm a small website.

@benm-eras
Copy link

@happy2deepak could you provide a little example of what you meant in your update there? I am not sure what you mean.

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

No branches or pull requests

6 participants