Как сделать так, чтобы дочерняя сетка была полной ширины экрана независимо от сетки? - PullRequest
0 голосов
/ 05 ноября 2019

Мне нужна помощь для следующего:

Я использую сетку в div "small-container", когда размер экрана ниже 768 пикселей, я хочу, чтобы один из его дочерних элементов ("vod-player") могберут полную ширину экрана, а не ширину 8 столбцов сетки, в то время как другие дочерние элементы будут охватывать 8 столбцов.

index.html:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Wireframe</title>
    <link rel="stylesheet" type="text/css" href="./style.css">
</head>
<body>
    <div class="big-container">
        <div class="header">Header</div>


        <div class="small-container"> 

            <div class=vod-player>Vod Player 16x9 8cols</div>

            <div class=highlights>Highlights 4cols, height=vodplayer height</div>
            <div class=video-information>
                <div class="video-name">Video Name</div>
                <div class="details-section">Details Section</div>
            </div>
            <div class=feedback>Feedback</div>
            <vr class=rule>
        </div>


        <div class="footer">2019</div> 

    </div>
</body>
</html> 

style.css:

/* html {
  margin: 0;
  border: 2px solid black;
  height: 100%;
}
body {
  margin: 0;
  border: 2px solid yellow;
  height: 100%;
} */
.big-container {
  max-width: 1920px;
  border: 2px solid red;
  width: 100%;
  margin: 0 auto;
}
.header {
  width: 100%;
  max-width: 1920px;
  height: 54px;
  border: 2px solid red;
  margin: 0;
  margin-bottom: 24px;
  background-color: #263238;
}
.small-container {
  display: grid;
  /* max-width:1800px; */
  max-width:95%; 
  margin: auto;  

  grid-column-gap: 30px;
  grid-row-gap: 24px;
  margin-right: 60px;
  margin-left: 60px;
  grid-template-columns: repeat(12, 1fr);
  grid-template-rows: auto auto auto;
  border: 2px solid red;
  /* grid-auto-rows: 766px; */
}
.vod-player {
  grid-area: vodplayer;
  max-height: 715px;
  border: 2px solid red;
  grid-column-start: 1;
  grid-column-end: 9;
  grid-row-start: 1;
  grid-row-end: 2;
  padding-top: 56.25%;
  background-color: #f4511e;
}
.highlights {
  grid-area: highlights;
  max-height: 715px;
  border: 2px solid purple;
  grid-column-start: 9;
  grid-column-end: 13;
  grid-row-start: 1;
  grid-row-end: 2;
  background-color: #546e7a;
}
.video-information {
  grid-area: info;
  max-height: 333px;
  border: 2px solid green;
  grid-column-start: 1;
  grid-column-end: 9;
  grid-row-start: 2;
  grid-row-end: 3;
  background-color: #4caf50;

  display: grid;
  grid-column-gap: 24px;
  grid-row-gap: 24px;
  margin-right: 0px;
  margin-left: 0px;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: auto auto;
  border: 2px solid red;

  /* margin-bottom: 80px; */
}
.video-name {
  grid-column-start: 1;
  grid-column-end: 9;
  grid-row-start: 1;
  grid-row-end: 2;
  height: 66px;
  border: 1px solid green;
}
.details-section {
  grid-column-start: 1;
  grid-column-end: 9;
  grid-row-start: 2;
  grid-row-end: 3;
  height: 243px;
  border: 1px solid green;
}
.feedback {
  height: 214px;
  grid-area: feedback;
  /* max-width: 580; */
  max-height: 214;
  grid-column-start: 9;
  grid-column-end: 13;
  border: 2px solid pink;
  grid-row-start: 2;
  grid-row-end: 3;
  background-color: #00bcd4;
}
.footer {
  height: 17px;
  width: 285px;
  color: #1c1c1d;
  font-family: "Proxima Nova";
  font-size: 14px;
  font-weight: 300;
  line-height: 17px;
  margin: auto;
  text-align: center;
  border: 2px solid red;
}
vr {
  grid-area: rule;
  grid-column-start: 1;
  grid-column-end: 9;
  grid-row-start: 3;
  grid-row-end: 4;
  margin-top: 16px;
  margin-bottom: 40px;
  box-sizing: border-box;
  height: 1px;
  width: 100%;
  border: 1px solid #cbd2da;
}

@media (max-width: 1440px) {
  .small-container {
    grid-column-gap: 30px;
    margin-right: 60px;
    margin-left: 60px;
  }
}
@media (max-width: 1280px) {
  .small-container {
    grid-column-gap: 30px;
    margin-right: 30px;
    margin-left: 30px;
  }
}
@media (max-width: 1024px) {
  .small-container {
    grid-column-gap: 30px;
    margin-right: 30px;
    margin-left: 30px;
  }
}
@media (max-width: 960px) {
  .small-container {
    grid-column-gap: 30px;
    margin-right: 30px;
    margin-left: 30px;
  }
}
@media (max-width: 768px) {
  .header {
    display: none;
  }
  .small-container {
    grid-column-gap: 30px;
    grid-row-gap: 0px;
    margin-right: 30px;
    margin-left: 30px;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: auto auto auto auto auto;
  }
  .vod-player {
    grid-column-start: 1;
    grid-column-end: 9;
    grid-row-start: 1;
    grid-row-end: 2;
  }
  .highlights {
    grid-column-start: 1;
    grid-column-end: 9;
    grid-row-start: 2;
    grid-row-end: 3;
  }
  .video-information {
    grid-column-start: 1;
    grid-column-end: 9;
    grid-row-start: 3;
    grid-row-end: 4;
    margin-bottom: 0px;
  }
  .feedback {
    grid-column-start: 1;
    grid-column-end: 9;
    grid-row-start: 4;
    grid-row-end: 5;
  }
  .rule {
    grid-column-start: 1;
    grid-column-end: 9;
    grid-row-start: 5;
    grid-row-end: 6;
  }
  vr {
    margin-top: 20px;
    margin-bottom: 20px;
  }
}
@media (max-width: 360px) {
  .header {
    display: none;
  }
  .small-container {
    grid-column-gap: 20px;
    margin-right: 20px;
    margin-left: 20px;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: auto auto auto auto auto;
  }
  .vod-player {
    grid-column-start: 1;
    grid-column-end: 5;
    grid-row-start: 1;
    grid-row-end: 2;
  }
  .highlights {
    grid-column-start: 1;
    grid-column-end: 5;
    grid-row-start: 2;
    grid-row-end: 3;
  }
  .video-information {
    grid-column-start: 1;
    grid-column-end: 5;
    grid-row-start: 3;
    grid-row-end: 4;
  }
  .feedback {
    grid-column-start: 1;
    grid-column-end: 5;
    grid-row-start: 4;
    grid-row-end: 5;
  }
}

ожидаемый результат:

выше 768px: (синяя полоса - "vod-player" и оранжевые "блики"). Сетка: https://ibb.co/dtHdvt2

ниже 768px: сетка: https://ibb.co/DfN83mC

1 Ответ

0 голосов
/ 05 ноября 2019

Попробуйте. С этим кодом, надеюсь, это поможет.

Файл CSS:

html {
  margin: 0;
  border: 2px solid black;
}
body {
  margin: 0;
  border: 2px solid black;
}
.big-container {
  max-width: 1920px;
  border: 2px solid red;
  width: 100%;
}
.header {
  width: 100%;
  max-width: 1920px;
  height: 54px;

  border: 2px solid red;
  margin: 0;
  margin-bottom: 24px;
}
.small-container {
  display: grid;
   max-width:95%;         // Newly added
  grid-column-gap: 30px;
  grid-row-gap: 24px;
  margin: auto;           // Newly added
  grid-template-columns: repeat(12, 1fr);
  border: 2px solid red;
  grid-auto-rows: 766px;
}
.vod-player {
  grid-area: vodplayer;
  max-height: 715px;
  border: 2px solid red;
  grid-column-start: 1;
  grid-column-end: 9;
  grid-row-start: 1;
  grid-row-end: 2;
}
.highlights {
  grid-area: highlights;
  /* max-width: 580px; */
  max-height: 715px;

  border: 2px solid red;
  grid-column-start: 9;
  grid-column-end: 13;
  grid-row-start: 1;
  grid-row-end: 2;
}
.video-information {
  grid-area: info;
  max-height: 333px;
  border: 2px solid red;
  grid-column-start: 1;
  grid-column-end: 9;
  grid-row-start: 2;
  grid-row-end: 3;
}
.feedback {
  grid-area: feedback;
  max-height: 214;
  grid-column-start: 9;
  grid-column-end: 13;
  border: 2px solid red;
  grid-row-start: 2;
  grid-row-end: 3;
}
.footer {
  height: 17px;
  width: 285px;
  color: #1c1c1d;
  font-family: "Proxima Nova";
  font-size: 14px;
  font-weight: 300;
  line-height: 17px;
  margin: auto;
  text-align: center;
  border: 2px solid red;
}

@media (max-width: 768px) {
  .small-container {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr;
    grid-row-gap: 0px;
    grid-template-areas:
      "vodplayer"
      "highlights"
      "info"
      "feedback";
  }
  .vod-player {
    grid-column-start: 1;
    grid-column-end: 2;
    grid-row-start: 1;
    grid-row-end: 2;
    margin-bottom: 0;
  }
  .highlights {
    grid-column-start: 1;
    grid-column-end: 2;
    grid-row-start: 2;
    grid-row-end: 3;
    margin-bottom: 0;
  }
  .video-information {
    grid-column-start: 1;
    grid-column-end: 2;
    grid-row-start: 3;
    grid-row-end: 4;
    margin-bottom: 0;
  }
  .feedback {
    grid-column-start: 1;
    grid-column-end: 2;
    grid-row-start: 4;
    grid-row-end: 5;
    margin: 0;
  }
}
@media (max-width: 360px) {
  .small-container {
    grid-template-columns: repeat(4, 1fr);
  }
  .vod-player {
    grid-column-start: 1;
    grid-column-end: 5;
    grid-row-start: 1;
    grid-row-end: 2;
    margin-bottom: 0;
  }
  .highlights {
    grid-column-start: 1;
    grid-column-end: 5;
    grid-row-start: 2;
    grid-row-end: 3;
    margin-bottom: 0;
  }
}

Файл HTML:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Wireframe</title>
    <link rel="stylesheet" type="text/css" href="./style.css">
</head>
<body>
    <div class="big-container">
        <div class="header"></div>
        <div class="small-container"> 
            <div class=vod-player></div>
            <div class=highlights></div>
            <div class=video-information></div>
            <div class=feedback></div>
        </div>
        <div class="footer">2019</div> 
    </div>
</body>
</html>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...