#showdevUbuntu CSS终端

Ubuntu和Ubuntu终端的设计和配色方案相对独特,以前使用过Ubuntu的任何人都可以立即识别。在CSS中重新创建Ubuntu终端是一个有趣的小练习,可以练习CSS技能。

Ubuntu字体

对于那些不知道的人,Ubuntu实际上拥有三种不同样式的自有字体:常规字体,压缩字体和等宽字体。 Ubuntu终端使用Ubuntu Regular作为工具栏中的标题,并使用Ubuntu Monospace作为终端中的文本。两者都可以从Google字体中找到和获取。

工具列

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

是一条线

是一个盒子

 class="Toolbar__button Toolbar__button--exit">
 class="Toolbar__button">
 class="Toolbar__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光标动画

最后,添加终端光标,默认情况下它只是一个白色块。我们可以将光标的不透明度更改为 01。要制作动画循环,我们可以添加 infinitealternateanimation 属性,因此光标将从 01 然后从动画 10 然后从动画 01 再三,一而再再而三。

.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之类的库来扩展此演示,以显示为命令添加动画的终端文本。或者我们可以放一个