[英]How to make image responsive in navbar html + css
I am using this code我正在使用此代码
<div> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container"> <div class="d-flex flex-row justify-content-center align-items-center"> <a class="navbar-brand" href="#"> <img class="img-logo" src="https://www.instagram.com/static/images/web/mobile_nav_type_logo.png/735145cfe0a4.png" alt="" loading="lazy" style="width:12%;height:auto; float: left;"> <h1 style="color: #89216b; float: right; margin-top: auto; margin-bottom: auto; font-size: all;">Trendings</h1> </a> </div> </div> </nav> </div>
All is perfect but when i see it on mobile image size is small and text size remains same I just want that Image size will not be small一切都很完美,但是当我在移动设备上看到它时,图像尺寸很小,文字尺寸保持不变,我只是希望图像尺寸不会很小
When you use width:12% in img it made image smaller automatically.当您在img中使用width:12%时,它会自动使图像变小。 So I suggested you to remove that code and use this one instead;因此,我建议您删除该代码并改用该代码;
.navbar-brand{
width:100%;
height:auto;
}
.img-logo{
max-width:100%;
height:auto;
object-fit:cover;
}
Also in your html;(I removed width and height in style)同样在您的 html 中;(我删除了样式中的宽度和高度)
<img class="img-logo" src="https://www.instagram.com/static/images/web/mobile_nav_type_logo.png/735145cfe0a4.png" alt="" loading="lazy" style="float: left;">
Base on what you have,.. you are using some css framework since you have:根据你所拥有的,.. 你正在使用一些 css 框架,因为你有:
d-flex flex-row etc
If so why use inline styling?如果是这样,为什么要使用内联样式? ...Anyhow if you are going to style anything then edit the image: ...无论如何,如果您要设置任何样式,然后编辑图像:
.img-logo {
width: 100%;
height: auto;
max-width: 100px;
}
or inline...或内联...
<img class="img-logo" src="img" alt="" loading="lazy" style="
width: 100%;
height: auto;
max-width: 100px;
">
100px is just my example you can do correct size by your will. 100px 只是我的例子,你可以根据自己的意愿做正确的尺寸。 That would be your image style so it can look fine at any size.那将是您的图像样式,因此它可以在任何尺寸下看起来都很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.