-
Notifications
You must be signed in to change notification settings - Fork 38
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
Allow users to override the display and position style on nested elements #69
Comments
I will follow up with a more detailed response later. briefly, those two styles are required for the library to work. Block level html elements are not supported inside the target elements. It only supports inline block elements inside the target element. As a potential alternative, you can target each of the block level elements that contain the text content, instead of targeting their parent container. https://codepen.io/lukePeavey/pen/xxMjevw <h2>
<span>Lorem ipsum</span>
<span>without the split plugin<span>
</h2> SplitType.create("h2 span", { types: 'words' }); |
Hi Luke, Thanks for the reply! Those styles are required during calculations then? Would it at least be possible to assign a class to it so it would be possible to apply styling; even if it needs Unfortunately I do not have any control over the markup at this point. So I have to do it all with JS / CSS at the moment so I'll try to come up with an alternative fix for now :-) Alrighty, keep up the great work! |
I took a look at the code. I think we can figure out a way to support what your asking for... first, its not necessary for the library set Other display values are not supported and will likely break the visual appearance of the text and/or cause unexpected results. This includes Anyway, I agree that people should be able to set the display style themselves to best suit their needs. The other property is a bit trickier. Nested elements inside the target elements need to have In most cases, this should be set to relative. I'm not sure if the library will work as expected if the target element contains a child element that is absolutely positioned. But we can provide an option so people can override this style if people want to try this. I will think about how to implement this, just wanted to give you a quick update |
Great to hear, and thanks for the update :-) Of course; line splitting is a little different in that regard. And yeah, As for <h1>
<svg>...</svg>
Title
</h1> Where the svg has And of course, some things just aren't possible, at least not in a way while keeping the code light enough for the majority of use-cases 👍 |
Yeah that makes sense. The svg icon is a good example. A few options... These would all be pretty easy to implement. Let me know what you think, or if you have other suggestions.
.myAbsoluteElement {
--splitType-nestedElementPosition: absolute;
// ... styles
}
.myBlockElement {
--splitType-nestedElementDisplay: block;
// ... styles
}
|
Option 1I like this idea since it gives the plugin the possibility to work correctly but also gives the developer options to overwrite. However a big downside might be that you get unexpected results since the existing class might have higher specificity for display like Option 2Quite like this as well. Would you assign these in a global Option 3I guess this is the behavior that I expected originally. However if you say that both the ConclusionI think option 1 would be the best option. Added as an optional setting so the core plugin just works as expected. When enabling you get the class names instead of inline styling which can then be easily overwritten (just make sure you keep the lowest specificity possible) while making sure the plugin functions just fine in 90% of the cases (when there's no The code for option 1 could be (121 characters, including override): <div class="classname"></div> .classname {
position: relative;
display: inline-block;
} Override: .my .classname {
display: block;
} The code for option 1 could be (204 characters, including override): <div style="position: var(--splittype-position); display: var(--splittype-display);"></div> :root {
--splittype-position: relative;
--splittype-display: inline-block;
} Override .my {
--splittype-display: block;
} Seeing this written out, it doesn't make such a big difference. It's also depending on what the class name is going to be and what the custom properties are going to be named. All you can say about it now is that option 1 might look a little cleaner in devtools since it's just the classname. But option 2 is a little bit more modern if you're into that :) |
Sounds good to me, let's go with option 1. I am working on another PR to update the dev dependencies. I will merge that before we start on this. If you are interested in working on this feel free to submit a PR |
Awesome! And I would if I thought I could, but the JS you wrote is a bit above my skill level ;) I'm mostly a designer / markup / CSS guy that writes (and copy-pastes) a little bit of JavaScript every now and then :) |
No worries! I should be able to get this done pretty soon. |
Hey there, great plugin!
I did run into a little issue though which might be fixable?
When another element is being found you make sure to preserve that element; which is great. However the fact that splitType is giving these elements inline styling for display and position is a bit less great ;) These elements also don't get any classname so we can't override them with
!important
(not that we want that, but even this is not an option).Here's a quick codepen illustrating the issue:
https://codepen.io/robinpoort/pen/mdvLaKW
As you can see, the span element inside the h2 get
display: inline-block
andposition: relative
applied to it. Even if the span has a class that has other values (the second example), these values will simply be overwritten. In my case (the real project i'm working on) the span can't even have a class since the headings are coming from a system I have little control over :(I can think of a few possible solutions:
position: relative; display: inline-block;
so this class is easily overwriteable. This solution would not be optimal since you can't target individual instances on the page this way.types
option add a 'inline-styleoption where you can assign a list like
inline-block, relative(the default) but also
inline, staticor
block, sticky` for example. This would be a nice addition since you can style different instances on the page accordingly.!important
to override the default behavior. Either that; or remove the inline styling when a custom class is set so you can set your own.Would any of the above even be possible?
Not sure if this is clear or not. Let me know if you need more explanation or examples :-)
The text was updated successfully, but these errors were encountered: