怎么把盒子1这个词用css调整到box1的中央位置?

来源:12-12 宰相肚里能撑船 - 使用padding为盒子设置内边距(填充)

remix1911

2016-03-17 21:38

<style type="text/css">

#box1{

    width:100px;

    height:100px;

    padding:10px;

    border:1px solid red;

    text-align:center;

    background:red;

}

</style>

</head>

<body>

<div id="box1">盒子1</div>


写回答 关注

7回答

  • weibo_我有一枚大果冻_0
    2016-03-17 22:06:25
    已采纳

    box1里面加个样式 line-height:100px;

    remix1...

    非常感谢!

    2016-03-17 22:58:11

    共 1 条回复 >

  • 希望成为大牛
    2016-03-17 22:58:11

    <style type="text/css">

    #box1{

        width:100px;

        height:100px;

        padding:10px;

        border:1px solid red;

        text-align:center;

        background:red;

        line-height:100px;

    }

    </style>

    </head>

    <body>

    <div id="box1" text-align:center;>盒子1</div>

    </body>


  • 梦之烟涯
    2016-03-17 22:06:30

    padding:50%;

  • 玖零儛
    2016-03-17 22:04:43


    <style type="text/css">
    #box1{
        width:100px;
        height:100px;
        padding:10px;
        border:1px solid red;
        text-align:center;
        background:red;
        margin:auto auto;
    }
    </style>
    </head>
    <body>
    <div id="box1" text-align:center;>盒子1</div>
    </body>


  • 学习1314
    2016-03-17 21:49:12

    center


    忆_卿

    那是水平居中 有什么用?

    2016-04-20 10:12:50

    共 1 条回复 >

  • huobobo
    2016-03-17 21:46:15

    text-align:center;

    忆_卿

    那是水平居中有什么用?

    2016-04-20 10:13:12

    共 1 条回复 >

  • Shmaur
    2016-03-17 21:44:52

    默认情况下,我们给盒子设置maring、padding和border的时候,不管设置的是什么单位的值,这些值都会计算在盒子的总体面积以内

初识HTML(5)+CSS(3)-升级版

HTML(5)+CSS(3)基础教程8小时带领大家步步深入学习标签用法和意义

1228570 学习 · 19080 问题

查看课程

相似问题