CSS 中的 Ubuntu 终端
本文最初发表于codinhood.com
Ubuntu 和 Ubuntu 终端的设计和配色方案相对独特,任何使用过 Ubuntu 的人都能一眼认出。用 CSS 重新创建 Ubuntu 终端是一个有趣的小练习,可以练习你的 CSS 技能。
Ubuntu 字体
对于那些不知道的人来说,Ubuntu 实际上有三种不同风格的字体:常规、压缩和等宽。Ubuntu 终端使用 Ubuntu 常规字体作为工具栏标题,使用 Ubuntu 等宽字体作为终端内的文本。这两种字体都可以在Google Fonts中找到并获取。
工具栏
Ubuntu 终端工具栏由三个按钮和标题组成,标题由用户名和系统名称组成。工具栏的背景实际上是深灰色的轻微线性渐变。此外,顶部工具栏的左右角是圆角,与整个终端的左右下角不同。
.Terminal__Toolbar {
background: linear-gradient(#504b45 0%,#3c3b37 100%);
width: 100%;
padding: 0 8px;
box-sizing: border-box;
height: 25px;
display: flex;
align-items: center;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
}
.Toolbar__user {
color: #d5d0ce;
margin-left: 4px;
font-size: 12px;
line-height: 14px;
margin-bottom: 1px;
}
工具栏按钮
工具栏按钮也带有轻微的灰色线性渐变,以及文本阴影和框阴影。我们可以使用图标来渲染工具栏按钮的内容,但为了简单起见,我们将为每个按钮使用HTML 字符实体。
✕
是 X
─
是一条线
◻
是一个盒子
<button class="Toolbar__button Toolbar__button--exit">✕</button>
<button class="Toolbar__button">─</button>
<button class="Toolbar__button">◻</button>
.Toolbar__buttons {
display: flex;
align-items: center;
}
.Toolbar__button {
width: 12px;
height: 12px;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
border-radius: 100%;
padding: 0;
font-size: 7px;
background: linear-gradient(#7d7871 0%, #595953 100%);
text-shadow: 0px 1px 0px rgba(255,255,255,0.2);
box-shadow: 0px 0px 1px 0px #41403A,0px 1px 1px 0px #474642;
border: none;
margin-right: 4px;
}
.Toolbar__button:hover {
cursor: pointer;
}
.Toolbar__button--exit {
background: #f25d2b;
background: linear-gradient(#f37458 0%, #de4c12 100%);
background-clip: padding-box;
}
.Toolbar__button:focus {
outline: none;
}
终端主体和文本
终端的主体更加简洁,只是一个矩形,背景为特定的紫色,并在其中填充了与终端相符的文本。由于 Ubuntu 终端的颜色非常独特,因此这里的关键在于颜色的正确性。“欢迎使用 Ubuntu!”的文本和美元符号是#ddd
,名称和系统是亮绿色#87d441
,而位置信息(目前为 ~ )是褪色的蓝灰色#6d85a9
。
.Terminal__body {
background: rgba(56, 4, 40, .9);
height: calc(100% - 25px);
margin-top: -1px;
padding-top: 2px;
font-family: 'Ubuntu mono';
}
.Terminal__text {
color: #ddd;
}
.Terminal__Prompt {
margin-top: 10px;
display: flex;
}
.Prompt__user {
color: #87d441;
}
.Prompt__location {
color: #6d85a9;
}
.Prompt__dollar {
color: #ddd;
}
Ubuntu 光标动画
最后,添加终端光标,默认情况下它只是一个白色块。我们可以通过将不透明度从 更改为 来使光标像闪烁一样动起来0
。1
为了使动画循环,我们可以将infinite
和添加alternate
到animation
属性,这样光标就会从 到 动画0
,1
再从 到 动画1
,0
再从0
到1
动画,如此反复。
.Prompt__cursor {
height: 17px;
width: 8px;
background: white;
display: block;
margin-left: 8px;
animation: 2000ms ease infinite alternate blink;
}
@keyframes blink {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
扩展演示
我们可以使用typed.js之类的库来扩展此演示,以显示终端文本和命令的动画效果。或者,我们可以<textarea>
在终端中放置一个,并允许用户输入。