【问题标题】:How to place play image in the middle of the teal square?如何将播放图像放在青色方块的中间?
【发布时间】:2022-12-03 22:31:36
【问题描述】:

这将如何完成? https://jsfiddle.net/mLwcyj9u/

你能帮助我吗?

我试图将播放图像放在蓝绿色正方形的中间。

这就是我想要做的。

将游戏图像放在蓝绿色方块内。

这些都是细节。

这就是一切。

我在下面提供了一个 sn-p。

.channel-tile {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  border-radius: 4px;
  width: 180px;
  float: left;
  display: block;
  margin-bottom: 18px;
  background: #2E2E2E;
  position: relative;
}

.channel-tile__image-area {
  width: 180px;
  height: 0;
  padding-top: 100%;
  position: relative;
  z-index: 0;
  border-radius: 4px;
  background: red;
  border: 1px solid blue;
}

.channel-tile__artwork {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  margin: auto;
  width: 170px;
  height: 170px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  z-index: 0;
  background: teal;
}

.cover {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  cursor: pointer;
  border: 9px solid blue;
  background: transparent;
  filter: drop-shadow(3px 3px 3px rgba(0, 0, 0, 0.7));
}

.cover::before {
  content: "";
  width: 0;
  height: 0;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;
  border-left: 27px solid blue;
  transform: translateX(4px);
}
<div class="channel-tile">
  <div class="channel-tile__image-area">
    <span class="channel-tile__artwork"></span>
  </div>
</div>
<div class="cover">
</div>

【问题讨论】:

  • 很简单,将你的.cover 元素放在-area 中,并在 CSS 中使用绝对位置(等),就像你对 __artwork 所做的那样。
  • 我不明白,播放图像总是乱七八糟。
  • 然后看下面的答案。我刚刚将 &lt;div class="cover" 移动到 -area 并添加了与 __artwork 相同的“绝对居中样式”

标签: css css-position


【解决方案1】:

很简单,将你的.cover 元素放在-area 中,并在 CSS 中使用绝对位置(等),就像你对 __artwork 所做的那样。

.channel-tile {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  border-radius: 4px;
  width: 180px;
  float: left;
  display: block;
  margin-bottom: 18px;
  background: #2E2E2E;
  position: relative;
}

.channel-tile__image-area {
  width: 180px;
  height: 0;
  padding-top: 100%;
  position: relative;
  z-index: 0;
  border-radius: 4px;
  background: red;
  border: 1px solid blue;
}

.channel-tile__artwork {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  margin: auto;
  width: 170px;
  height: 170px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  z-index: 0;
  background: teal;
}

.cover {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  cursor: pointer;
  border: 9px solid blue;
  background: transparent;
  filter: drop-shadow(3px 3px 3px rgba(0, 0, 0, 0.7));
  
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  margin: auto;
}

.cover::before {
  content: "";
  width: 0;
  height: 0;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;
  border-left: 27px solid blue;
  transform: translateX(4px);
}
<div class="channel-tile">
  <div class="channel-tile__image-area">
    <span class="channel-tile__artwork"></span>
    <div class="cover"></div>
  </div>
</div>

避免使用float。请改用flex

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    • 1970-01-01
    • 2018-08-13
    • 1970-01-01
    相关资源
    最近更新 更多