首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >垂直对齐包含长文本的旋转列表项

垂直对齐包含长文本的旋转列表项
EN

Stack Overflow用户
提问于 2022-01-27 10:09:01
回答 3查看 44关注 0票数 1

我已经创建了一个被旋转的项目列表。一切都在滚动,除了长长的弦.由于一个未知的原因,“长项目”被推到绿色对齐笔画以下。

根据字符串是否包含空格(B项对C项),我在这里可能会看到2种情况。

我试过用垂直排列,然后柔韧盒,但没有成功。如果你有主意,我会优雅地接受它们。

非常感谢。

代码语言:javascript
运行
复制
ol {
  margin-top: 8rem;
  transform: translate(0%, -50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding-left: 0px;
}

li {
  position: relative;
  text-decoration: none;
  list-style-type: none;
  width: 20px;
  height: 20px;
  border: 5px solid rgb(201, 201, 201);
  border-radius: 100%;
  display: inline-block;
  margin-right: 20px;
  box-sizing: content-box;
}

li::before {
  content: "";
  display: block;
  width: 25px;
  height: 5px;
  margin-left: 25px;
  margin-top: 7px;
  background-color: rgb(220, 221, 221);
}

li:last-child::before {
  display: none;
}

li:last-child {
  margin-right: 0;
}

li span {
  position: absolute;
  top: -75px;
  left: -25px;
  color: #000;
  transform: rotate(-70deg);
  width: 120px;
  text-decoration: none;
}


li.checked {
  background-color: #27a2b8;
  border-color: rgb(20, 25, 10);
}

.checkbox {
  position: absolute;
  top: -2px;
  left: -2px;
}

.checkbox>input {
  position: absolute;
  clip: rect(0px, 0px, 0px, 0px);
}

.checkbox>svg>circle {
  stroke-width: 6px;
}

.checkbox .checked>svg {
  background-color: rgb(0, 175, 245);
  border-radius: 50%;
}

.checkbox .checked>svg>path {
  stroke: rgb(255, 255, 255);
}
}
代码语言:javascript
运行
复制
<ol>
  <li class="item"><span class="info s-QW0kY0-XRkIZ">Item A is OK</span>
    <div class="checkbox">
      <input type="checkbox" name="itemA">
      <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
        <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
      </svg>
    </div>
  </li>
  <li class="item checked">
    <span class="title">Item B is really too long</span>
    <div class="checkbox checked" name="itemB">
      <input type="checkbox" checked>
      <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
        <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
      </svg>
    </div>
  </li>
  <li class="item checked">
    <span class="title">Item-c-is-also-really-too-long-too</span>
    <div class="checkbox checked" name="itemC">
      <input type="checkbox" checked>
      <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
        <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
      </svg>
    </div>
  </li>
  <li class="item">
    <span class="title">Item c is OK</span>
    <div class="checkbox" name="itemD">
      <input type="checkbox">
      <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
        <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
      </svg>
    </div>
  </li>
</ol>

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2022-01-27 10:18:20

在您的white-space: nowrap上使用li span,这将修复它。

下面是修改后的片段:

代码语言:javascript
运行
复制
ol {
  margin-top: 8rem;
  transform: translate(0%, -50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding-left: 0px;
}

li {
  position: relative;
  text-decoration: none;
  list-style-type: none;
  width: 20px;
  height: 20px;
  border: 5px solid rgb(201, 201, 201);
  border-radius: 100%;
  display: inline-block;
  margin-right: 20px;
  box-sizing: content-box;
}

li::before {
  content: "";
  display: block;
  width: 25px;
  height: 5px;
  margin-left: 25px;
  margin-top: 7px;
  background-color: rgb(220, 221, 221);
}

li:last-child::before {
  display: none;
}

li:last-child {
  margin-right: 0;
}

li span {
  position: absolute;
  top: -75px;
  left: -25px;
  color: #000;
  transform: rotate(-70deg);
  width: 120px;
  text-decoration: none;
  white-space: nowrap;
}


li.checked {
  background-color: #27a2b8;
  border-color: rgb(20, 25, 10);
}

.checkbox {
  position: absolute;
  top: -2px;
  left: -2px;
}

.checkbox>input {
  position: absolute;
  clip: rect(0px, 0px, 0px, 0px);
}

.checkbox>svg>circle {
  stroke-width: 6px;
}

.checkbox .checked>svg {
  background-color: rgb(0, 175, 245);
  border-radius: 50%;
}

.checkbox .checked>svg>path {
  stroke: rgb(255, 255, 255);
}
}
代码语言:javascript
运行
复制
<ol>
  <li class="item"><span class="info s-QW0kY0-XRkIZ">Item A is OK</span>
    <div class="checkbox">
      <input type="checkbox" name="itemA">
      <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
        <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
      </svg>
    </div>
  </li>
  <li class="item checked">
    <span class="title">Item B is really too long</span>
    <div class="checkbox checked" name="itemB">
      <input type="checkbox" checked>
      <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
        <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
      </svg>
    </div>
  </li>
  <li class="item checked">
    <span class="title">Item-c-is-also-really-too-long-too</span>
    <div class="checkbox checked" name="itemC">
      <input type="checkbox" checked>
      <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
        <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
      </svg>
    </div>
  </li>
  <li class="item">
    <span class="title">Item c is OK</span>
    <div class="checkbox" name="itemD">
      <input type="checkbox">
      <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
        <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
      </svg>
    </div>
  </li>
</ol>

票数 1
EN

Stack Overflow用户

发布于 2022-01-27 13:32:44

我在html和css文件中做了一些修改,并达到了这个结果。希望这对你的生意有好处。我将文本放入div并添加了p标记。我在css中做了一些小改动,并使用了overflow-wrap:break-word

代码语言:javascript
运行
复制
ol {
  margin-top: 8rem;
  transform: translate(0%, -50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding-left: 0px;
}

li {
  position: relative;
  text-decoration: none;
  list-style-type: none;
  width: 20px;
  height: 20px;
  border: 5px solid rgb(201, 201, 201);
  border-radius: 100%;
  display: inline-block;
  margin-right: 40px;
  box-sizing: content-box;
}

li::before {
  content: "";
  display: block;
  width: 40px;
  height: 5px;
  margin-left: 25px;
  margin-top: 7px;
  background-color: rgb(220, 221, 221);
}

li:last-child::before {
  display: none;
}

li p {
  top: -100px;
  left: -20px;
  position: absolute;
  color: #000;
  transform: rotate(-70deg);
  width: 120px;
  text-decoration: none;
  display: inline-block;
  overflow-wrap: break-word;
}

li span {
  top: -77px;
  left: -22px;
  position: absolute;
  color: #000;
  transform: rotate(-70deg);
  width: 120px;
  text-decoration: none;
  display: inline-block;
  overflow-wrap: break-word;
}

li.checked {
  background-color: #27a2b8;
  border-color: rgb(20, 25, 10);
}

.checkbox {
  position: relative;
  top: -2px;
  left: -2px;
}

.checkbox > input {
  position: absolute;
  clip: rect(0px, 0px, 0px, 0px);
}

.checkbox > svg > circle {
  stroke-width: 6px;
}

.checkbox .checked > svg {
  background-color: rgb(0, 175, 245);
  border-radius: 50%;
}

.checkbox .checked > svg > path {
  stroke: rgb(255, 255, 255);
}
代码语言:javascript
运行
复制
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="/style.css">
    <title>Document</title>
</head>


<body>
    <div id="container">
        <ol>
            <li class="item">
                <div style="text-align: left;">
                    <span style="padding:-3px;">Item A is OK</span>
                    <div>
                        <div class="checkbox checked" name="itemB">
                            <input type="checkbox" checked>
                            <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
                                <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round"
                                    stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
                            </svg>
                        </div>
            </li>
            <li class="item checked">
                <div style="text-align: left;">
                    <p>B is really too long</p>
                    <div>
                        <div class="checkbox checked" name="itemB">
                            <input type="checkbox" checked>
                            <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
                                <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round"
                                    stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
                            </svg>
                        </div>
            </li>
            <li class="item checked">
                <div style="text-align: center;">
                    <p>Item-C-is-also-really-too-long-too</p>
                    <div>
                        <div class="checkbox checked" name="itemB">
                            <input type="checkbox" checked>
                            <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
                                <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round"
                                    stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
                            </svg>
                        </div>
            </li>
            <li class="item">
                <div style="text-align: left;">
                    <span>Item D is OK</span>
                    <div>
                        <div class="checkbox checked" name="itemB">
                            <input type="checkbox" checked>
                            <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
                                <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round"
                                    stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
                            </svg>
                        </div>
            </li>
        </ol>
    </div>
</body>

</html>

票数 0
EN

Stack Overflow用户

发布于 2022-01-27 13:44:27

我还有一个解决方案,请看你的更新代码。它与左对齐文本和固定文本宽度一起工作。

您还可以检查Codepen.io示例。

代码语言:javascript
运行
复制
:root {
  --ol-gap-size: 20px;
}

ol {
  margin-top: 8rem;
  transform: translate(0%, -50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding-left: 0;
  column-gap: var(--ol-gap-size);
}

li {
  position: relative;
  text-decoration: none;
  list-style-type: none;
  width: 20px;
  height: 20px;
  border: 5px solid rgb(201, 201, 201);
  border-radius: 50%;
/*   display: inline-block; */
/*   margin-right: 20px; */
/*   box-sizing: content-box; */
}

li:not(:last-child):before {
  content: "";
  display: block;
  width: calc(var(--ol-gap-size) + 5px);
  height: 5px;
  margin-left: 25px;
  margin-top: 7px;
  background-color: rgb(220, 221, 221);
}

/* li:last-child::before {
  display: none;
} */

/* li:last-child {
  margin-right: 0;
} */

li span {
  position: absolute;
  color: #000;
  width: 120px;
  text-decoration: none;
  
  top: 50%;
  left: calc(100% + 10px);
  transform: translate3d(0, -50%, 0) rotate(-70deg);
  transform-origin: calc(var(--ol-gap-size) * -1) center;
  
  /*   top: -75px; */
  /*   left: -25px; */
  /*   transform: rotate(-70deg); */
}


li.checked {
  background-color: #27a2b8;
  border-color: rgb(20, 25, 10);
}

.checkbox {
  position: absolute;
  top: -2px;
  left: -2px;
}

.checkbox>input {
  position: absolute;
  clip: rect(0px, 0px, 0px, 0px);
}

.checkbox>svg>circle {
  stroke-width: 6px;
}

.checkbox .checked>svg {
  background-color: rgb(0, 175, 245);
  border-radius: 50%;
}

.checkbox .checked>svg>path {
  stroke: rgb(255, 255, 255);
}
代码语言:javascript
运行
复制
<ol>
  <li class="item"><span class="info s-QW0kY0-XRkIZ">Item A is OK</span>
    <div class="checkbox">
      <input type="checkbox" name="itemA">
      <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
        <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
      </svg>
    </div>
  </li>
  <li class="item checked">
    <span class="title">Item B is really too long</span>
    <div class="checkbox checked" name="itemB">
      <input type="checkbox" checked>
      <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
        <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
      </svg>
    </div>
  </li>
  <li class="item checked">
    <span class="title">Item-c-is-also-really-too-long-too</span>
    <div class="checkbox checked" name="itemC">
      <input type="checkbox" checked>
      <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
        <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
      </svg>
    </div>
  </li>
  <li class="item">
    <span class="title">Item c is OK</span>
    <div class="checkbox" name="itemD">
      <input type="checkbox">
      <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
        <path d="M6.5 12.5l4 4 8-8" fill="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" class="s-QW0kY0-XRkIZ"></path>
      </svg>
    </div>
  </li>
</ol>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70876717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档