Использование Display Flex для сохранения ориентации - PullRequest
0 голосов
/ 13 февраля 2020

в настоящее время у меня есть этот макет сетки, когда я в масштабе 100%.

Layout

Когда я go до 150% масштаба, я получаю это как мой макет:

enter image description here

Однако, когда я масштабирую go до 150%, это идеальный макет, который я хочу:

enter image description here

Ниже приведен мой код:


<html>

<head>
    <script type="text/javascript"> </script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</head>
<style>
    * {
        font-family: sans-serif;
        font-size: 1.4em;   
    }

    .container {
        height: 400px;

    }

    .row {
        display: flex;
        padding: 0;
        margin: 0;
    }

    .box {
        display: flex;
        flex-direction: row;
        width: 200px;   
        height: 100px;
        margin: 1px;
        padding: 10px;
        background-color: purple;
        color: white;
    }

    </style>

    <section class="container">
        <div class="row">
            <div class="box box1">One</div>
            <div class="box box2">Two</div>
            <div class="box box3">Three</div>
            <div class="box box4">Four</div>
            <div class="box box5">Five</div>
        </div>

        <div class="row">
            <div class="box box6">Six</div>
            <div class="box box7">Seven</div>
            <div class="box box8">Eight</div>
            <div class="box box9">Nine</div>
            <div class="box box10">Ten</div>
        <div class="row"></div>
        </section>


</body>
</html>

Я не уверен, что мне нужно изменить, чтобы получить нужный макет. Я использую дисплей: flex для этого

Ответы [ 2 ]

0 голосов
/ 13 февраля 2020

Поместите свои ящики в один ряд

 * {
        font-family: sans-serif;
        font-size: 1.4em;   
    }

    .container {
        height: 400px;
    }

    .row {
        display: flex;
        padding: 0;
        margin: 0;
    }

    .box {
        display: flex;
        flex-direction: row;
        width: 200px;   
        height: 100px;
        margin: 1px;
        padding: 10px;
        background-color: purple;
        color: white;
    }
<html>
<head>
    <script type="text/javascript"> </script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</head>

    <section class="container">
        <div class="row">
            <div class="box box1">One</div>
            <div class="box box2">Two</div>
            <div class="box box3">Three</div>
            <div class="box box4">Four</div>
            <div class="box box5">Five</div>
            <div class="box box6">Six</div>
            <div class="box box7">Seven</div>
            <div class="box box8">Eight</div>
            <div class="box box9">Nine</div>
            <div class="box box10">Ten</div>
      </div>
   </section>
</html>
0 голосов
/ 13 февраля 2020

Просто используйте медиа-запросы в em в вашем css:

.box {
    flex-wrap: wrap;
}
@media (max-width: 75em) {
    .box {
        flex-basis: 20%;
    }
}

@media (min-width: 76em) {
    .box {
        flex-basis: 25%;
    }
}

Источник

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...