A
A
Artem Skopintsev2016-04-09 19:54:32
css
Artem Skopintsev, 2016-04-09 19:54:32

Flexbox: Why is child element resized and how to fix it?

Good time of the day.
Learning Flexbox, ran into a problem. I divide the container into three parts using the flex-grow property . Code:
HTML:

<section class="top-nav">
        <div class="part1">
            <img src="img/logo.svg" alt="Logo">
        </div>
        <div class="part2">

        </div>
        <div class="part3">

        </div>
</section>

CSS:
.top-nav {
        display: flex;
}

.part1 {
        flex-grow: 1
}
.part2 {
        flex-grow: 2
}
.part3 {
        flex-grow: 1
}

Blocks are placed and stretched exactly as I need. But the problem arose when I inserted the image into the block (part1) . He expanded, which I do not need at all.
How to fix it?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem Skopintsev, 2016-04-09
@SharperX

I got to the bottom of the solution to the problem and it all consisted only in the fact that I did not read up about the properties of Flexbox. I know, sinner, sorry to bother you. However, maybe it will save someone :)
Solution: instead of the flex-grow property, you need to use the flex property

M
Mikhail, 2016-04-22
Chirskiy @chirskiy_mixail

You better learn what Flex does, and then the questions will disappear, Flex replaces 3 values ​​flex-grow, flex-shrink and flex-basis, in your case, you lacked exactly flex-basis

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question