Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Media queries vs. svelte:window innerWidth - Which one is better way to build a responsive UI in svelte? [closed]

$
0
0

While building a responsive webpage using sveltekit, I found two ways to render different UIs depending on the device width: media queries and bind:innerWidth with svelte:window.

Media query seems to be used very widely in web UI development. According to the device width we set the css display property none or the others. With display: none, the element disappears from the view.

The other way is using <svelte:window bind:innerWidth />. In this way we can bind the window size to a variable and then use the value in <script>. Then we can conditionally render elements using if blocks.

So I got a question. Which way is better in two aspects: optimization and clean code? Considering more details we have numerous ways to build the responsive design, and which way would you choose to achieve this?


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>