图文混排失败

图文混排失败

相关代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图文混排</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .wrap{
            height: 760px;
            width: 100%;
            position: relative;
            background-color: aquamarine;
           
        }
        .box1,box2,box3,box4{
            height: 380px;
            width: 25%;
        }
        .wrap img{
            display: block;
            width: 25%;
            height: 380px;
        }
        .wrap .spec{
            display: block;
            width: 25%;
            height: 380px;
        }
        .wrap .spec h2{
            font-size: 24px;
            color:white;
            padding: 20px;
        }
        .wrap .spec .p1{
            color: white;
            font-size: 16px;
            padding: 20px;
            padding-top: 10px;
        }
        .wrap .spec .p2{
            color: grey;
            padding: 0 20px;
            font-size: 11px;
        }
        .wrap .spec input{
            display: block;
            background-color: black;
            color: white;
            margin: 5px auto;
            text-align: center;
            height: 40px;
            width: 138px;
        }
        .wrap .box1{
            float: left;
        }
        .wrap .box2{
            float: left;
        }
        .wrap .box3{
            float: left;
        }
        .wrap .box4{
            float: left;
        }
    </style>

</head>

<body>
    <div class="wrap">
        <div class="box1">
            <img src="images/b1.jpg" alt="">
            <div class="spec">
                <h2>Library</h2>
                <p class="p1">Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
                <p class="p2">Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
                    took a galley of type and scrambled it to make a type specimen book.</p>
                <input type="button" value="EXPLORE">
            </div>
        </div>
        <div class="box2">
            <div class="spec">
                <h2>Library</h2>
                <p class="p1">Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
                <p class="p2">Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
                    took a galley of type and scrambled it to make a type specimen book.</p>
                <input type="button" value="EXPLORE">
            </div>
            <img src="images/b2.jpg" alt="">
        </div>
        <div class="box3">
            <img src="images/b3.jpg" alt="">
            <div class="spec">
                <h2>Library</h2>
                <p class="p1">Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
                <p class="p2">Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
                    took a galley of type and scrambled it to make a type specimen book.</p>
                <input type="button" value="EXPLORE">
            </div>
        </div>
        <div class="box4">
            <div class="spec">
                <h2>Library</h2>
                <p class="p1">Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
                <p class="p2">Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
                    took a galley of type and scrambled it to make a type specimen book.</p>
                <input type="button" value="EXPLORE">
                <img src="images/b4.jpg" alt="">
            </div>
        </div>
    </div>
</body>

</html>


老师我这个怎么浮动啊,四个盒子我都设置了.box1,box2,box3,box4的宽高,我思路是背景里放从左往右四个盒子,每个盒子了有两个盒子,这两个盒子不需浮动,只要浮动外面四个盒子就行了。

还有最下面的按钮按照题目要求的边框值会掉出来,所以我设置了上下5像素,是不是出题有误啊


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

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

1回答
好帮手慕慕子 2022-03-24 16:37:12

同学你好,对于你的问题解答如下:

1、组合选择中box2、box3和box4类选择器前缺少点,导致设置的宽度和高度样式没有生效。建议修改:

https://img1.sycdn.imooc.com//climg/623c2bb9091f002e04690404.jpg

另外,图片和文字所在的盒子需要设置宽度为百分百,填充满父盒子,建议修改:

https://img1.sycdn.imooc.com//climg/623c2c2c09035cd804890401.jpg

2、题目无误,是同学代码书写的有问题,经过第一条的建议修改后,参考标注图给出的值设置按钮的上下间距,按钮是正常显示的,如下:

https://img1.sycdn.imooc.com//climg/623c2d0a092e9c2913420743.jpg

3、由于box4盒子中,将图片放在了spec盒子中,导致图片显示位置不对,如下图所示:

https://img1.sycdn.imooc.com//climg/623c2d6909a22bd206930690.jpg

建议修改:将img标签放在spec盒子外

https://img1.sycdn.imooc.com//climg/623c2db609ac70bd13250344.jpg

祝学习愉快~

  • 提问者 长袖泡面头 #1

    老师就是老师,果然厉害👍,,原来四个盒子是八个小盒子的父元素,忽略了这点, 还有点马虎


    我换种思路做老师觉得可行吗,就是分成上下两个大盒子,每个大盒子里放四个小盒子,给四个图片设置一样的类名,四个问题块也一样的类名,这样大盒子不用浮动,之浮动面的小盒子,这个方式在实际中会常用吗

    2022-03-24 17:05:32
  • 好帮手慕慕子 回复 提问者 长袖泡面头 #2

    这用思路也是可以的呀,实际开发中,一般不会规定必须使用哪种方式,根据要实现的具体效果图,灵活应用所学知识去实现效果就可以了。祝学习愉快~

    2022-03-24 17:13:37
问题已解决,确定采纳
还有疑问,暂不采纳

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

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

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

在线咨询

领取优惠

免费试听

领取大纲

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