我从https://www.layoutit.com/grid#clear为我的网页创建了一个布局。
javascript - 如何将内容放入布局-LMLPHP

但是我想在框的中间删除这些文本。我尝试了一些东西但不幸的是没有用。



html, body { margin: 15; height: 100% }
.grid-container * {  }
.grid-container div:after {
    content: attr(class);
    color: #888;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    background-color: #2A2A2A;
}
.grid-container {  display: grid;  height: 100%;
                   grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr;
                   grid-template-rows: 1fr 1fr 1fr 1fr;
                   grid-gap: 10px 10px;
                   grid-template-areas: 'box1 box1 box2 box2 box3 box4' 'box5 box5 box6 box6 box6 box7' 'box5 box5 box6 box6 box6 box8' 'box9 box10 box11 box12 box13 box14';}
.box1 { grid-area: box1;

}
.box2 { grid-area: box2; }
.box3 { grid-area: box3; }
.box4 { grid-area: box4; }
.box5 { grid-area: box5; }
.box6 { grid-area: box6; }
.box7 { grid-area: box7; }
.box8 { grid-area: box8; }
.box9 { grid-area: box9; }
.box10 { grid-area: box10; }
.box11 { grid-area: box11; }
.box12 { grid-area: box12; }
.box13 { grid-area: box13; }
.box14 { grid-area: box14; }

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>New Pen!</title>
      <link rel="stylesheet" href="css/style.css">
</head>
<body body bgcolor="black">
    <div class='grid-container'>
        <div class='box1'></div>
        <div class='box2'></div>
        <div class='box3'></div>
        <div class='box4'></div>
        <div class='box5'></div>
        <div class='box6'></div>
        <div class='box7'></div>
        <div class='box8'></div>
        <div class='box9'></div>
        <div class='box10'></div>
        <div class='box11'></div>
        <div class='box12'></div>
        <div class='box13'></div>
        <div class='box14'></div>
    </div>
   </body>
</html>





我也尝试将名称放入div中,但是它不起作用。我会在这些框内放置一些内容,而不是名称。我不允许更改框内容,而且我无法理解这些名称的书写位置(box1,box2,box3 )

最佳答案

attr将从相关dom中获取属性,在这种情况下,会将其添加到内容中。

content: attr(class);替换为content: '';



html,
body {
  margin: 15;
  height: 100%
}

.grid-container * {}

.grid-container div:after {
  content: '';
  color: #888;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-color: #2A2A2A;
}

.grid-container {
  display: grid;
  height: 100%;
  grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr 1fr;
  grid-gap: 10px 10px;
  grid-template-areas: 'box1 box1 box2 box2 box3 box4' 'box5 box5 box6 box6 box6 box7' 'box5 box5 box6 box6 box6 box8' 'box9 box10 box11 box12 box13 box14';
}

.box1 {
  grid-area: box1;
}

.box2 {
  grid-area: box2;
}

.box3 {
  grid-area: box3;
}

.box4 {
  grid-area: box4;
}

.box5 {
  grid-area: box5;
}

.box6 {
  grid-area: box6;
}

.box7 {
  grid-area: box7;
}

.box8 {
  grid-area: box8;
}

.box9 {
  grid-area: box9;
}

.box10 {
  grid-area: box10;
}

.box11 {
  grid-area: box11;
}

.box12 {
  grid-area: box12;
}

.box13 {
  grid-area: box13;
}

.box14 {
  grid-area: box14;
}

<body body bgcolor="black">
  <div class='grid-container'>
    <div class='box1'></div>
    <div class='box2'></div>
    <div class='box3'></div>
    <div class='box4'></div>
    <div class='box5'></div>
    <div class='box6'></div>
    <div class='box7'></div>
    <div class='box8'></div>
    <div class='box9'></div>
    <div class='box10'></div>
    <div class='box11'></div>
    <div class='box12'></div>
    <div class='box13'></div>
    <div class='box14'></div>
  </div>

08-03 14:54
查看更多