【问题标题】:Shift cards over to next row when browser size is 915px width当浏览器大小为 915 像素宽度时,将卡片移至下一行
【发布时间】:2022-01-23 06:35:45
【问题描述】:

当浏览器宽度为 915px 时,如何将内容转移到下一行?

这就是我现在拥有的:

<div class="body">
    <div class="container">
        <div class="card">
            <div class="box">
                <div class="percent">
                    <svg>
                        <circle cx="70" cy="70" r="70"></circle>
                        <circle cx="70" cy="70" r="70"></circle>
                    </svg>
                    <div class="number">
                        <h2>90<span>%</span></h2>
                    </div>
                </div>
                <h2 class="text">Html</h2>
            </div>
        </div>
        <div class="card">
            <div class="box">
                <div class="percent">
                    <svg>
                        <circle cx="70" cy="70" r="70"></circle>
                        <circle cx="70" cy="70" r="70"></circle>
                    </svg>
                    <div class="number">
                        <h2>85<span>%</span></h2>
                    </div>
                </div>
                <h2 class="text">CSS</h2>
            </div>
        </div>
        <div class="card">
            <div class="box">
                <div class="percent">
                    <svg>
                        <circle cx="70" cy="70" r="70"></circle>
                        <circle cx="70" cy="70" r="70"></circle>
                    </svg>
                    <div class="number">
                        <h2>60<span>%</span></h2>
                    </div>
                </div>
                <h2 class="text">Javascript</h2>
            </div>
        </div>
    </div>
</div>

还有我的css

.body {
  display: flex;
  justify-content: center;
  align-items: center;

  min-height: 100vh;
}

.container {
  display: flex;
  justify-content: space-around;
}
.container .card {
  margin-left: 20px;
  position: relative;
  width: 250px;
  background: #222;
  background: linear-gradient(0deg, #1b1b1b, #222, #1b1b1b);
  display: flex;
  justify-content: center;
  align-items: center;
  height: 300px;
  border-radius: 4px;
  text-align: center;
  overflow: hidden;
  transition: 0.5s;
}
.container .card:hover {
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
  transform: translateY(-10px);
}
.container .card:before {
  content: "";
  position: absolute;
  top: 0;
  left: -50%;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.03);
  pointer-events: none;
  z-index: 1;
}
.percent {
  position: relative;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  box-shadow: inset 0 0 50px #000;
  background: #222;
  z-index: 100;
}
.percent .number {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
}
.percent .number h2 {
  color: #777;
  font-weight: 700;
  font-size: 40px;
  transition: 0.5s;
}
.card:hover .percent .number h2 {
  color: #fff;
  font-size: 60px;
}
.percent .number h2 span {
  font-size: 24px;
  color: #777;
}
.text {
  color: #777;
  margin-top: 20px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: 0.5s;
}
.card:hover .text {
  color: #fff;
}
svg {
  position: relative;
  width: 150px;
  height: 150px;
  z-index: 1000;
}
circle {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: #191919;
  stroke-width: 10;
  stroke-linecap: round;
  transform: translate(5px, 5px);
}
circle:nth-child(2) {
  stroke-dasharray: 440;
  stroke-dashoffset: 440;
}
.card:nth-child(1) svg circle:nth-child(2) {
  stroke-dashoffset: calc(440 - (440 * 90) / 100);
  stroke: #00ff43;
}
.card:nth-child(2) svg circle:nth-child(2) {
  stroke-dashoffset: calc(440 - (440 * 85) / 100);
  stroke: #00a1ff;
}
.card:nth-child(3) svg circle:nth-child(2) {
  stroke-dashoffset: calc(440 - (440 * 60) / 100);
  stroke: #c104ff;
}

@media only screen and (max-width: 915px) {
  /* your css of 1024 px screen size */
  .card {
    flex: 10% !important;
  }
}

当浏览器宽度为 915 像素时,如何使内容向下移动,以便在移动设备上看起来不错。我试过 flex,改变显示,改变宽度,但没有任何效果。我不知道这是否与其中任何一个有关,但我将不胜感激。

【问题讨论】:

    标签: html css svg


    【解决方案1】:

    您可以使用grid 布局。首先,将容器设置为display: grid;。在您可以使用grid-template-columns: 1fr; 设置网格后(1fr = 一列,1fr 1fr = 2 列,1fr 2fr = 2 列,但右侧更大......等等)。之后,您可以添加gap: 1rem; 以在您的列和行之间留出间隙。

    Grid Documentation on W3School

    这是一个例子:

    .body {
      display: flex;
      justify-content: center;
      align-items: center;
    
      min-height: 100vh;
    }
    
    .container {
      display: flex;
      justify-content: space-around;
    }
    .container .card {
      margin-left: 20px;
      position: relative;
      width: 250px;
      background: #222;
      background: linear-gradient(0deg, #1b1b1b, #222, #1b1b1b);
      display: flex;
      justify-content: center;
      align-items: center;
      height: 300px;
      border-radius: 4px;
      text-align: center;
      overflow: hidden;
      transition: 0.5s;
    }
    .container .card:hover {
      box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
      transform: translateY(-10px);
    }
    .container .card:before {
      content: "";
      position: absolute;
      top: 0;
      left: -50%;
      width: 100%;
      height: 100%;
      background: rgba(255, 255, 255, 0.03);
      pointer-events: none;
      z-index: 1;
    }
    .percent {
      position: relative;
      width: 150px;
      height: 150px;
      border-radius: 50%;
      box-shadow: inset 0 0 50px #000;
      background: #222;
      z-index: 100;
    }
    .percent .number {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 50%;
    }
    .percent .number h2 {
      color: #777;
      font-weight: 700;
      font-size: 40px;
      transition: 0.5s;
    }
    .card:hover .percent .number h2 {
      color: #fff;
      font-size: 60px;
    }
    .percent .number h2 span {
      font-size: 24px;
      color: #777;
    }
    .text {
      color: #777;
      margin-top: 20px;
      font-weight: 700;
      font-size: 18px;
      letter-spacing: 1px;
      text-transform: uppercase;
      transition: 0.5s;
    }
    .card:hover .text {
      color: #fff;
    }
    svg {
      position: relative;
      width: 150px;
      height: 150px;
      z-index: 1000;
    }
    circle {
      width: 100%;
      height: 100%;
      fill: none;
      stroke: #191919;
      stroke-width: 10;
      stroke-linecap: round;
      transform: translate(5px, 5px);
    }
    circle:nth-child(2) {
      stroke-dasharray: 440;
      stroke-dashoffset: 440;
    }
    .card:nth-child(1) svg circle:nth-child(2) {
      stroke-dashoffset: calc(440 - (440 * 90) / 100);
      stroke: #00ff43;
    }
    .card:nth-child(2) svg circle:nth-child(2) {
      stroke-dashoffset: calc(440 - (440 * 85) / 100);
      stroke: #00a1ff;
    }
    .card:nth-child(3) svg circle:nth-child(2) {
      stroke-dashoffset: calc(440 - (440 * 60) / 100);
      stroke: #c104ff;
    }
    
    @media only screen and (max-width: 915px) {
      /* your css of 1024 px screen size */
      .card {
        flex: 10% !important;
      }
      .grid-class{
          display: grid;
        grid-template-columns: 1fr;
        gap: 1rem;
      }
    }
    <div class="body">
        <div class="container grid-class">
            <div class="card">
                <div class="box">
                    <div class="percent">
                        <svg>
                            <circle cx="70" cy="70" r="70"></circle>
                            <circle cx="70" cy="70" r="70"></circle>
                        </svg>
                        <div class="number">
                            <h2>90<span>%</span></h2>
                        </div>
                    </div>
                    <h2 class="text">Html</h2>
                </div>
            </div>
            <div class="card">
                <div class="box">
                    <div class="percent">
                        <svg>
                            <circle cx="70" cy="70" r="70"></circle>
                            <circle cx="70" cy="70" r="70"></circle>
                        </svg>
                        <div class="number">
                            <h2>85<span>%</span></h2>
                        </div>
                    </div>
                    <h2 class="text">CSS</h2>
                </div>
            </div>
            <div class="card">
                <div class="box">
                    <div class="percent">
                        <svg>
                            <circle cx="70" cy="70" r="70"></circle>
                            <circle cx="70" cy="70" r="70"></circle>
                        </svg>
                        <div class="number">
                            <h2>60<span>%</span></h2>
                        </div>
                    </div>
                    <h2 class="text">Javascript</h2>
                </div>
            </div>
        </div>
    </div>

    【讨论】:

      猜你喜欢
      • 2015-09-14
      • 2017-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-11
      • 1970-01-01
      • 2017-05-29
      • 1970-01-01
      相关资源
      最近更新 更多