如何按外观顺序旋转(而非堆栈)垂直顺序的HTML块?

发布于 2025-01-31 07:32:02 字数 1701 浏览 2 评论 0原文

给定一个逻辑(可读的搜索引擎)HTML菜单,其中包含在< nav>内包裹的无序列表菜单,从项目主页开始,然后以项目博客结尾。我在纯CSS和HTML中尝试了几件事,但无法实现我想要的东西。

”这是:

  1. 将整个垂直菜单与屏幕的左上边缘对齐。
    无论< nav> !!

    中包含的列表项的数量和/或长度如何
  2. 将每个带下划线的链接的可点击区域扩展到其整个蓝色块。
    为了悬停并单击菜单项时易于使用。

  3. 理想情况下,我们应该抛弃我的破碎开始,然后选择Flexbox CSS设计。
    也许这为我们提供了更好的灵活性来实现这一目标。那将是一个奖励!

nav {
  text-align:center;
  transform: rotate(-90deg) translateX(-240px) translateY(-100px);
  margin: 0;
  top: 0px;
  left: 0px;
  position: absolute;
}

nav li{
    display: inline-block;
    background-color: blue;
    height: 24px;
    line-height: 24px;
    vertical-align: middle;
    margin: 5px auto;
    padding: 1em;
}

nav li a{
  color: #fff;
}

nav li a:hover{
  background: black;
}

nav li.selected {
  background-color: purple;
}
<nav>
  <ul>
    <li><a href="#">Home</a></li>
    <li class="selected"><a href="#">Philosophy</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">Products</a></li>
    <li><a href="#">Contact</a></li>
    <li><a href="#">Blog</a></li>
  </ul>
</nav>

Given a logical (search engine readable) HTML menu containing an unordered list menu wrapped inside a <nav>, starting with item Home and ending with item Blog. I have tried several things in pure CSS and HTML but cannot achieve what I want.

https://jsfiddle.net/6zt3gfp4/

What I would like, is this:

  1. Align the whole vertical menu to the top left edge of the screen, automatically.
    Regardless of the number of and/or length of the list items contained in the <nav>!!

  2. Expand the clickable area of each underlined link to its entire blue block.
    For ease of use when hovering and clicking a menu item.

  3. Ideally we should leave my broken start behind and opt for a FlexBox CSS design.
    Perhaps that gives us all better flexibility for achievng this. That would be a bonus!

enter image description here

nav {
  text-align:center;
  transform: rotate(-90deg) translateX(-240px) translateY(-100px);
  margin: 0;
  top: 0px;
  left: 0px;
  position: absolute;
}

nav li{
    display: inline-block;
    background-color: blue;
    height: 24px;
    line-height: 24px;
    vertical-align: middle;
    margin: 5px auto;
    padding: 1em;
}

nav li a{
  color: #fff;
}

nav li a:hover{
  background: black;
}

nav li.selected {
  background-color: purple;
}
<nav>
  <ul>
    <li><a href="#">Home</a></li>
    <li class="selected"><a href="#">Philosophy</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">Products</a></li>
    <li><a href="#">Contact</a></li>
    <li><a href="#">Blog</a></li>
  </ul>
</nav>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清泪尽 2025-02-07 07:32:02

转型不要玩很多。然后使用写作模式然后将应用于li的样式移至a以使链接区域更大。

nav {
  top: 0px;
  left: 0px;
  position: absolute;
}
nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
nav li {
  background-color: blue;
  writing-mode: vertical-rl; /* */
  transform: scale(-1); /* */
  margin: 5px 0;
}
nav li a {
  color: #fff;
  padding: 1em;
  display: inline-block;
  line-height: 24px;
}
nav li a:hover {
  background: black;
}
nav li.selected {
  background-color: purple;
}
<nav>
  <ul>
    <li><a href="#">Home</a></li>
    <li class="selected"><a href="#">Philosophy</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">Products</a></li>
    <li><a href="#">Contact</a></li>
    <li><a href="#">Blog</a></li>
  </ul>
</nav>

Don't play a lot with transformation. Use writing-mode then move the style applied to li to a to make the link area bigger.

nav {
  top: 0px;
  left: 0px;
  position: absolute;
}
nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
nav li {
  background-color: blue;
  writing-mode: vertical-rl; /* */
  transform: scale(-1); /* */
  margin: 5px 0;
}
nav li a {
  color: #fff;
  padding: 1em;
  display: inline-block;
  line-height: 24px;
}
nav li a:hover {
  background: black;
}
nav li.selected {
  background-color: purple;
}
<nav>
  <ul>
    <li><a href="#">Home</a></li>
    <li class="selected"><a href="#">Philosophy</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">Products</a></li>
    <li><a href="#">Contact</a></li>
    <li><a href="#">Blog</a></li>
  </ul>
</nav>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文