首页 > 其他 > 详细

用三或四个个div标签实现工字效果

时间:2015-11-19 00:26:36      阅读:258      评论:0      收藏:0      [点我收藏+]

使用重构的方式制作出一个如下图的水平、垂直都居中,短边为50px,长边为150px的红色“工”字。

a) 使用3个div完成

技术分享

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        body{margin:0;}
        #top,#bottom,#middle{background: #f00;position:absolute;left:50%;top:50%;}
        #top,#bottom{width:150px;height:50px;margin-left:-75px;}
        #top{margin-top: -75px}
        #bottom{margin-top: 25px;}
        #middle{width:50px;height:150px;margin:-75px 0 0 -25px;}
    </style>
    
</head>
<body>
    <div id="top"></div>
    <div id="middle"></div>
    <div id="bottom"></div>
</body>
</html>

b) 使用4个div完成;

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        body{margin:0;}
        #wrap{position:absolute;left:50%;top:50%;width:150px;height:150px;margin:-75px 0 0 -75px;}
        #top,#bottom,#middle{background: #f00;}
        #top,#bottom{width:150px;height:50px;}    
        #middle{width:50px;height:50px;margin:0 auto;}
    </style>
    
</head>
<body>
    <div id="wrap">
        <div id="top"></div>
        <div id="middle"></div>
        <div id="bottom"></div>
    </div>
</body>
</html>

 

用三或四个个div标签实现工字效果

原文:http://www.cnblogs.com/jiechen/p/4976206.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!