问答详情
源自:2-3 编程练习

为什么什么都没有显示

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<style>

    .myBox{

        width:200px;

        height:100px;

        border:1px solid red;

        margin-top:10px;

        padding-left:15px;

    }

</style>

<div class="myBox">Hello World!</div>



</head>

<body>



<div class="myBox1">Hello world</div>




</body>

</html>

哪里错了?


提问者:慕粉4052528 2016-10-19 22:40

个回答

  • 前端喵
    2016-10-20 15:12:13

    我这里显示你创建了两个DIV标签,分别是myBox和myBox1;

    其中,第一个DIV是在head标签里,第二个是在body标签里,所以第一个无法显示的,第二个人可以显示。

    CSS部分是针对第一个div的,所以也显示不出效果。

    不懂为什么会把div写到head里啊?

    那里不可以写div的。



  • 码农吊车尾
    2016-10-20 14:54:03

    <style>
        .myBox{
            width:200px;
            height:100px;
            border:1px solid red;
            margin-top:10px;
            padding-left:15px;
        }
    </style>
    
    
    <body>
    <div class="myBox1">Hello world</div>
    </body>
    </html>
    
    class写错了,style标签里写的是.myBox  ; div class="myBox1"

  • qq_上海恋银_04241740
    2016-10-19 23:11:49

    就是你的style 定义class的时候, 文件是css。 所以你得写 <style type="text/css>

  • 慕粉4052528
    2016-10-19 23:08:22

    不懂?


  • qq_上海恋银_04241740
    2016-10-19 22:49:29

    style 部分代码是

    <style type="text/css">开始, 表示文件是css