フロントエンド毎日戦闘:#74ビデオは、純粋なCSSでのMacBook Proのを作成する方法を示しています

画像のキャプション

結果のプレビュー

押してフルスクリーンプレビューへのリンクをクリックして、現在のページをプレビューする権利「プレビュー]をクリックします」ボタンをクリックします。

https://codepen.io/comehop​​e/pen/MXNNyR

インタラクティブビデオ

このビデオでは、対話型である、あなたがビデオを編集して、コードのビデオを一時停止することができます。

クロム、サファリ、エッジオープンビューを使用してください。

https://scrimba.com/p/pEgDAM/cyEPrue

ソースコードのダウンロード

毎日のフロントエンド戦闘シリーズ完全なソースコードはgithubのからダウンロードできます。

https://github.com/comehop​​e/front-end-daily-challenges

コード読み取り

定義されたDOM、容器、2つの要素を含む画面と塩基を表します。

<div class="macbook">
    <span class="screen"></span>
    <span class="base"></span>
</div>

中央揃え:

body {
    margin: 0;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, white, gray);
}

定義されたコンテナのサイズであります:

.macbook {
    width: 50em;
    font-size: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

画面の輪郭を描きます。

.screen {
    width: 40em;
    height: calc(40em * 0.667);
    background-color: black;
    border-radius: 3% 3% 0 0 / 5%;
    border: 0.2em solid silver;
    border-bottom: none;
    position: relative;
}

光と影が画面に描画します:

.screen {
    position: relative;
}

.screen::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: radial-gradient(
        circle at right bottom,
        rgba(255, 255, 255, 0.4) 75%,
        rgba(255, 255, 255, 0.6) 75%
    );
    margin: 4.3% 3.2%;
}

ベースのアウトラインを描きます:

.base {
    position: relative;
}

.base {
    width: inherit;
    height: 1.65em;
    background: linear-gradient(
        white,
        white 55%,
        #999 60%,
        #222 90%,
        rgba(0, 0, 0, 0.1) 100%
    );
    border-radius: 0 0 10% 10% / 0 0 50% 50%;
}

照明効果はベースとして増加します:

.base::before {
    content: '';
    position: absolute;
    width: inherit;
    height: 55%;
    background: linear-gradient(
        to right,
        rgba(0, 0, 0, 0.5) 0%,
        rgba(255, 255, 255, 0.8) 1%,
        rgba(0, 0, 0, 0.4) 4%,
        transparent 15%,
        rgba(255, 255, 255, 0.8) 50%,
        transparent calc(100% - 15%),
        rgba(0, 0, 0, 0.4), calc(100% - 4%),
        rgba(255, 255, 255, 0.8) calc(100% - 1%),
        rgba(0, 0, 0, 0.5) 100%
    );
}

オープンスクリーンギャップのベースを描きます。

.base::after {
    content: '';
    position: absolute;
    width: 7em;
    height: 0.7em;
    background-color: #ddd;
    left: calc(50% - 7em / 2);
    box-shadow: 
        inset -0.5em -0.1em 0.3em rgba(0, 0, 0, 0.2),
        inset 0.5em 0.1em 0.3em rgba(0, 0, 0, 0.2);
    border-radius: 0 0 7% 7% / 0 0 95% 95%;
}

私たちは完了です。

おすすめ

転載: www.cnblogs.com/baimeishaoxia/p/11888614.html