随笔记录方便自己和同路人查阅,学习CSS时最好先学会HTML。

#------------------------------------------------我是可耻的分割线-------------------------------------------

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>input系列</title>
</head>
<body>
    <div class="c1 c2" style="border:1px solid red; width:50%; height:100px; font-size:30px; text-align:center;"> nihaone</div>
</body>
</html>

效果:

CSS基础(十)-- 边框及其他样式之让字体居中

text-align:center;其中text-align表示设置字体位置center表示中间,这种只能水平居中,不能上下居中,有一个比较好的办法,见下面代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>input系列</title>
</head>
<body>
    <div class="c1 c2" style="
    border:1px solid red;
    width:50%;
    height:100px;
    font-size:30px;
    text-align:center;
    line-height:100px;
"> nihaone</div>
</body>
</html>

效果:

CSS基础(十)-- 边框及其他样式之让字体居中

line-height:100px;表示把字体放到100px中间,这个数要和高度一致,不然格式就错了比如高40px,你把字体放到100px居中

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>input系列</title>
</head>
<body>
    <div class="c1 c2" style="
    border:1px solid red;
    width:50%;
    height:400px;
    font-size:30px;
    text-align:center;
    line-height:100px;
"> nihaone</div>
</body>
</html>

 

效果:

CSS基础(十)-- 边框及其他样式之让字体居中

 

相关文章:

  • 2021-11-15
  • 2021-12-13
  • 2021-11-22
  • 2022-01-16
  • 2021-06-19
  • 2021-09-21
  • 2021-12-26
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2022-02-01
  • 2021-12-22
  • 2021-05-29
  • 2021-12-02
  • 2021-04-21
相关资源
相似解决方案