老师请教一下,遇到一个小问题

老师请教一下,遇到一个小问题

.con-but {
    width: 1600px;
    margin: 0 auto;
}
.con-but .b-top,
.con-but .b-but{
    margin: 0;
    padding: 0;
}
.b-top .t-img,
.b-top .t-word,
.b-but .b-img,
.b-but .b-word{
    float: left;
    position: relative;
}
.b-top .t-img img,
.b-but .b-img img{
    width: 400px;
    height: 300px;
}
.b-top .t-word,
.b-but .b-word{
    width: 340px;
    height: 260px;
    padding: 20px 30px;
    background: #85e5e4;
}
.word-horn-right{
    width: 0;
    height: 0;
    border-top: 15px solid transparent;
    border-right: 25px solid transparent;
    border-bottom: 15px solid transparent;
    border-left: 25px solid #85e5e4;
    position: absolute;
    top: 50%;
}
.word-horn-left{
    width: 0;
    height: 0;
    border-top: 15px solid transparent;
    border-right: 25px solid #85e5e4;
    border-bottom: 15px solid transparent;
    border-left: 25px solid transparent;
    position: absolute;
    right: 0;
    top: 50%;
}
.b-top .t-word h3,
.b-but .b-word h3{
    color: white;
    font-family: "微软雅黑";
    margin-bottom: 20px;
}
.t-word p:nth-child(even),
.b-word p:nth-child(even){
    color: white;
    font-size: 18px;
    line-height: 25px;
    margin-bottom: 20px;
}
.t-word p:nth-child(odd),
.b-word p:nth-child(odd){
    color: #f9f9f9;
    font-size: 14px;
    line-height: 25px;
    margin-bottom: 40px;
}
.t-word button,
.b-word button{
    padding: 10px;
    background: black;
    color: white;
    border: 2px solid #85e5e4;
    text-align: center;
}
.t-word-but{
    text-align: center;
}
.t-word button:hover,
.b-word button:hover{
    background: transparent;
    color: black;
    border: 2px solid black;
}
            <div class="con-but">
                <div class="b-top">
                   <div class="t-img">
                        <div class="word-horn-left"></div>
                       <img src="img/b1.jpg">
                   </div>
                   <div class="t-word">
                       <h3>Library-1</h3>
                        <p>There are many variations of passages of Lorem Ipsum available.</p>
                        <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour.</p>
                        <div class="t-word-but">
                            <button>EXPLORE</button>
                        </div>
                   </div>
                   <div class="t-img">
                        <div class="word-horn-left"></div>
                       <img src="img/b2.jpg">
                   </div>
                   <div class="t-word">
                       <h3>Library-2</h3>
                        <p>There are many variations of passages of Lorem Ipsum available.</p>
                        <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour.</p>
                        <div class="t-word-but">
                            <button>EXPLORE</button>
                        </div>
                   </div>
                   <div class="clear"></div>
                </div>
                <div class="b-but">
                    <div class="b-word">
                        <h3>Library-3</h3>
                        <p>There are many variations of passages of Lorem Ipsum available.</p>
                        <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour.</p>
                        <div class="t-word-but">
                            <button>EXPLORE</button>
                        </div>
                    </div>
                    <div class="b-img">
                        <div class="word-horn-right"></div>
                        <img src="img/b3.jpg">
                    </div>
                    <div class="b-word">
                        <h3>Library-4</h3>
                        <p>There are many variations of passages of Lorem Ipsum available.</p>
                        <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour.</p>
                        <div class="t-word-but">
                            <button>EXPLORE</button>
                        </div>
                    </div>
                    <div class="b-img">
                        <div class="word-horn-right"></div>
                        <img src="img/b4.jpg">
                    </div>
                   <div class="clear"></div>
                </div>
            </div>

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

这里多出4px边距,但是我尝试给上下盒子限制高度,就出现变形,是为什么呢?

正在回答

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

3回答

你好同学 ,根据上传的代码进行测试 ,按钮溢出 ,影响下面的盒子浮动不过去 :

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

如下修改:

整体的盒子要设置相对浏览器宽度100%显示

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

里面有8个内容块 ,每个内容块平分25%宽度 :

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

另外选择题如下设置:

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

.t-word p:nth-child(3) 表示选择.t-word中第三个子元素 ,并且这个字元素是p . 如下:

两个p的位置分别是第2, 第3 .

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

.t-word  p:nth-child(1)表示的就是.t-word 下面的第一个位置上面的子元素p ,而结果中第一个子元素是h3 ,所以并不会选择上的 .这里要正确里面使用数字的用法 .

希望解答了你的疑惑 ,祝学习愉快 ,望采纳 .

  • 王小大 提问者 #1
    好的!谢谢老师指点
    2018-11-21 20:52:54
提问者 王小大 2018-11-21 17:48:43

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

老师还有个问题,这里我是用选择器 括号内写1/2无法选择对应的为什么呢,但是使用奇偶数就行

提问者 王小大 2018-11-21 17:26:21

css里面多出一些无用的代码,是我之前测试 没用的 但是忘删了

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

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

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

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

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

帮助反馈 APP下载

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

公众号

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

在线咨询

领取优惠

免费试听

领取大纲

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