第二十八天:文字排版

金鱼都能懂的网页切版:22、23、24、25

文字排版

在文字排版里,html版面基本是一模一样,只是我们可以运用css部分让画面增添更多不一样的变化
其中有运用到几个值得学习的css技巧。

  • column-count: 2; 分几栏
  • column-gap: 30px; gap距离
  • 透过伪元素做出文字背景
  • 用flex-shrink: 0;,使两个块不会进行收缩
  • 透过 text-shadow: 6px 6px 0px #eee; 做出文字背景
  • flex-grow: 1;可以自动填满宽度
  • 使用伪元素搭配 border 做出文章前後的点缀效果

版面一

https://codepen.io/mikeyam/pen/ExyjmZe

用伪元素做出下底线

.container h1::after{
    content: '';
    display: block;
    height: 4px;
    width: 5em;
    background-color: #000;
    margin-left: auto;
}
.container .text{
    width: 800px;
    box-sizing: border-box;
    padding: 0 15px;
    column-count: 2;
    column-gap: 30px;
}

版面二

https://codepen.io/mikeyam/pen/NWrqjgp

改用float: left;呈现文绕图

.container{
    width: 1200px;
    /* display: flex; */
    margin: auto;
    padding: 100px 0;
}
.container h1{
    width: 300px;
    text-align: right;
    box-sizing: border-box;
    padding: 15px;
    border-right: 3px solid #000;
    float: left;
    margin-right: .5em;
}
.container .text{
    box-sizing: border-box;
    padding: 0 15px;
}

版面三

https://codepen.io/mikeyam/pen/zYBGwPm

这个版面是在文字上使用伪元素做出文字背景
并且学到使用 position: absolute; 时,宽度会不见,因此要加上 width: 100%;

.container h1::after{
    content: '';
    position: absolute;
    /* 使用定位,宽度会不见 */
    width: 100%;
    bottom: 0;
    display: block;
    height: 70px;
    background: #EEE;
    z-index: -1;
}
.container .text{
    box-sizing: border-box;
    padding: 0 15px;
    column-count: 2;
    column-gap: 30px;
}
.container .text p::first-letter{
    font-size: 40px;
    float: left;
    padding-right: 10px;
}

版面四

https://codepen.io/mikeyam/pen/zYBGMLG?editors=1100

这个版面是把文字使用定位方式,水平垂直居中
并且使用:first-child:first-letter 做出首字大写

.container{
    width: 1200px;
    margin: auto;
    position: relative;
    margin-top: 200px;
}
.container h1{
    width: 400px;
    box-sizing: border-box;
    padding: 15px;
    background: #eee;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
    display: flex;
    align-items: center;
    text-align: center;
    font-size: 60px;
}
.container p:first-child:first-letter{
font-size: 40px;
float: left;
padding-right: 6px;
}

版面五

https://codepen.io/mikeyam/pen/gOMpExG?editors=1100

这个版面同样是透过伪元素做出文字背景
并且学到 设定绝对定位时,会被强制转成block
搭配transform: rotate(20deg);做出旋转效果

.container h1{
    width: 400px;
    box-sizing: border-box;
    padding: 15px;
    float: right;
    font-size: 90px;
    color: #aaa;
    position: relative;
}
.container h1::before{
    content: '';
    display: block;
    position: absolute;
    /* 设定绝对定位时,会被强制转成block */
    width: 200px;
    height: 200px;
    border: 30px solid #F1C555;
    z-index: -1;
    bottom: 0;
    left: 60px;
    transform: rotate(20deg);
}

版面六

https://codepen.io/mikeyam/pen/bGedJaX?editors=0110

这个版面先用flex做排版
在用flex-shrink: 0;,使两个块不会进行收缩
搭配position: absolute; 和 overflow: hidden;做出背景文字

.container{
    width: 1200px;
    margin: auto;
    display: flex;
    position: relative;
    box-shadow: 0 0  30px #ccc;
    justify-content: flex-end;
    overflow: hidden;
}
.container h1{
    width: 100%;
    flex-shrink: 0;
    box-sizing: border-box;
    font-size: 160px;
    padding-left: 15px;
    color: #DDD;
    position: absolute;
    left: 0;
    top: -60px;
    line-height: 1.1em;
}
.container .text{
    width: 600px;
    flex-shrink: 0;
    box-sizing: border-box;
    column-count: 2;
    column-gap: 30px;
    padding: 15px;
    position: relative;
    z-index: 1;
}

版面七

https://codepen.io/mikeyam/pen/BazNevp?editors=0110

透过 text-shadow: 6px 6px 0px #eee; 做出文字背景

.container h1{
    width: 100%;
    flex-shrink: 0;
    box-sizing: border-box;
    font-size: 160px;
    padding-left: 15px;
    color: #fff;
    position: absolute;
    left: 0;
    top: -60px;
    line-height: 1.1em;
    text-shadow: 6px 6px 0px #eee;
}

版面八

https://codepen.io/mikeyam/pen/oNLXrgg?editors=0110

透过伪元素做出 h1 两条横线
flex-grow: 1;可以自动填满宽度

.container h1::before,
.container h1::after{
    content: '';
    display: block;
    height: 5px;
    /* width: 2em; */
    flex-grow: 1;
    /* 拿掉宽度,一样可以填满 */
    background-color: #aaa;
    margin: auto;
}
.container h1::before{
    margin-right: 1em;
}
.container h1::after{
    margin-left: 1em;
}

版面九

https://codepen.io/mikeyam/pen/jOrPjyp?editors=0100

使用伪元素搭配 border 做出文章前後的点缀效果

.container .text::before,
.container .text::after{
    content: '';
    position: absolute;
    width: 50px;
    height: 50px;
}
.container .text::before{
    top: 0;
    left: 0;
    border-top: 3px solid #AAA;
    border-left: 3px solid #AAA;
}
.container .text::after{
    right: 0;
    bottom: 0;
    border-right: 3px solid #AAA;
    border-bottom: 3px solid #AAA;
}

<<:  这些日子我学到的JavaScript:Day24- HTML 的自订资料属性

>>:  第27天:this(2)

Day 15:Remove Duplicates from linked list

这题开始之前先来介绍一下Linked list(连结串列)的资料结构。 Linked list(连结...

Day1 初探NodeJS

学习新知的第一步是初步了解原理,学习新的开发技术除了原理也要先学习设定环境。 写在最最最前面 虽然N...

铁人赛 Day17 -- 搞了这麽多天,来试着做会员登入介面吧

今日目标 : 不罗嗦,直接附上Code css .login{0 background-color:...

Day08-元件特性

元件是Vue最强大的功能之一,可以将重复的程序码封装,提高效率和维护性。 元件组织 把网页分成区块,...

[如何关掉TP-Link WR841N的Beacon]

目前在做学校实验,用analyzer收集wifi讯号时都会出现beacon的干扰,请问该如何关掉他或...