You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在页面右上角添加3个项目符号图片?

问题截图

这是我的代码:

我尝试过相关操作,但图片仍然呈垂直排列。

问题原因

你的代码存在三个关键问题:

  1. HTML嵌套错误:第二个.skill-box1被嵌套在第一个.skill-box1内部,导致container1的Grid布局只识别到一个子元素,剩下的内容只能在内部垂直排列。
  2. CSS笔误:.inner的padding-top: 20p x;是无效写法,应为20px。
  3. 定位缺失:.skill-title1未设置position: relative;,导致其伪元素定位错误。

修复后的代码

CSS代码

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: 'Roboto', sans-serif;
}

body {
  background-color: #333;
}

.inner {
  padding-top: 20px; /* 修正笔误 */
}

.header {
  text-align: center;
  color: #fff;
  padding: 1rem;
  position: relative;
}

.header:after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  height: 4px;
  width: 100px;
  background-color: #2ecc71;
}

.container1 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  justify-content: center;
  align-items: center;
  text-align: center;
  grid-gap: 10px;
  padding: 1rem 80px;
  font-size: 1.2rem;
}

.skill-box1 {
  padding: 1rem;
  color: #ddd;
  cursor: pointer;
}

.skill-title1 {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  position: relative; /* 添加相对定位,让伪元素正确定位 */
}

.skill-title1:after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 50%;
  width: 35px;
  height: 4px;
  border-radius: 2px 0 0 2px;
  background-color: #2ecc71;
}

.skill-title1:before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 35px;
  height: 4px;
  border-radius: 0 2px 2px 0;
  background-color: #2ecc71;
}

.img1 {
  width: 90px;
  height: 90px;
  padding: 10px;
  position: relative;
  border-radius: 45px;
  background-color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
}

.img1:after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 90px;
  background: rgba(100, 100, 100, 0.5);
  border-radius: 45px 0 0 45px;
}

.skill-title1 h3 {
  color: #fff;
  margin: 0.5rem;
}

.skill-icon1 {
  width: 50px;
  z-index: 2;
}

HTML代码

<div class="inner">
  <div class="header">
    <h1>Kemampuan</h1>
  </div>
  <div class="container1">
    <div class="skill-box1">
      <div class="skill-title1">
        <div class="img1">
          <img src="https://swimburger.net/media/ppnn3pcl/azure.png" class="skill-icon1">
        </div>
        <h3>MIKROTIK</h3>
      </div>
    </div> <!-- 闭合第一个skill-box1 -->
    <div class="skill-box1"> <!-- 作为container1的直接子元素 -->
      <div class="skill-title1">
        <div class="img1">
          <img src="https://swimburger.net/media/ppnn3pcl/azure.png" class="skill-icon1">
        </div>
        <h3>MIKROTIK</h3>
      </div>
    </div> <!-- 闭合第二个skill-box1 -->
  </div>
</div>

说明

修复后,.container1的Grid布局会正确识别所有.skill-box1子元素,按照repeat(5, 1fr)的设置横向排列,同时修正了定位和样式笔误问题。

内容的提问来源于stack exchange,提问作者Evloseis Indonesia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 08:24:55