下面有问题

下面有问题

在写第三个我用决定定位的时候三个dl会到第一个dl位置重合,我给dl高度就好了,但是为啥第二个dl我在没有设置高度时候用绝对定位它不会重合到一个位置



<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <link rel="stylesheet" href="main.css">

  <title>Document</title>

</head>

<body>

  <section class="main">

    <aside>

      <h1>Recent</h1><samp>Course</samp>

      <dl>

        <dt>Hyper Text Marlup Languange</dt>

        <dd><img src="http://img1.sycdn.imooc.com/climg//582e61290001787900500051.png"></dd>

        <dd>1</dd>

        <dd>HTML is the standard markup Languange used to create web pages and its elements form the building blocks of all websites</dd>

      </dl>

      <dl>

        <dt>Cascading Style Sheets</dt>

        <dd><img src="http://img1.sycdn.imooc.com/climg//582e61290001787900500051.png"></dd>

        <dd>2</dd>

        <dd>Csscading Style Sheets(CSS) is a simple mechanism for adding style (e.g,fonts,colors,spacing) to Web</dd>

      </dl>

      <dl>

        <dt>JavaScript</dt>

        <dd><img src="http://img1.sycdn.imooc.com/climg//582e61290001787900500051.png"></dd>

        <dd>3</dd>

        <dd>JavaScript is a high-level,dynamic,untyped,and interpreted programming language.</dd>

      </dl>

      <dl>

        <dt>Angular JS</dt>

        <dd><img src="http://img1.sycdn.imooc.com/climg//582e61290001787900500051.png"></dd>

        <dd>4</dd>

        <dd>AngularJS is an open-source web application framework mainly maintained by Google and buy a community of individuals and ...</dd>

      </dl>

    </aside>

    <article>

      <h1>Welcome to</h1><samp>Massive Open Online Course!</samp>

      <p>we provide the knowledge to help you cope with the changing woeld!</p>

      <img src="http://img1.sycdn.imooc.com/climg//582e61180001ede703300130.jpg">

      <p>We hope that all the students who love the internet can be more cinveninent access to learning resource,using the interent thinking to change our learning.</p>

      <p>Focus on IT skill educantion MOOC,cansistent with the development trend of the interent down earth's MOOC.We are free. we only teach useful.we concentate on education.</p>

    </article>

  </section>

</body>

</html>












.main h1{

    font-size: 30px; 

    display: inline;

    margin-right: 10px;

}

.main samp{

    color:#666;

    font-size: 30px;  

}

.main{

    width: 1200px;

    margin: 0 auto;

    overflow: hidden;

}

.main > aside{

    width: 550px;

    float: left;

   

}

.main > article{

    float:right;

    width: 630px;

}

.main >aside>dl{

    width: 480px;

    position: relative;

    height: 80px;

    margin-bottom: 30px;

}

.main>aside>dl>dt{

    position: absolute;

    font-weight: bold;

    left: 100px;

    font-size: 1.1em;

    z-index: 2;

    text-decoration: underline;

}

.main>aside>dl>dd:first-of-type{

    position: absolute;

    left: -20px;

    top: 5px;

    z-index: 1;

}

.main>aside>dl>dd:nth-of-type(2){

    font-size: 30px;

    color: #fff;

    position: absolute;

    z-index: 2;

    left: -4px;

    top:10px;

}

.main>aside>dl>dd:last-of-type{

    position: absolute;

    left: 60px;

    top: 30px;

}

.main >article>img{

    width: 630px;

    height: 200px;

}

.main >article>img,p{

    margin-bottom: 20px;

}




正在回答 回答被采纳积分+1

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

3回答
好帮手慕言 2020-05-30 19:12:49

同学你好,删除dl的高度,重合在一起的原因是dl元素里面的子元素(dd和dt)都设置了定位,脱离文档流,dl的高度塌陷,高度为0,元素就重合在一起了。

把最后一个dd的css代码删掉,最后一个dd没有定位,就不会脱离文档流,可以撑开父级的高度,也就出现了同学第二张截图的情况。

祝学习愉快 ~

  • 提问者 福徐贵 #1
    最后一个dd我设置了绝对定位呀,截图不是有么
    2020-05-30 19:17:25
  • 提问者 福徐贵 #2
    懂了 不用说了
    2020-05-30 19:37:22
提问者 福徐贵 2020-05-30 18:57:02

http://img1.sycdn.imooc.com//climg/5ed23baa09aea85713640347.jpg我把dl高度删掉的情况



http://img1.sycdn.imooc.com//climg/5ed23bcf099f315f13290539.jpg高度没加,我把最后一个dd注释掉,他就不会重合

好帮手慕言 2020-05-30 18:47:53

同学你好,使用同学提供的代码测试,第三个dl设置绝对定位,第三个dl并没有与第一个dl重合,如下:

http://img1.sycdn.imooc.com//climg/5ed238f40901c20f16570816.jpg

第三个dl设置绝对定位之后,第四个和第三个dl会叠压在一起,原因是使用绝对定位之后,原来的位置不会被保留,第四个dl就会往上移动。

建议:同学可以把有问题的(发生重叠的代码粘贴上来)。祝学习愉快~

  • 提问者 福徐贵 #1
    我上面给出了问题截图
    2020-05-30 18:57:40
  • 提问者 福徐贵 #2
    重新截图了
    2020-05-30 19:06:28
问题已解决,确定采纳
还有疑问,暂不采纳

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

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

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

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