博主信息
博文 18
粉丝 0
评论 0
访问量 16929
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
写一个盒子-2019年07月04日 22时 10分
高明博客
原创
1214人浏览过

针对学习的盒子模型,写一个盒子,使用padding,margin,border完整写法和简写。具体代码如下:

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>写一个盒子</title>
    <style>
        .box{
            width: 200px;
            height: 200px;
            background-color: #ffb3ac;
            line-height: 200px;
            font-size: 50px;
            text-align: center;

            /*设置内边距padding,上20px,右30px下20px,左30px*/
            /*padding-top:20px;*/
            /*padding-right: 30px;*/
            /*padding-bottom: 20px;*/
            /*padding-left: 30px;*/

            /*padding功能简写 4个参数写法*/
            /*padding: 20px 30px 20px 30px;*/

            /*padding功能简写 3个参数写法*/
            /*padding: 20px 30px 20px;*/

            /*padding功能简写 2个参数写法*/
            padding: 20px 30px;



            /*设置外边距margin,上20px,右30px下20px,左30px*/
            /*margin-top:20px;*/
            /*margin-right: 30px;*/
            /*margin-bottom: 20px;*/
            /*margin-left: 30px;*/

            /*margin功能简写 4个参数写法*/
            /*margin: 20px 30px 20px 30px;*/

            /*margin功能简写 3个参数写法*/
            /*margin: 20px 30px 20px;*/

            /*margin功能简写 2个参数写法*/
            margin: 20px 30px;


            /*设置盒子4个边框border,宽度2x,样式dashed,颜色yellow*/

            /*/设置上边框border-top*/
            /*border-top-width: 2px;*/
            /*border-top-style: dashed;*/
            /*border-top-color: yellow;*/
            /*设置上边框代码简写*/
            /*border-top: 2px dashed yellow;*/

            /*/设置右边框border-right*/
            /*border-right-width: 2px;*/
            /*border-right-style: dashed;*/
            /*border-right-color: yellow;*/
            /*设置右边框代码简写*/
            /*border-right: 2px dashed yellow;*/

            /*/设置下边框border-bottom*/
            /*border-bottom-width: 2px;*/
            /*border-bottom-style: dashed;*/
            /*border-bottom-color: yellow;*/
            /*设置下边框代码简写*/
            /*border-bottom: 2px dashed yellow;*/

            /*/设置左边框border-left*/
            /*border-left-width: 2px;*/
            /*border-left-style: dashed;*/
            /*border-left-color: yellow;*/
            /*设置左边框代码简写*/
            /*border-left: 2px dashed yellow;*/

            /*border总的设置4个边框样式简写*/
            border:2px dashed yellow;
        }
    </style>
</head>
<body>
<!--要求用到margin,padding,border, 并用到它们的完整语法, 简写语法-->
<div class="box">
      盒子
</div>

</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

本地运行效果截图:

0704.png

总结,css中,一切可见元素皆可称为盒子,盒子有内边距,外边距,边框是盒子重要组成部分,在网页样式布局中起到非常重要的作用,具体使用,请查看案例代码。

批改状态:合格

老师批语:前端变化非常快, 其实现在这种基本的盒子已不多用, 更多的在用一些变形盒子, 有空了解一下
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学