请大家帮我看看有什么需要改动的

请大家帮我看看有什么需要改动的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title></title>
  <style type="text/css">
    /*此处写代码*/
    *{margin:0;
        padding:0;
    }
    .bg{background:black;
        width:1100px;
        height:100px;
        position:absolute;
        top:50%;
        left:50%;
        margin-left:-550px;
        margin-top:-50px;
    }
    .logo{
        background:url(http://img1.sycdn.imooc.com/climg//58c0d2d900016ce303000100.png);
        width:300px;
        height:80px;
        float:left;
    }
    .dht{
      width:100px;
      height: auto;
      color: white;
      float: right;
      font-size: 20px;
      line-height: 100px;
      margin-left:30px;
      text-align: center; 
      cursor: pointer;         
    }
    .dht:nth-child(4){margin-left: 40px;}
 
  </style>  
</head>
<body>
  <!-- 此处写代码 -->
  <div class="bg">
      <div class="logo"></div>
      <div class="dht">手记</div>
      <div class="dht">猿问</div>
      <div class="dht">实战</div>
      <div class="dht">职业路径</div>
      <div class="dht">课程</div>
  </div>
   
</body>
</html>


正在回答

登陆购买课程后可参与讨论,去登陆

3回答

:nth-child(n) 选择器匹配属于其父元素的第 N 个子元素,不论元素的类型。

你的代码中,匹配的是其父元素<div class="bg">的第4个子元素。

该选择器是CSS3中的选择器,当前学习阶段,使用我们的类或者id选择器去写就可以实现了,进阶的专题中会有详细讲解CSS3的选择器,先学好当前的内容吧。

祝学习愉快!

  • AiChiRol 提问者 #1
    谢谢,因为看到视频里有用到就想自己试一试
    2018-03-06 10:00:20
  • AiChiRol 提问者 #2
    还想问一下,除了我这样设置,还有什么方法能够让字体间距一样呢?谢谢
    2018-03-06 10:15:31
小丸子爱吃菜 2018-03-06 11:16:16

这个间距就是使用padding或者margin去实现的。

提问者 AiChiRol 2018-03-05 21:04:38

问一个问题:为什么我在设置.dht:nth-child(4){margin-left: 40px;}时候,我想设置的是“实战”的margin-left的值,我当时用的是.dht:nth-child(3){margin-left: 40px;},因为在class="dht"的元素中“实战”在我代码看起来是第三个,为什么要设置4而不是3呢

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码