给定一个逻辑(搜索引擎可读)HTML菜单,其中包含一个包裹在<nav>中的无序列表菜单,从item Home开始,到item Blog结束.我已经try 了一些纯CSS和HTML的东西,但无法实现我想要的.

100

我想要的是:

  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>

推荐答案

不要玩太多的转换.使用写入模式,然后将应用于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>

Html相关问答推荐

HTML图像无法正确放大和缩小规模

<;img>;和具有负边距的元素的堆叠顺序

我应该怎么做才能显示出整个字符串?

在CSS中旋转排除的蒙版图像

在单独的容器之间堆叠上下文

天使17:令人惊叹的动画

当溢出到滚动条中时, bootstrap 按钮样式会更改

如何使用css横向显示英文和中日韩文字?

当底部进入视图时从底部粘性定位

Angular中如何向单选按钮添加验证

水平填充容器内的空间

具有 css 高度的输入元素:100% 溢出父 div

我如何使用 CSS nth-child(odd) nth-child(even) 来对齐 CSS 网格中的列?

将 HTML 元素粘贴到容器底部,而不剪裁其顶部

是否可以将文本添加到表格边框?

如何将 img 元素定位到特定位置?

CSS Padding 将右对齐的对象推离页面

html tailwindcss 给 li 标签添加边框

focusout() Select 器不适用于搜索框

我可以将两个元素之间的所有空间都放在弹性框或网格中吗?