给div设置宽度下面有滚动条,设置图片宽度没有,怎么让图片适应div

来源:7-2 编程练习

qq_精慕门4435346

2020-03-25 14:27:13

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

<title></title>

<style>

#img2{

    width:150px;

    height:200px;

    position:fixed;

    top:50%;

    margin-top:-100px;

}

    #img3{

width:150px;

    height:200px;

    position:fixed;

    top:50%;

    right:0px;

    margin-top:-100px;

}

    #img1{

        width:100%;

    }

</style>

</head>

<body>

    <div>

        <img src=http://climg.mukewang.com/59c9f7ce0001839219034033.png id=img1>

<div><img src=http://climg.mukewang.com/5a3383c70001f1b702240364.png id=img2></div>

<div><img src=http://climg.mukewang.com/5a3383d00001a3dd02240364.png id=img3></div>

</div>

</body>

</html>


写回答

1回答

guly

2020-03-25

你好,建议参考代码如下:

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title></title>

    <style>

        #img2{

            width:150px;

            height:200px;

            position:fixed;

            top:50%;

            margin-top:-100px;

        }

        #img3{

            width:150px;

            height:200px;

            position:fixed;

            top:50%;

            right:0px;

            margin-top:-100px;

        }

        #img1{

            width:100%;

        }

    </style>

</head>

<body>

<div>
    <div style='width:400px;height:auto;text-align:center;float:none;margin-left:auto;margin-right:auto;'>
        <img src="http://climg.mukewang.com/59c9f7ce0001839219034033.png" style="width:4000px;height:auto;">
    </div>

    <img src=http://climg.mukewang.com/59c9f7ce0001839219034033.png id=img1>

    <div width="1600px;"><img src=http://climg.mukewang.com/5a3383c70001f1b702240364.png id=img2></div>



</div>

</body>

</html>

如果解决您的问题请采纳,祝学习愉快!

0

0 学习 · 4928 问题

查看课程