html 使用CSS Grid和Flexbox的LastPass Vault布局
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 使用CSS Grid和Flexbox的LastPass Vault布局相关的知识,希望对你有一定的参考价值。
/*
All grid code is placed in a 'supports' rule (feature query) at the bottom of the CSS.
The 'supports' rule will only run if your browser supports CSS grid.
Flexbox is used as a fallback so that browsers which don't support grid will still recieve an identical layout.
*/
/* Fonts */
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,600);
@import url(https://use.fontawesome.com/releases/v5.0.6/css/all.css);
/* Base styles */
:root {
/* Base font size */
font-size: 10px;
}
body {
font-family: "Open Sans", Arial, sans-serif;
display: flex;
min-height: 100vh;
background-color: #fafafa;
position: relative;
}
.main-content {
display: flex;
flex-direction: column;
flex: 1;
order: 1;
}
.btn {
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}
/* Top bar */
.top-bar {
display: flex;
align-items: center;
flex-basis: 6rem;
position: -webkit-sticky;
position: sticky;
top: 0;
background-color: #d12f2e;
color: #fff;
padding: 0 5rem;
}
.logo h1 {
font-size: 2.5rem;
font-weight: 600;
letter-spacing: -0.1rem;
white-space: nowrap;
}
.logo i {
padding-left: 0.5rem;
vertical-align: middle;
}
.vault-search {
flex: 1 0 19.2rem;
margin: 0 1.6rem;
position: relative;
}
.search-input {
font-size: 1.8rem;
font-weight: 400;
height: 4.4rem;
width: 98%;
background-color: rgba(255, 255, 255, 0.2);
color: #fff;
caret-color: #fff;
padding-left: 4.4rem;
border: none;
}
.search-input:hover,
.search-input:focus {
background-color: rgba(255, 255, 255, 0.3);
}
.search-input::-webkit-input-placeholder {
color: rgba(255, 255, 255, 0.6);
}
.search-input:-ms-input-placeholder {
color: rgba(255, 255, 255, 0.6);
}
.search-input::-ms-input-placeholder {
color: rgba(255, 255, 255, 0.6);
}
.search-input::placeholder {
color: rgba(255, 255, 255, 0.6);
}
.search-icon {
font-size: 1.7rem;
position: absolute;
top: 2.2rem;
left: 2.2rem;
transform: translate(-50%, -50%);
}
.user-settings {
display: flex;
align-items: center;
font-weight: 400;
line-height: 1.2;
height: 100%;
padding: 0 0.8rem;
cursor: pointer;
}
.user-settings:hover {
background-color: #f14f4e;
}
.user-image {
font-size: 3.2rem;
}
.user-info {
margin: 0 1rem;
}
.user-email {
font-size: 1.3rem;
}
.user-type {
font-size: 1.1rem;
color: #f1c1c0;
}
.user-arrow-btn {
font-size: 1.5rem;
}
/* Vault items controls */
.vault-items-controls {
display: flex;
align-items: center;
position: -webkit-sticky;
position: sticky;
top: 6rem;
padding: 1.8rem 5rem;
background-color: #fafafa;
}
.vault-items-controls h2 {
flex: 1;
font-size: 1.9rem;
font-weight: 700;
color: #000;
}
.vault-items-controls-group {
display: flex;
}
.vault-items-controls-group .vault-items-controls-btn {
flex: 1;
}
.vault-items-controls-btn {
font-size: 2rem;
width: 4.8rem;
height: 4rem;
background-color: #fff;
color: #888;
box-shadow: 0 0.1rem 0.2rem rgba(0, 0, 0, 0.2);
border-radius: 0.2rem;
margin-right: 1rem;
}
.vault-items-controls-btn.current,
.vault-items-controls-btn:nth-child(5) {
margin-right: 0;
}
.vault-items-controls-btn:hover {
background-color: #ddd;
}
.vault-items-controls-btn.current {
background-color: #888;
color: #fff;
}
/* Vault Items */
.vault-items-container {
display: flex;
flex-wrap: wrap;
flex: 1;
padding: 0 5rem 1.5rem;
}
.vault-item {
display: flex;
flex-direction: column;
flex-basis: 27rem;
height: 12.8rem;
margin-right: 1.5rem;
margin-bottom: 3rem;
border-radius: 0.2rem;
box-shadow: 0 0.1rem 0.3rem rgba(0, 24, 48, 0.2);
cursor: pointer;
}
.vault-item-info {
flex-basis: 3.2rem;
background-color: #fff;
padding: 0.9rem;
line-height: 1.2;
}
.vault-item-name {
font-size: 1.5rem;
font-weight: 600;
color: #465e7b;
}
.vault-item-summary {
font-size: 1.2rem;
font-weight: 400;
color: #666;
}
.vault-item-thumbnail {
display: flex;
justify-content: center;
align-items: center;
flex: 1;
font-size: 4.5rem;
color: #fff;
}
.address-item .vault-item-thumbnail {
background-color: #0a6353;
}
.bank-account-item .vault-item-thumbnail {
background-color: #4fa553;
}
.drivers-licence-item .vault-item-thumbnail {
background-color: #424f9f;
}
.medical-item .vault-item-thumbnail {
background-color: #e1403f;
}
.note-item .vault-item-thumbnail {
background-color: #9838b0;
}
.passport-item .vault-item-thumbnail {
background-color: #17a0e5;
}
.password-item .vault-item-thumbnail {
background-color: #4e8ff1;
}
.payment-card-item .vault-item-thumbnail {
background-color: #84b750;
}
.social-security-item .vault-item-thumbnail {
background-color: #fcd23e;
}
.wifi-item .vault-item-thumbnail {
background-color: #f25d2d;
}
.add-vault-item-btn {
position: fixed;
right: 2rem;
bottom: 2rem;
height: 5.8rem;
width: 5.8rem;
font-size: 2.8rem;
background-color: #d32d27;
color: #fff;
border-radius: 50%;
box-shadow: 0.4rem 0.4rem 1rem rgba(0, 0, 0, 0.3);
}
/* Side-bar */
.side-bar {
display: flex;
flex-direction: column;
flex: 0 0 6rem;
position: -webkit-sticky;
position: sticky;
top: 0;
height: 100vh;
font-size: 2rem;
background-color: #3c4a54;
color: #88959e;
}
.vault-controls-menu {
display: flex;
flex-direction: column;
flex: 1 0 0;
overflow-y: auto;
}
.vault-controls-menu::-webkit-scrollbar {
width: 1.2rem;
}
.vault-controls-menu::-webkit-scrollbar-track {
background-color: #3c4a54;
}
.vault-controls-menu::-webkit-scrollbar-thumb {
background-color: #22313b;
border-radius: 0.5rem;
border: 0.2rem solid #3c4a54;
}
.vault-menu-group {
margin-bottom: 1.8rem;
}
.vault-settings-menu {
font-size: 2.4rem;
box-shadow: 0 -0.2rem 0.2rem #36424b;
z-index: 1;
}
.menu-btn {
height: 4rem;
flex-shrink: 0;
}
.menu-btn:hover {
background-color: #36424b;
}
.menu-btn.current {
background-color: #22313b;
color: #fff;
}
.collapse-btn {
height: 6rem;
}
/*
The following code will only run if your browser supports CSS grid.
Remove or comment-out the code below to see how the browser will fall-back to flexbox styling.
*/
@supports (display: grid) {
body {
display: grid;
grid-template-columns: 6rem 1fr;
}
.main-content {
display: grid;
grid-template-rows: 6rem auto 1fr;
}
.top-bar {
display: grid;
grid-template-columns: auto minmax(19.2rem, 1fr) auto;
grid-column-gap: 1.6rem;
}
.vault-items-container {
display: grid;
grid-template-columns: repeat(auto-fill, 27rem);
grid-gap: 3rem 1.5rem;
}
.vault-items-controls {
display: grid;
grid-template-columns: 1fr repeat(4, auto);
grid-column-gap: 1rem;
}
.vault-items-controls-group {
display: grid;
grid-template-columns: repeat(2, auto);
}
.vault-item {
display: grid;
grid-template-rows: 1fr 5rem;
}
.side-bar {
display: grid;
grid-template-rows: auto minmax(auto, 1fr) auto;
}
.vault-controls-menu {
display: grid;
grid-row-gap: 1.8rem;
align-content: start;
}
.user-settings {
display: grid;
grid-template-columns: repeat(3, auto);
grid-column-gap: 1rem;
}
.user-info,
.vault-item,
.vault-search,
.vault-menu-group,
.vault-items-controls-btn {
margin: 0;
}
}
/*
Looks best in full-page view:
https://codepen.io/GeorgePark/full/PQweLr/
*/
LastPass Vault Layout with CSS Grid & Flexbox
---------------------------------------------
This pen shows how CSS Grid (with flexbox fallback) can be used to recreate the LastPass vault layout with no media queries.
A [Pen](https://codepen.io/harunpehlivan/pen/qxOmEV) by [HARUN PEHLİVAN](https://codepen.io/harunpehlivan) on [CodePen](https://codepen.io).
[License](https://codepen.io/harunpehlivan/pen/qxOmEV/license).
<!-- Main Content -->
<div class="main-content">
<!-- Top bar -->
<div class="top-bar">
<div class="logo">
<h1>LastPass<i class="fas fa-ellipsis-h"></i></h1>
</div>
<div class="vault-search">
<form>
<input type="search" class="search-input" placeholder="search my vault">
<i class="fas fa-search search-icon"></i>
</form>
</div>
<div class="user-settings">
<div class="user-image">
<i class="fas fa-user-circle"></i>
</div>
<ul class="user-info">
<li class="user-email">email@example.com</li>
<li class="user-type">Premium User</li>
</ul>
<div class="user-arrow-btn">
<i class="fas fa-caret-down"></i>
</div>
</div>
</div>
<!-- End of top bar -->
<!-- Vault items controls-->
<div class="vault-items-controls">
<h2>All items</h2>
<div class="vault-items-controls-btn btn">
<i class="fas fa-caret-up"></i>
</div>
<div class="vault-items-controls-btn btn">
<i class="fas fa-search-minus"></i>
</div>
<div class="vault-items-controls-group">
<div class="vault-items-controls-btn btn current">
<i class="fas fa-th-large"></i>
</div>
<div class="vault-items-controls-btn btn">
<i class="fas fa-list"></i>
</div>
</div>
<div class="vault-items-controls-btn btn">
<i class="fas fa-sort"></i>
</div>
</div>
<!-- End of vault items controls-->
<!-- Vault items container -->
<div class="vault-items-container">
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-amazon"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Amazon</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-apple"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Apple ID</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item bank-account-item">
<div class="vault-item-thumbnail">
<i class="fas fa-building"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Bank Account</h3>
<h4 class="vault-item-summary">Ending in 1234</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-behance-square"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Behance</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-codepen"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">CodePen</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-bitcoin"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Coinbase</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item payment-card-item">
<div class="vault-item-thumbnail">
<i class="fas fa-credit-card"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Credit Card</h3>
<h4 class="vault-item-summary">Ending in 1234</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-digital-ocean"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Digital Ocean</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-discord"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Discord</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item drivers-licence-item">
<div class="vault-item-thumbnail">
<i class="fas fa-car"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Drivers Licence</h3>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-dropbox"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Dropbox</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-facebook"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Facebook</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-github"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Github</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-google"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Google</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item address-item">
<div class="vault-item-thumbnail">
<i class="fas fa-address-book"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Home Address</h3>
<h4 class="vault-item-summary">123 Main Street</h4>
</div>
</div>
<div class="vault-item wifi-item">
<div class="vault-item-thumbnail">
<i class="fas fa-wifi"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Home Wi-fi</h3>
<h4 class="vault-item-summary">SSID12345</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-instagram"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Instagram</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-linkedin"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">LinkedIn</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item medical-item">
<div class="vault-item-thumbnail">
<i class="fas fa-heartbeat"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Medical Insurance</h3>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-microsoft"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Microsoft</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item note-item">
<div class="vault-item-thumbnail">
<i class="fas fa-sticky-note"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Online Recovery Codes</h3>
</div>
</div>
<div class="vault-item passport-item">
<div class="vault-item-thumbnail">
<i class="fas fa-globe"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Passport</h3>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-patreon"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Patreon</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-paypal"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">PayPal</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-pinterest"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Pinterest</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-reddit"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Reddit</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-snapchat"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Snapchat</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item social-security-item">
<div class="vault-item-thumbnail">
<i class="fas fa-balance-scale"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Social Security</h3>
<h4 class="vault-item-summary">Ending in 1234</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-spotify"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Spotify</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-stack-overflow"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Stack Overflow</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-steam"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Steam</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-trello"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Trello</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-twitch"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Twitch</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-twitter"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Twitter</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-uber"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Uber</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item password-item">
<div class="vault-item-thumbnail">
<i class="fab fa-vimeo"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Vimeo</h3>
<h4 class="vault-item-summary">email@example.com</h4>
</div>
</div>
<div class="vault-item address-item">
<div class="vault-item-thumbnail">
<i class="fas fa-address-book"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Work Address</h3>
<h4 class="vault-item-summary">321 Main Street</h4>
</div>
</div>
<div class="vault-item note-item">
<div class="vault-item-thumbnail">
<i class="fas fa-sticky-note"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Work Door Access Codes</h3>
</div>
</div>
<div class="vault-item wifi-item">
<div class="vault-item-thumbnail">
<i class="fas fa-wifi"></i>
</div>
<div class="vault-item-info">
<h3 class="vault-item-name">Work Wi-fi</h3>
<h4 class="vault-item-summary">SSID54321</h4>
</div>
</div>
<div class="add-vault-item-btn btn">+</div>
</div>
<!-- End of vault items container -->
</div>
<!-- End of main content -->
<!-- Side-bar -->
<div class="side-bar">
<div class="collapse-btn menu-btn btn">
<i class="fas fa-arrow-right"></i>
</div>
<div class="vault-controls-menu">
<div class="menu-btn btn current">
<i class="fas fa-home"></i>
</div>
<div class="vault-menu-group">
<div class="menu-btn btn">
<i class="fas fa-lock"></i>
</div>
<div class="menu-btn btn">
<i class="fas fa-sticky-note"></i>
</div>
<div class=" menu-btn btn">
<i class="fas fa-address-book"></i>
</div>
</div>
<div class="vault-menu-group">
<div class="menu-btn btn">
<i class="fas fa-credit-card"></i>
</div>
<div class="menu-btn btn">
<i class="fas fa-building"></i>
</div>
</div>
<div class="vault-menu-group">
<div class="menu-btn btn">
<i class="fas fa-globe"></i>
</div>
<div class="menu-btn btn">
<i class="fas fa-balance-scale"></i>
</div>
</div>
</div>
<div class="vault-settings-menu">
<div class="menu-btn btn">
<i class="fas fa-shield-alt"></i>
</div>
<div class="menu-btn btn">
<i class="fas fa-users"></i>
</div>
<div class="menu-btn btn">
<i class="fas fa-life-ring"></i>
</div>
<div class="menu-btn btn">
<i class="fas fa-cog"></i>
</div>
<div class="menu-btn btn">
<i class="fas fa-ellipsis-h"></i>
</div>
</div>
</div>
<!-- End of side-bar -->
以上是关于html 使用CSS Grid和Flexbox的LastPass Vault布局的主要内容,如果未能解决你的问题,请参考以下文章
CSS多列布局Multi-column伸缩布局Flexbox网格布局Grid详解
使用 CSS Grid 和 Flexbox 水平对齐位于不同网格单元格中的元素
Flexbox 中的 CSS Grid 仅在 Chrome 上无法正常工作