自檢:前端知識(shí)清單——手寫布局

前言

題目來(lái)自ConardLi的blog
寫的是自己的題解,水平有限采驻,所以僅供參考
代碼會(huì)整合在github双揪,覺得有幫助就給個(gè)star吧~

正文

二、HTML和CSS

手寫

1.手寫圖片瀑布流效果

通過(guò)css multi-column去實(shí)現(xiàn)多列布局實(shí)現(xiàn)瀑布流

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        body {
            background: #eaedf1;
        }

        #myModal {
            display: none;
            position: fixed;
            left: 0;
            top: 0;
            width: 100vw;
            height: 100vh;
            opacity: 0;
        }

        #bg {
            display: none;
            position: fixed;
            left: 30%;
            top: 10%;
            width: 40vw;
            height: 80vh;
            justify-content: center;
            align-items: center;
        }

        #img {
            height: 100%;
            object-fit: contain;
            animation-name: zoom;
            animation-duration: 0.6s;
        }

        .root {
            margin: 0 auto;
            width: 1200px;
            column-count: 4;
            column-gap: 20px;
            padding-bottom: 20px;
        }

        .item {
            margin-bottom: 10px;
            break-inside: avoid;
            background: #fff;
            border-radius: 15px;
            overflow: hidden;
        }

        .item:hover {
            box-shadow: 2px 2px 2px rgba(71, 70, 70, 0.5);
            opacity: 0.8;
        }

        .itemImg {
            width: 100%;
            vertical-align: middle;
            cursor: pointer;
        }

        @keyframes zoom {
            from {
                transform: scale(0)
            }

            to {
                transform: scale(1)
            }
        }

        @media screen and (min-width:700px) and (max-width: 1024px) {
            .root {
                width: 700px;
                column-count: 3;
            }

            #img {
                max-width: 100%;
                max-height: 100%;
            }

            #bg {
                left: 20%;
                width: 60vw;
            }
        }

        @media screen and (min-width:420px) and (max-width: 700px) {
            .root {
                width: 400px;
                column-count: 2;
            }

            #img {
                max-width: 100%;
                max-height: 100%;
            }

            #bg {
                left: 15%;
                width: 70vw;
            }
        }

        @media screen and (max-width: 420px) {
            .root {
                width: 250px;
                column-count: 1;
            }

            #img {
                width: 100%;
                height: 100%;
                object-fit: fill;
            }

            #bg {
                left: 10%;
                width: 80vw;
            }
        }
    </style>
</head>

<body>
    <div class="root">
        <div class="item">
            <img onclick="spread(this)" class="itemImg" src="./img1.jpg" alt="">
        </div>
        <div class="item">
            <img onclick="spread(this)" class="itemImg" src="./img2.jpg" alt="">
        </div>
        <div class="item">
            <img onclick="spread(this)" class="itemImg" src="./img3.jpg" alt="">
        </div>
        <div class="item">
            <img onclick="spread(this)" class="itemImg" src="./img4.jpg" alt="">
        </div>
        <div class="item">
            <img onclick="spread(this)" class="itemImg" src="./img5.jpg" alt="">
        </div>
        <div class="item">
            <img onclick="spread(this)" class="itemImg" src="./img6.jpg" alt="">
        </div>
        <div class="item">
            <img onclick="spread(this)" class="itemImg" src="./img7.jpg" alt="">
        </div>
        <div class="item">
            <img onclick="spread(this)" class="itemImg" src="./img8.jpg" alt="">
        </div>
        <div class="item">
            <img onclick="spread(this)" class="itemImg" src="./img9.jpg" alt="">
        </div>
        <div class="item">
            <img onclick="spread(this)" class="itemImg" src="./img10.jpg" alt="">
        </div>
    </div>
    <div id="myModal">
    </div>
    <div id="bg">
        <img id="img">
    </div>
    <script>
        const modal = document.getElementById('myModal')
        const img = document.getElementById('img')
        const bg = document.getElementById('bg')

        const spread = function (e) {
            modal.style.display = 'block'
            bg.style.display = 'flex'
            img.src = e.src
        }
        modal.onclick = function () {
            modal.style.display = 'none'
            bg.style.display = 'none'
        }
    </script>
</body>

</html>

效果圖:


2至耻、使用CSS繪制幾何圖形(圓形、三角形镊叁、扇形尘颓、菱形等)

圓形:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .circle {
            border-radius: 50%;
            width: 200px;
            height: 200px;
            background: red;
        }
    </style>
</head>

<body>
    <div class="circle">

    </div>
</body>


</html>

三角形:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .triangle {
            width: 0;
            height: 0;
            border: transparent 100px solid;
            border-bottom-color: red;
        }
    </style>
</head>

<body>
    <div class="triangle">

    </div>
</body>

</html>

扇形:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .triangle {
            width: 0;
            height: 0;
            border: transparent 100px solid;
            border-bottom-color: red;
            border-bottom-left-radius: 50%;
            border-bottom-right-radius: 50%;
        }
    </style>
</head>

<body>
    <div class="triangle">

    </div>
</body>

</html>

菱形:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .square {
            width: 100px;
            height: 100px;
            clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
            background: red
        }
    </style>
</head>

<body>
    <div class="square">

    </div>
</body>

</html>

3、使用純CSS實(shí)現(xiàn)曲線運(yùn)動(dòng)(貝塞爾曲線)

暫時(shí)不會(huì)晦譬,待更新

4疤苹、實(shí)現(xiàn)常用布局(三欄、圣杯敛腌、雙飛翼卧土、吸頂),可是說(shuō)出多種方式并理解其優(yōu)缺點(diǎn)

三欄布局:

  • float方案
    html:
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .main {
            height: 100vh;
        }

        * {
            margin: 0;
            padding: 0;
        }

        .left-wrap {
            float: left;
            width: 200px;
            height: 100vh;
            background: #1ba1e2
        }

        .right-wrap {
            float: right;
            width: 200px;
            height: 100vh;
            background: #1ba1e2
        }

        .center-wrap {
            width: 100%;
            height: 100vh;
        }
    </style>
</head>

<body>
    <div class="main">
        <div class="left-wrap"></div>
        <div class="right-wrap"></div>
        <div class="center-wrap">
            This is the center
        </div>
    </div>
</body>

</html>
  • position方案
    html:
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .main {
            height: 100vh
        }

        .left {
            position: absolute;
            top: 0;
            left: 0;
            width: 200px;
            background: #1ba1e2;
            height: 100vh;
        }

        .right {
            position: absolute;
            top: 0;
            right: 0;
            width: 200px;
            background: #1ba1e2;
            height: 100vh;
        }

        .main {
            margin: 0 200px;
            height: 100vh
        }
    </style>
</head>

<body>
    <div class="main">
        <div class="left"></div>
        <div class="right"></div>
        <div class="center">this is a center</div>
    </div>
    <script>

    </script>
</body>

</html>
  • flex方案
    html:
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .main {
            display: flex;
        }

        * {
            padding: 0;
            margin: 0;
        }

        .left {
            width: 200px;
            background: #1ba1e2;
            height: 100vh;
        }

        .center {
            flex: 1;
            height: 100vh;
        }

        .right {
            width: 200px;
            order: 1;
            background: #1ba1e2;
            height: 100vh;
        }
    </style>
</head>

<body>
    <div class="main">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
    </div>
</body>

</html>
  • grid方案
    html:
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .container {
            position: relative;
            display: grid;
            grid-template-columns: 200px auto 200px;
            grid-template-rows: 100%;
            grid-template-areas: "lt cr rt"
        }

        * {
            margin: 0;
            padding: 0;
        }

        div {
            height: 100vh
        }

        .center-wrap {
            grid-area: cr;
        }

        .left-wrap {
            grid-area: lt;
            background: #1ba1e2;
        }

        .right-wrap {
            grid-area: rt;
            background: #1ba1e2;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="left-wrap"></div>
        <div class="center-wrap"></div>
        <div class="right-wrap"></div>
    </div>
</body>

</html>
  • table方案:
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            width: 100%;
            height: 100%;

        }

        table {
            width: 100%;
            height: 100%;
            text-align: center;
            font-size: 30px;

        }

        table tr td {
            border-width: 0;
        }
    </style>
    <title>Document</title>
</head>

<body>
    <table>
        <tbody>
            <tr height='100%''>
                <td width = ' 200' bgcolor="#1ba1e2">

                </td>
                <td>
                    this is center
                </td>
                <td width='200' bgcolor="#1ba1e2">

                </td>
            </tr>
        </tbody>
    </table>
</body>

</html>

圣杯布局:暫時(shí)不會(huì)
雙飛翼布局:暫時(shí)不會(huì)
吸頂布局:暫時(shí)不會(huì)

5像樊、實(shí)現(xiàn)等比寬高的div

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末尤莺,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子生棍,更是在濱河造成了極大的恐慌颤霎,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,602評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件涂滴,死亡現(xiàn)場(chǎng)離奇詭異友酱,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)柔纵,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,442評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門缔杉,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人搁料,你說(shuō)我怎么就攤上這事或详〗裕” “怎么了?”我有些...
    開封第一講書人閱讀 152,878評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵鸭叙,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我拣宏,道長(zhǎng)沈贝,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,306評(píng)論 1 279
  • 正文 為了忘掉前任勋乾,我火速辦了婚禮宋下,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘辑莫。我一直安慰自己学歧,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,330評(píng)論 5 373
  • 文/花漫 我一把揭開白布各吨。 她就那樣靜靜地躺著枝笨,像睡著了一般。 火紅的嫁衣襯著肌膚如雪揭蜒。 梳的紋絲不亂的頭發(fā)上横浑,一...
    開封第一講書人閱讀 49,071評(píng)論 1 285
  • 那天,我揣著相機(jī)與錄音屉更,去河邊找鬼徙融。 笑死,一個(gè)胖子當(dāng)著我的面吹牛瑰谜,可吹牛的內(nèi)容都是我干的欺冀。 我是一名探鬼主播,決...
    沈念sama閱讀 38,382評(píng)論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼萨脑,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼隐轩!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起砚哗,我...
    開封第一講書人閱讀 37,006評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤龙助,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后蛛芥,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體提鸟,經(jīng)...
    沈念sama閱讀 43,512評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,965評(píng)論 2 325
  • 正文 我和宋清朗相戀三年仅淑,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了称勋。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,094評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡涯竟,死狀恐怖赡鲜,靈堂內(nèi)的尸體忽然破棺而出空厌,到底是詐尸還是另有隱情,我是刑警寧澤银酬,帶...
    沈念sama閱讀 33,732評(píng)論 4 323
  • 正文 年R本政府宣布嘲更,位于F島的核電站,受9級(jí)特大地震影響揩瞪,放射性物質(zhì)發(fā)生泄漏赋朦。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,283評(píng)論 3 307
  • 文/蒙蒙 一李破、第九天 我趴在偏房一處隱蔽的房頂上張望宠哄。 院中可真熱鬧,春花似錦嗤攻、人聲如沸毛嫉。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,286評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)承粤。三九已至,卻和暖如春恶耽,著一層夾襖步出監(jiān)牢的瞬間密任,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,512評(píng)論 1 262
  • 我被黑心中介騙來(lái)泰國(guó)打工偷俭, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留浪讳,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 45,536評(píng)論 2 354
  • 正文 我出身青樓涌萤,卻偏偏與公主長(zhǎng)得像淹遵,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子负溪,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,828評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容