【发布时间】:2021-08-18 10:51:10
【问题描述】:
我试图让这个列表居中,但是当我添加内联块时,它会换行。那么如何让这个列表不换行并垂直显示在一行中呢?空白:nowrap 似乎不起作用,我完全没有其他想法来尝试修复它。
.mobile-nav {
background-color: rgba(255, 255, 255, 0.9);
position: fixed;
top: 0;
bottom: 0;
left: 0;
width: 4rem;
border-style: solid;
border-right-width: 1px;
border-color: rgba(243, 244, 246, 1.0);
z-index: 10;
background-color: lightgray;
}
.nav {
background-color: lightblue;
}
.nav li {
display: inline-block;
text-transform: uppercase;
writing-mode: vertical-rl;
text-orientation: mixed;
transform: scale(-1);
margin-bottom: 50px;
font-weight: 600;
font-size: 0.85rem;
background-color: coral;
white-space: nowrap
}
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet"/>
<!-- left side container -->
<div class="fixed top-0 bottom-0 left-0 w-16 border-r border-gray-100 z-10 mobile-nav">
<!-- left side container content -->
<div class="fixed bottom-16 left-0 w-16 select-none">
<!-- navigation -->
<nav class="nav block w-full text-center">
<ul>
<li>
<a href="#">Test 1</a>
</li>
<li>
<a href="#">Test 2</a>
</li>
<li>
<a href="#">Test 3</a>
</li>
<li>
<a href="#">Test 4</a>
</li>
<li>
<a href="#">Test 5</a>
</li>
</ul>
</nav><!-- end navigation -->
</div>
</div> <!-- end left side container -->
【问题讨论】:
-
为什么首先使用
inline-block而不是flexbox? -
希望它居中。
-
和? flexbox 可用于垂直和水平居中元素。再说一遍,为什么是
inline-block而不是flexbox? -
你能举个例子吗?当我使用 flexbox 时它不会居中。
-
删除:
.nav li { display: inline-block; };添加:.nav ul { display: flex; flex-direction: column-reverse; align-items: center; }
标签: html css tailwind-css