html - 定位旋转inline-block伪元素

标签 html css web frontend

div {
  height: 100vh;
  width: 100vw;
  background: #000;
  color: white;
  font-size: 30vh;
}

span{
  font-family: sans-serif;
  padding: 2vw;
  margin: 2vw;
  font-weight: bold;
}
#name:before {
  position: relative;
  display: inline-block;
  content: "I AM";
  transform: rotate(-90deg);
  font-size: 7vw;
  margin-right: -10vw;
  font-weight: lighter;
}
<head><link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.min.css" rel="stylesheet"/>
</head>
<body>
<div>
  <span id="name">
  test
  </span>
  <br />
  <span id="verb">
  Hello</span>
  <br />
  <span id="verb_two">
  World!</span>
  
</div>
</body>

我正在尝试垂直旋转内联 block :before 元素并将其放置在跨度的一侧。所以,我希望“I AM”文本的宽度与“test”中“t”的长度相同,并希望它被放置在与“test”具有相同基准水平的一侧。我该怎么做?

最佳答案

一种可能,玩写模式:

div {
  height: 100vh;
  width: 100vw;
  background: #000;
  color: white;
  font-size: 15vw;
}

span{
  font-family: sans-serif;
  padding: 2vw;
  margin: 2vw;
  font-weight: bold;
}
#name:before {
  position: relative;
  display: inline-block;
  content: "I AM";
  transform: rotate(180deg);
  writing-mode: vertical-rl; 
  font-size: 7vw;
  margin-right: -4vw;
  font-weight: lighter;
  left: -2vw;
  bottom: 0px;
  background-color: red;
  height: 15vw;
  padding: 1vw;
}
<head><link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.min.css" rel="stylesheet"/>
</head>
<body>
<div>
  <span id="name">
  test
  </span>
  <br />
  <span id="verb">
  Hello</span>
  <br />
  <span id="verb_two">
  World!</span>
  
</div>
</body>

关于html - 定位旋转inline-block伪元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44481646/

相关文章:

html - <section> 标签在屏幕空间不足时下移

future 某个时间的Java运行事件

css - 如何使页脚停留在滚动的末尾

html - 即使您没有将鼠标放在下拉菜单上,下拉菜单也是可见的

css 选择器选择包含 img 的表格单元格

trello - Trello webhook 问题

javascript - 将图像保存为 JSON,然后在 HTML5 和 jquery 中再次加载

html - CSS - 已声明样式的计算样式

html - 为什么列表样式类型不起作用?没有显示任何内容

javascript - 多次追加加载的 HTML