Я хочу иметь 4 столбца, как показано ниже на скриншоте, с полями вокруг них. Каждый из них col-md-6 с запасом 0,5%. Однако это поле изначально приводит к тому, что столбцы переходят на следующую строку. Я знаю, что нет опции поля поля, подобного рамке поля ... Моим текущим решением было изменить свойство flex из:

flex: 0 0 0 50%;

Кому:

flex: 0 0 0 49%;

Чтобы добавить маржу, я добавил ... Однако, это не работает в Internet Explorer.

.services_content,
.services_image {
  border-radius: 20px;
  margin: .5%;
  flex: 0 0 49%;
}
<div class="row">
  <div class="order-sm-0 order-md-1 col-md-6 services_image_1 services_image" style="background: url('<?php echo $servicesImgLink_1;?>">
    <h2 class="service_img_heading">
      <?php the_field('services_heading_1'); ?>
    </h2>
  </div>
  <div id="services_content_1" class=".order-sm-1  .order-md-0 col-md-6 services_content_1 services_content">
    <p>
      <?php the_content(); ?>
    </p>
  </div>
</div>

Каков наилучший способ получить этот полноэкранный вид с небольшим запасом вокруг этих 4 столбцов?

enter image description here

1
JakeFromStateFarm 19 Дек 2019 в 01:34

2 ответа

Примерно так будет работать. Но сейчас я пытаюсь понять, как получить равные места.

.block {
  background: url('https://gmsrp.cachefly.net/images/19/12/18/135acb4a87157a536a861995694f7b79/320.jpg');
  border-radius: 5px;
  height: 120px;
  margin: 10px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<div class="container">
  <div class="row">
    <div class="col-6">
      <div class="block">

      </div>
    </div>
    <div class="col-6">
      <div class="block">

      </div>
    </div>
    <div class="col-6">
      <div class="block">

      </div>
    </div>
    <div class="col-6">
      <div class="block">

      </div>
    </div>
  </div>
</div>
1
Dhaval Jardosh 18 Дек 2019 в 22:53

Базовая структура grid, использующая flex, а также отзывчивая.

body {
  color: #404040;
  font: 100 1em/150% "proxima-nova", Helvetica, sans-serif;
}

.wrapper {
  max-width: 1200px;
  margin: auto;
}

h1, h2, h3, h4 {
  font-weight: 900;
  color: #333;
  margin: 1.5em 0 0.5em;
}

h1 {
  font-size: 2em;
}

h2 {
  font-size: 1.8em;
}

h3 {
  font-size: 1.5em;
}

h4 {
  font-size: 1.3em;
}

strong {
  font-weight: 600;
}

hr {
  border: none;
  height: 1px;
  background-color: rgba(51, 153, 204, 0.2);
}

.img-placeholder {
  background-image: url("http://placehold.it/200x100/CC99CC/ffffff&text=Feature");
  background-size: cover;
  min-height: 100px;
  min-width: 100px;
}

/*Basic Grid Styles*/
.Grid {
  display: flex;
  flex-flow: row;
  flex-wrap: wrap;
}

.u-textCenter {
  text-align: center;
}

.Grid-cell {
  flex: 1;
}

.Demo {
  padding: .8em 1em 0;
  margin-bottom: 1em;
  background: rgba(51, 153, 204, 0.2);
  transition: background-color 0.3s ease;
  border: 1px solid #33cccc;
  border-radius: 3px;
}
.Demo:after {
  content: "";
  display: block;
  margin-top: .8em;
  height: 1px;
}
.Demo:hover {
  background: rgba(51, 153, 204, 0.6);
}

.Demo.Holly {
  background: rgba(102, 51, 255, 0.1);
}
.Demo.Holly:hover {
  background: rgba(102, 51, 255, 0.25);
}

/* With gutters*/
.Grid--gutters {
  margin-left: -1em;
}
.Grid--gutters .Grid-cell {
  padding-left: 1em;
}
.Grid--gutters .Grid--nested .Grid-cell:first-of-type .Demo {
  margin-right: 1em;
}

/* Justify per row*/
.Grid--right {
  justify-content: flex-end;
}

.Grid--center {
  justify-content: center;
}

/* Alignment per row */
.Grid--top {
  align-items: flex-start;
}

.Grid--bottom {
  align-items: flex-end;
}

.Grid--center {
  align-items: center;
}

/* Alignment per cell */
.Grid-cell--top {
  align-self: flex-start;
}

.Grid-cell--bottom {
  align-self: flex-end;
}

.Grid-cell--center {
  align-self: center;
}

.navigation {
  list-style: none;
  /*background: deepskyblue;*/
  background: rgba(102, 51, 255, 0.1);
  margin: 0 0 1em;
  border: 1px solid #33cccc;
  border-radius: 3px;
  display: flex;
  -webkit-flex-flow: row wrap;
  justify-content: flex-end;
}
.navigation a {
  text-decoration: none;
  display: block;
  padding: 1em;
  color: #333;
}
.navigation a:hover {
  background: rgba(64, 0, 255, 0.1);
  border-radius: 3px;
}
.navigation:hover {
  background: rgba(102, 51, 255, 0.25);
}

@media all and (max-width: 800px) {
  .navigation {
    justify-content: space-around;
  }
}
@media all and (max-width: 600px) {
  .navigation {
    -webkit-flex-flow: column wrap;
    flex-flow: column wrap;
    padding: 0;
  }
  .navigation a {
    text-align: center;
    padding: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  }
  .navigation li:last-of-type a {
    border-bottom: none;
  }
}
/*===========================================*/
/* Base classes for all media - Mobile first */
.Grid--cols-2 > .Grid-cell {
  flex: 0 0 100%;
}

.Grid--cols-3 > .Grid-cell {
  flex: 0 0 100%;
}

.Grid--cols-4 > .Grid-cell {
  flex: 0 0 100%;
}

.Grid--cols-6 > .Grid-cell {
  flex: 0 0 calc(50% - 1em);
}

.Grid--cols-12 > .Grid-cell {
  flex: 0 0 calc(33.3333% - 1em);
}

.Grid--holly-grail .aside, .Grid--holly-grail .main {
  flex: 1 100%;
}

/* One of -- columns*/
.Grid--1of2 > .Grid-cell,
.Grid--1of4 > .Grid-cell:first-of-type,
.Grid--1of3 > .Grid-cell:first-of-type {
  flex: 0 0 100%;
}

.Grid--1of6 > .Grid-cell:first-of-type {
  flex: 0 0 50%;
}

.Grid--fit > .Grid-cell {
  flex: 1;
}

.Grid--full > .Grid-cell {
  flex: 0 0 100%;
}

/* Tablet (medium) screens */
@media (min-width: 30em) {
  .Grid--cols-4 > .Grid-cell {
    flex: 0 0 calc(50% - 1em);
  }

  .Grid--cols-6 > .Grid-cell {
    flex: 0 0 calc(33.3333% - 1em);
  }

  .Grid--cols-12 > .Grid-cell {
    flex: 0 0 calc(16.6666% - 1em);
  }

  .Grid--holly-grail .aside {
    flex: 1 calc(25% - 1em);
  }

  .Grid--1of2 > .Grid-cell {
    flex: 0 0 50%;
  }

  .Grid--1of6 > .Grid-cell:first-of-type {
    flex: 0 0 30%;
  }

  .Grid--1of4 > .Grid-cell:first-of-type {
    flex: 0 0 50%;
  }

  .Grid--1of3 > .Grid-cell:first-of-type {
    flex: 0 0 100%;
  }
}
/* Large screens */
@media (min-width: 48em) {
  .Grid--cols-2 > .Grid-cell,
  .Grid--cols-3 > .Grid-cell,
  .Grid--cols-4 > .Grid-cell,
  .Grid--cols-6 > .Grid-cell,
  .Grid--cols-12 > .Grid-cell {
    flex: 1;
  }

  .Grid--holly-grail .main {
    flex: 2;
  }
  .Grid--holly-grail .aside {
    flex: 1;
  }
  .Grid--holly-grail .aside-1 {
    order: 1;
  }
  .Grid--holly-grail .main {
    order: 2;
  }
  .Grid--holly-grail .aside-2 {
    order: 3;
  }

  .Grid--1of2 > .Grid-cell {
    flex: 0 0 50%;
  }

  .Grid--1of6 > .Grid-cell:first-of-type {
    flex: 0 0 16.6666%;
  }

  .Grid--1of4 > .Grid-cell:first-of-type {
    flex: 0 0 25%;
  }

  .Grid--1of3 > .Grid-cell:first-of-type {
    flex: 0 0 30%;
  }

  .Grid--gutters.Grid--nested .Grid-cell:first-of-type .Demo {
    margin-right: 0;
  }
}
.content-1of1::before {
  content: "1";
}

.content-1of2::before {
  content: "1/2";
}

.content-1of3::before {
  content: "1/3";
}

.content-1of4::before {
  content: "1/4";
}

.content-1of6::before {
  content: "1/6";
}

.content-1of12::before {
  content: "1/12";
}
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Flexbox responsive grid</title>
</head>
<body>
  <div class="wrapper">
    <p>Responsive grid with Flexbox</p>
  <h1>Basic Grid</h1>
    <p></p>
  <div class="Grid Grid--full u-textCenter">
    <div class="Grid-cell"><div class="Demo content-1of1"></div></div>
  </div>
  <div class="Grid Grid--gutters Grid--cols-2 u-textCenter">
    <div class="Grid-cell"><div class="Demo content-1of2"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of2"></div></div>
  </div>
  <div class="Grid Grid--gutters Grid--cols-3 u-textCenter">
    <div class="Grid-cell"><div class="Demo content-1of3"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of3"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of3"></div></div>
  </div>
  <div class="Grid Grid--gutters Grid--cols-4 u-textCenter">
    <div class="Grid-cell"><div class="Demo content-1of4"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of4"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of4"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of4"></div></div>
  </div>
  <div class="Grid Grid--gutters Grid--cols-6 u-textCenter">
    <div class="Grid-cell"><div class="Demo content-1of6"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of6"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of6"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of6"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of6"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of6"></div></div>
  </div>
    
  <div class="Grid Grid--gutters Grid--cols-12 u-textCenter">
    <div class="Grid-cell"><div class="Demo content-1of12"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of12"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of12"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of12"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of12"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of12"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of12"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of12"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of12"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of12"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of12"></div></div>
    <div class="Grid-cell"><div class="Demo content-1of12"></div></div>
  </div>  
  
 </div>
</body>
</html>
0
Awais 19 Дек 2019 в 09:22