html - 图像不会使用 CSS 和 HTML 代码调整大小或调整
问题描述
所以我一直在尝试很多代码来完成这项工作,但我的 Squarespace 网站似乎没有任何效果。
我不是网页设计师也不是开发人员,但我也在努力学习,这种“简单”的代码看起来很简单,但很难。即使我更换图像,它仍然保持相同的大小。
请在此处查看代码:
CSS:
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.container {
position: relative;
width: 100%;
max-width: 400px;
}
.container img {
width: 100%;
height: auto;
}
</style>
html:
<div class="container">
<img src="https://cdn.pixabay.com/photo/2019/09/26/14/04/etretat-4506072_1280.jpg" alt="landing page" width="1500" height="528">
<button class="btn">Learn More</button>
</div>
</body>
</html>
很高兴听到你的想法。非常感谢,我现在很沮丧。
解决方案
我可以帮助你。我用 HTML 修复了你的代码。对于图像大小调整,您应该使用“px”。
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<style>
.container {
position: relative;
width: 100%;
max-width: 200px;
}
.container img {
width:100px;
height:100px;
}
</style>
<h1>Html:</h1>
<div class="container">
<img src="https://cdn.pixabay.com/photo/2019/09/26/14/04/etretat-4506072_1280.jpg" alt="landing page" width="1500" height="528">
<button class="btn">Learn More</button>
</div>
</body>
</html>
推荐阅读
- python - 如何在每辆车上独立更改 x 和 y 轴的值?
- c# - 如何在标题栏中显示带有下标或上标的文本?
- jquery - 未在通过分页加载的元素上引发事件
- react-native - React Native Android - 为什么无法与父组件边界之外的绝对定位视图进行交互?
- elasticsearch - 如何在elasticsearch simple_query_string中包含除空格之外的所有字符?
- c++ - 为什么不能直接使用类模板来推导方法模板呢?SFINAE
- mysql - 我如何优化此查询以用于计算响应的 sql
- flutter - 测量两个位置之间的距离
- rust - Rust 借用了可能未初始化的变量 - 作为程序员,这对我来说很明显,它总是会被初始化
- excel - 如何在kartik export yii2中更改文件名