D
D
Drovosek012018-09-21 16:48:36
css
Drovosek01, 2018-09-21 16:48:36

How to make "dynamic" padding?

I'm learning to typeset...
I made a block, placed elements in it, set padding to the block.
The problem is that when I change the width of the window in dev-tools, at a certain moment the pictures start to "climb out" to the right, and then completely go off the screen.
5ba4f6a97b166716375465.png
Yes, this problem can be solved with media queries, but they kind of hard-code the padding.
I would like that when the window width decreases, when the content does not fit into the container frame, then the content either runs over the padding, or the padding decreases.
Here is a sample code: https://codepen.io/Drovosek/pen/MqxONW

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2018-09-21
@Drovosek01

How to properly layout a content container:

.container {
  width: calc(100% - 32px);  // отступ по 16px в случае если страница <= 1024px
  max-width: 1024px;  // размер для примера
  margin: 0 auto;
}

max-width can be set to 100% and directly set padding, of course to width + 32px
.container {
  width: 100%;
  max-width: 1056px;
  margin: 0 auto;
  padding: 0 16px;
}

N
Nikita-Fast, 2018-09-21
@Nikita-Fast

https://codepen.io/topicstarter/pen/NLJyQa?editors=1100
here I did not fix the layout, but slightly corrected css - added three lines

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question