Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

MoonLight
MoonLight

Posted on

Css units

<divclass="box"></div>
Enter fullscreen modeExit fullscreen mode
body{width:300px;}.box{/* ⚜️ 50% of the width of body (300px) */width:50%;height:100px;background-color:gold;border-top:3pxsolidorange;}
Enter fullscreen modeExit fullscreen mode

Image description

body{margin:0px;}.box{/* ⚜️ 50% of the viewport */width:50vw;/* ⚜️ 100% of the viewport */height:100vh;background-color:gold;border-top:3pxsolidorange;}
Enter fullscreen modeExit fullscreen mode

Image description

body{margin:0px;}.box{/* ⚜️ because the font size defaults is 16 px    so width will be 10 * 16 = 160 px */width:10em;height:100vh;background-color:gold;border-top:3pxsolidorange;}
Enter fullscreen modeExit fullscreen mode

Image description

body{margin:0px;}.box{/* ⚜️ change font size */font-size:20px;/* ⚜️ because the font size defaults is 16 px    so width will be 10 * 20 = 200 px */width:10em;height:100vh;background-color:gold;border-top:3pxsolidorange;}
Enter fullscreen modeExit fullscreen mode

Image description

استفاده از
rem
محاسبه رو آسون تر می کنه

html{/* 1️⃣ it means 62.5% of 16px = 10px     so 10px will be root font size!*/font-size:62.5%;}body{margin:0px;}.box{/* 2️⃣ rem x root font size     the result will be 150 px*/width:15rem;height:100vh;background-color:gold;border-top:3pxsolidorange;}
Enter fullscreen modeExit fullscreen mode

Image description

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Joined

More fromMoonLight

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp