๐ŸŒฑ → ๐ŸŒณ

[HTML] Span Tag ๋ณธ๋ฌธ

Client/HTML CSS

[HTML] Span Tag

BAY 2022. 6. 21. 17:06
728x90

 ๐Ÿ“Œ ์งˆ๋ฌธ (์˜ค๋ฅ˜ ๋ฐœ์ƒ)

codingon ๊ณผ์ œ๋ฅผ ํ•˜๋˜ ์ค‘ ์งˆ๋ฌธ์ด ๋ฐœ์ƒํ•˜์˜€๋‹ค.

๊ณผ์ œ๋Š” div์™€ span tag๋ฅผ ์ด์šฉํ•˜์—ฌ 2022 7์›” ๋‹ฌ๋ ฅ ๋งŒ๋“ค๊ธฐ

span tag ์˜ค๋ฅ˜ ๋ฐœ์ƒ

์œ„ ์‚ฌ์ง„์—์„œ ๊ฐ™์€ span tag์— display:inline-block; ํ–ˆ๋Š”๋ฐ 

text๊ฐ’์ด ๋“ค์–ด๊ฐ„ span์€ ์•„๋ž˜๋กœ(์œ„์— ๋นˆ์นธ ๋ฐœ์ƒ), text๊ฐ’์ด ๋“ค์–ด๊ฐ€์ง€ ์•Š์€ span์€ ์œ„๋กœ ๋ถ™์–ด์„œ(์•„๋ž˜ ๋นˆ์นธ ๋ฐœ์ƒ) 

text๊ฐ€ ์žˆ๋Š” span๊ณผ ์—†๋Š” span์ด ๊ฐ™์ด ๋“ค์–ด๊ฐ„ div์นธ๋งŒ height๊ฐ€ ์ปค์ ธ์žˆ์Œ

๋ญ๊ฐ€ ๋ฌธ์ œ์ผ๊นŒ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์ด ๋ญ˜๊นŒ 

 

๐Ÿ“Œ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

span ์š”์†Œ์˜ ๊ธฐ๋ณธ ์†์„ฑ์ธ vertical-align ์†์„ฑ์ด base-line ์œผ๋กœ ์„ค์ •์ด ๋˜์–ด์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ์˜€๋‹ค.

์ฆ‰, span ์š”์†Œ์˜ ๊ฒฝ์šฐ ์ˆ˜์ง ์ •๋ ฌ์„ ๊ธ€์ž์˜ base-line ์— ๋งž์ถ”์–ด์„œ ์ˆ˜์ง ์ •๋ ฌ์ด ์ผ์–ด๋‚˜๋Š”๋ฐ

  ๊ฐ™์€ ๊ณต๋ฐฑ ๋ฌธ์ž๋„ ์—†๋Š” span ์š”์†Œ๋Š” ๋ง ๊ทธ๋Œ€๋กœ ๋ฌธ์ž๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์—

inline-block์œผ๋กœ ์„ ์–ธํ•œ span ์š”์†Œ์˜ ์ตœํ•˜๋‹จ์ด ํ•ด๋‹น ์š”์†Œ์˜ base-line ์ด ๋œ๋‹ค.

๋”ฐ๋ผ์„œ ์ฝ”๋“œ์—์„œ ํ•ด๋‹น span ์š”์†Œ์˜ ์ตœํ•˜๋‹จ๊ณผ ์˜†์— ์žˆ๋Š” ์ˆซ์ž basline ์ด ์ •ํ™•ํ•˜๊ฒŒ ์ผ์น˜ํ•˜์‹œ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. 

ํ•ด๋‹น ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐ ํ•˜์‹œ๊ธฐ ์œ„ํ•ด์„œ๋Š” span ์š”์†Œ์— vertical-align ์†์„ฑ ๊ฐ’์„ bottom ์œผ๋กœ ๋งž์ถ”๋ฉด

๊ฐ span ์š”์†Œ์˜ ์ตœํ•˜๋‹จ์„ ๊ธฐ์ค€์œผ๋กœ ์ˆ˜์ง ์ •๋ ฌ์ด ๋ฐœ์ƒํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ ๋œ๋‹ค.

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

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>span tag</title>
    <style>
        span {
            display: inline-block;
            /* vertical-align: baseline; */
            vertical-align: bottom;
            width: 100px;
            height: 100px;
        }

        .test1 {
            background-color: orange;
        }

        .test2 {
            font-size: 30px;
            background-color: skyblue;
        }

        .test3 {
            font-size: 50px;
            background-color: yellow;
        }
    </style>
</head>

<body>
    <span class="test1"></span>
    <span class="test2">2</span>
    <span class="test3">1</span>

</body>
</html>

 

vertical-align: baseline; ๋กœ ํ–ˆ์„ ๋•Œ
vertical-align: bottom; ๋กœ ๊ธฐ๋ณธ ๊ฐ’์„ ๋ฐ”๊ฟ”์ฃผ์—ˆ์„ ๋•Œ

 

 

CSS ์ ์šฉํ•  ๋•Œ ๋ญ”๊ฐ€ ๋‚ด ๋œป๋Œ€๋กœ ์•ˆ๋œ๋‹ค๋ฉด,

ํ•ด๋‹น ์š”์†Œ์˜ ๊ธฐ๋ณธ๊ฐ’์„ ํ™•์ธํ•ด๋ณด์ž

728x90

'Client > HTML CSS' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[CSS] CSS ์ƒ์†  (0) 2022.06.21
[HTML] Select Tag, Input Tag  (0) 2022.06.21
[HTML] HTML ๊ตฌ์กฐ  (0) 2022.06.19
[CSS] Flexbox  (0) 2022.05.10
[CSS] ๋ ˆ์ด์•„์›ƒ ์ •๋ฆฌ display, position ์™„์„ฑ  (0) 2022.05.10