-
Notifications
You must be signed in to change notification settings - Fork 42
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
only set nested html elements to relative if needed #55
Comments
as a workaround, im looking for mutations on my dynamically created buttons and reverting the style if the mutation is related to the style attribute ...
const observer = new MutationObserver(function(mutations) {
const relativeFound = false;
mutations.forEach(function({oldValue, target}) {
if (oldValue.includes('position: absolute') && target.style.position === 'relative') {
$symbolButton.style.position = 'absolute';
relativeFound = true;
}
});
if (relativeFound) {
observer.disconnect();
}
});
observer.observe($symbolButton, { attributeOldValue: true });
... |
Would it be possible to create a codePen / CodeSandbox example of this issue? |
i can't at the moment because it's a pretty big project and extracting this specific part into a codepen would be time-consuming but my description above is pretty straightforward, your script is forcing all elements within the split text to be relatively positioned but i need only one of those elements to remain absolutely positioned which is why i can't use the "absolute: true" setting. this setting breaks my entire layout by adding even more inline css. my proposed solution is to only add the inline my headlines start like this: Headline Text & Asteriskand end up like this where the asterisk is a button: Headline Text & Asterisk*Adding the inline styles to my examples so it's a little clearer?
<h2>headline text & <span style="position: relative;">asterisk</span>.</h2>
<h2>headline text & <span style="position: relative;">asterisk <button style="position: absolute;">*</button></span>.</h2>
<div style="overflow: hidden;">
<div class="line">Headline text & </div>
</div>
<div style="overflow: hidden;">
<div class="line">
<span style="position: relative;">asterisk <button style="position: relative;">*</button></span>
</div>
</div> |
@eballeste several other people have requested this. I am working on a PR that will make it possible to set the display or position of nested elements inside the target element. Follow #69 for updates |
I have a global script that automatically adds a dynamic button to headline texts based on whether a nested span element within the headline has a specific target class. This dynamically inserted button is absolutely positioned relative to the span element.
Example markup:
Example markup after my script runs:
My script works beautifully except for animated headlines that use the splittype library. An extra space is added in between my button and the
span
wrapped text. After digging into it I noticed that it was this SplitType library that changes my button from an absolute to a relative positioned button. I tried using theabsolute: true
setting but this just breaks the layout even more since SplitType then injects more style attributes to the button which causes even more conflicts with my style rules from my original script.I was wondering would it be possible to modify SplitType so that it does a check for any inline styles before forcing the div to be relatively positioned?
something like (untested pseudocode):
split.js
The text was updated successfully, but these errors were encountered: