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

Calculated CSS unit #12129

Open
Sonnenuntergang opened this issue Jun 21, 2024 · 2 comments
Open

Calculated CSS unit #12129

Sonnenuntergang opened this issue Jun 21, 2024 · 2 comments

Comments

@Sonnenuntergang
Copy link

Describe the problem

I really like svelte but there's one thing that gets on my nerves. I prefer creating my own components and not using a framework. When I want for example the border radius to be half of the height of the element, I have to manually create a JS function to calculate this.

Describe the proposed solution

I would like to have a custom css unit that is removed from CSS and added as a JS function which adds a style attribute. An example:

element {
   border-radius: 50rh;
}

That would mean half of the height of an element (rh for 'real height').
I imagine a compiled solution like this:

<element bind:this={ node } style=`border-radius: { node.offsetHeight * 0.5 }` />

Importance

would make my life easier

@adminy
Copy link

adminy commented Jun 21, 2024

Technically svelte is a framework ... component libraries like daisy UI are a life saver actually ... but ok.

I think this would work in css for what you're trying to do:

element {
   border-radius: 9999px;
}

@Sonnenuntergang
Copy link
Author

@adminy Thank you for your answer. That's a good solution. I've thought about any other use case for a unit like this but couldn't find one where it would be more elegant than with just normal CSS.

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

2 participants