K
K
Kostiantyn Kondratiuk2021-05-29 00:34:01
css
Kostiantyn Kondratiuk, 2021-05-29 00:34:01

SVG background - how to make it responsive?

The landing page has several sections with a background written like this:

.about-me {
    background-image: url(/img/back_2_section.svg);
    background-position: top;
    padding-top: 184px;
    padding-bottom: 145px;
}


But when I started to make an adaptive background, it does not behave adaptively .
At high resolution:
60b16060157ff269583944.jpeg

When I reduce:

60b16125b128d915351957.jpeg

Maybe I'm not registering the background itself in the right way?
Please share the correct solution.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Ankhena, 2021-05-29
@Kinderman

Background images are adapted using background-size
Or block resizing. For example, they are inserted as a background of a pseudo element and then adjust the size of the pseudo, and the background is set to contain, cover or 100% (or not 100)
The only difference between a raster and SVG is that a raster changes its proportions, while SVG usually does not.
To change the proportions of SVG, it must have an attribute preserveAspectRatio
Here are examples
https://jsfiddle.net/0xrh6uvj/ - change the width of the window with the result
----
But you did not make a sandbox on jsfiddle.net with your problematic code and it is not clear that at all you are doing there.

K
kryamk, 2021-05-29
@kryamk

And it seems to me that the matter is not in the background, but in the fact that the block with the background is compressed. Remove all blocks (right in the task manager), except for the one with the background and see why it shrinks. You can also set a border or outline for a block with a background so that you can see its borders

A
Alexey Dubrovin, 2021-05-29
@alekcena

Learn

S
Sergey Levchenko, 2021-05-29
@Levchenski

background-repeat: no-repeat;
background-size: cover;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question