html怎么把一个盒子放在另一个盒子中间

 我来答
幻翼高达Zero
2019-07-09 · TA获得超过1.7万个赞
知道答主
回答量:499
采纳率:0%
帮助的人:7.1万
展开全部

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<body>标签中,输入html代码:。

<div style="border: 1px solid blue;position:relative;width: 200px;height: 80px;">

<div style="border: 1px solid blue;top: 19px;left: 49px;position:absolute;width: 100px;height: 40px;"></div>

</div>

3、浏览器运行index.html页面,此时一个盒子放在了另一个盒子的正中央。

百度网友247ce63
2017-08-07 · 超过12用户采纳过TA的回答
知道答主
回答量:18
采纳率:100%
帮助的人:10.2万
展开全部

绝对居中方法,让一个子标签水平垂直居中在父标签的中央,如果你知道子标签的宽度和高度,可以使用这类方法:

<html>
<body>
    <style>
        .box1{
            width: 500px;
            height: 500px;
            position: relative;
            background-color: #2793ff;
        }
        .box2{
            width: 100px;
            height: 100px;
            display: block;
            position: absolute;
            top: 0px; left: 0px;
            right: 0px; bottom: 0px;
            margin: auto;
            background-color: #e55581;
        }
    </style>
    <div class="box1">
        <div class="box2"></div>
    </div>
</body>
</html>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
生活的简单之处
2015-12-21 · TA获得超过967个赞
知道小有建树答主
回答量:1627
采纳率:45%
帮助的人:140万
展开全部
------style----
*{margin:0;padding:0}

.div1{width:200px;height:200px;background:red;}
.div2{width:100px;height:100px;background:green;margin:0 auto; }
就是设置margin或者padding或者定位实现的


-----------html------------------
<div class="div1">
    <div class="div2">

    </div>
</div>
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
爱龙2007
2017-07-19 · TA获得超过123个赞
知道答主
回答量:26
采纳率:0%
帮助的人:4.6万
展开全部
可以利用css3的flex布局
.box{
display: flex;
justify-content:center;
background:#0099cc
}
<div class="box">
<h1>flex弹性布局justify-content属性实现元素水平居中</h1>
</div>
flex详情请查看css文档有详细说明,或http://www.cnblogs.com/lxiang/p/4766813.html
有详细说明
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
孤狼0114
2015-12-21 · TA获得超过130个赞
知道小有建树答主
回答量:338
采纳率:0%
帮助的人:54.4万
展开全部
用定位
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式