html - 如何将旋转的元素居中并将其与顶部对齐?

标签 html css css-transforms

* {
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    margin: 0px;
}

.we-adopt {
    background-color: #8a8484;
    color: #ffffff;
    padding: 88px 0px;
    height: 100px;
}

.we-adopt-list span {
    display: inline-block;
    vertical-align: top;
    padding: 16px 60px 16px 24px;
    background-color: #222222;
    color: #ffffff;
    width: 100%;
}

.we-adopt-list li {
    color: #FFFFFF;
    font-size: 32px;
    font-weight: 500;
    letter-spacing: 1.6px;
    line-height: 24px;
    margin-bottom: 70px;
    text-transform: uppercase;
}

.we-adopt-list ul {
    display: inline-block;
    transform: rotate(-90deg) translateY(-50%);
    position: relative;
    left: 50%;
}

.we-adopt-list {
    position: relative;
}

.we-adopt-list li:last-child {
    margin-bottom: 0px;
}
<section class="we-adopt" style="height: 100px;">
    
</section>
<section class="we-adopt-wrap">
    <div class="container">
        <div class="we-adopt-list">
            <ul>
                <li><span>Mental agility</span></li>
                <li><span>Emotional agility</span></li>
                <li><span>Trust</span></li>
            </ul>
        </div>
    </div>
</section>

每当我将 transform-rotate 属性应用到我的列表部分时,它就会重叠,或者有时它会占用上面内容的空间。

案例1

enter image description here

案例2

enter image description here

应用transform-rotate后,我想从上面的灰色部分开始列表部分,没有间距,如下图所示。

预期结果

enter image description here

还有其他方法可以创建这种设计吗?

最佳答案

考虑transform-origin并更新transform,如下所示:

* {
  box-sizing: border-box;
}

body {
  font-family: 'Poppins', sans-serif;
  margin: 0px;
}

.we-adopt {
  background-color: #8a8484;
  color: #ffffff;
  padding: 88px 0px;
  height: 100px;
}

.we-adopt-list span {
  display: inline-block;
  vertical-align: top;
  padding: 16px 60px 16px 24px;
  background-color: #222222;
  color: #ffffff;
  width: 100%;
}

.we-adopt-list li {
  color: #FFFFFF;
  font-size: 32px;
  font-weight: 500;
  letter-spacing: 1.6px;
  line-height: 24px;
  margin-bottom: 70px;
  text-transform: uppercase;
}

.we-adopt-list ul {
  display: inline-block;
  transform-origin: top left;
  transform: rotate(-90deg) translateX(-100%) translateY(-50%);
  position: relative;
  margin: 0;
  left: 50%;
}

.we-adopt-list {
  position: relative;
}

.we-adopt-list li:last-child {
  margin-bottom: 0px;
}
<section class="we-adopt" style="height: 100px;">

</section>
<section class="we-adopt-wrap">
  <div class="container">
    <div class="we-adopt-list">
      <ul>
        <li><span>Mental agility</span></li>
        <li><span>Emotional agility</span></li>
        <li><span>Trust</span></li>
      </ul>
    </div>
  </div>
</section>

关于html - 如何将旋转的元素居中并将其与顶部对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63297064/

相关文章:

html - 如何避免使用css一行出现孤词?

javascript - 为什么不使用 jquery 将外部内容加载到 HTML 中?

html - 如何在我的 Wordpress 网站上添加 flexbox

javascript - CSS Transform Skew 和 Scale 在 Microsoft Edge 中无法正常工作

html - 使用具有页眉和页脚的外部容器进行视差滚动

html - 可变高度内容和表格单元格底部之间的垂直居中图标

javascript - IE7/8 不动态添加 css 属性 'top' 作为内联样式

jquery - 用动画填充颜色

html - CSS 过渡没有按预期工作

internet-explorer - CSS3 动画在 IE9 中不工作