Giter VIP home page Giter VIP logo

Comments (10)

chrisdavidmills avatar chrisdavidmills commented on May 16, 2024

@WDGroll does background-size: 100% 100%; help here?

Have you got a version of your example in a live code editor (e.g. codepen), or even just on a server somewhere that I can play with?

from content.

WDGroll avatar WDGroll commented on May 16, 2024

No,
background-size: 100% 100%;
doesn't help. Looks it scales to it's parent element, not to the size of the viewport.

I created a tiny example for testing:

example-3159.zip

from content.

chrisdavidmills avatar chrisdavidmills commented on May 16, 2024

Hrm. I've just played around with this a whole load, and can't get to what you are hoping for.

The closest I can get is

html {
  height: 100%;
  background-image:url("./rainbow.svg");
  background-repeat: no-repeat;
  background-size: 100% auto;
}

But that only gives you the effect in the width direction. It fails with a narrow viewport.

It looks like Chrome behaves the same, leading me to think maybe it was a spec change?

from content.

WDGroll avatar WDGroll commented on May 16, 2024

Well, it worked in the past, and I don't know whether there was a specification change since then.

Maybe I misinterpret the specifications.
https://www.w3.org/TR/css-values-3/ ยง 5.1 or
https://www.w3.org/TR/css-values-4/ ยง 6.1.2.
According to this, 100vw and 100vh should be exactly the size of the viewport.

Is there any other way to achieve this only in CSS without using Javascript?
example-3159-v2.zip

from content.

chrisdavidmills avatar chrisdavidmills commented on May 16, 2024

I wonder if @rachelandrew has an idea about a solution for this one?

from content.

Ryuno-Ki avatar Ryuno-Ki commented on May 16, 2024

According to this, 100vw and 100vh should be exactly the size of the viewport.

I was about to suggest just this.

Is this about applying a user stylesheet (which would apply to all webpages) or only for a specific website (htdocs/index.html makes me think of a locally running Apache web server).

from content.

rachelandrew avatar rachelandrew commented on May 16, 2024

Seems to work fine with an image, so I'm not sure why not with the SVG.

https://codepen.io/rachelandrew/pen/cb98439b1f485cd33c55a582da973dd4

from content.

rachelandrew avatar rachelandrew commented on May 16, 2024

Oh. I just had a thought.

You need `preserveAspectRatio="none" on your SVG.

https://codepen.io/rachelandrew/pen/6be905fc1f68875f5d8ac64c5ce06c0a

@chrisdavidmills @WDGroll

from content.

chrisdavidmills avatar chrisdavidmills commented on May 16, 2024

@rachelandrew nice, thanks Rachel!

from content.

rachelandrew avatar rachelandrew commented on May 16, 2024

I was trying to see where this info could be added, and found this: https://developer.mozilla.org/en-US/docs/Web/CSS/Scaling_of_SVG_backgrounds

So maybe I'll add it as a note.

from content.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.