css tips

1. Vertically center multi-line text:

<div>
    <span>随便写点什么拿来测试</span>
</div>
div{
    width: 100px;
    height: 100px;
    margin: 100px auto;
    border: 1px solid #000;
    display: table;
}
span{
    line-height: 20px;
    display: table-cell;
    vertical-align: middle;
}

As shown in the figure:
write picture description here

2. Clear the gap: For example, there will be a gap between the content written in the span of two lines

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <div >
            <span>123</span>
            <span>456</span>
        </div>
    </body>
</html>


write picture description here
As shown in the figure, this is because a newline will render a space. If two spans are written on the same line, there will be no gap, but it is not in line with our habits, then use css to solve it:

div{
    font-size: 0;
}
span{
    font-size: 16px;
}

write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325728405&siteId=291194637