html - 尝试使用@media 查询来调整手机、平板电脑桌面的图像大小
问题描述
我很难让我的网站上的背景图像响应。我已将媒体查询添加到我的页面,但它们不起作用,我不确定还能做什么。下面,我列出了三个图像的 html 和 css。有什么建议请指教,谢谢!
body {
background: url(/img/sect-bkgrd.jpg) center/cover fixed no-repeat;
font-family: 'Roboto', sans-serif;
color: #000;
}
#header {
min-height: calc(100vh - 94px);
background: linear-gradient(to right, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), url(/img/sushi-main.jpg);
background-position: center center;
background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
background-color: #000;
}
#menu {
background: linear-gradient(rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.2)), url(/img/menu-bkgrd.jpg) center/cover fixed no-repeat;
}
<header id="header">
<div class="container">
<div class="row height-90 align-items-center justify-content-center">
<div class="col">
<div class="banner text-center">
<h1 class="display-1 text-capitalize underline w-50 mx-auto">
<strong class="primary-color">Title</strong>
<img src="/img/sushi-logo2.png" class="img-fluid" alt="" />
</h1>
</div>
</div>
</div>
</div>
<section id="menu" class="py-5 my-5">
<div class="container">
<div class="row">
<div class="col-md-6">
<!-- title-->
<div class="row">
<div class="col">
<h1 class="primary-color text-uppercase">sushi</h1>
</div>
</div>
<!-- title-->
<!-- single item-->
<div class="single-item d-flex justify-content-between my-3 p-3">
<div class="single-item-text">
<h2 class="text-uppercase text-black">sushi</h2>
<h4 class="text-white">Lorem ipsum dolor sit amet.</h4>
</div>
<div class="single-item-price align-self-end">
<h1 class="text-uppercase text-black">$10</h1>
</div>
</div>
</div>
</div>
</div>
</section>
</header>
解决方案
您可以使用 max-width 或 min-width 属性为多个设备调整背景图像的大小。例如,对于小型设备,媒体查询将是
@media screen & (max-width:768px){
#img{
max-width: 100%;
}
}
推荐阅读
- html - 如何使用来自 UWP 应用的 XAML 在 TextBlock 中显示 HTML 内容?
- java - Jackson-JQ:从 java 运行 jq 命令
- c# - 如何将对象解析为 json 反序列化之类的类?
- mysql - SQL 更新所有 varchar 列行
- c# - 无法在 C# 中验证对模拟的调用
- laravel - 问题理解 Laravel 6.0 Passport with Password Grant Tokens 流程
- javascript - 隐藏/重新展开后父/子表刷新
- c# - 对 Azure 应用服务上的程序集加载问题/文件未找到异常进行故障排除的建议
- python-3.x - OSError:[Errno 30] 只读文件系统:英特尔开发云上的“/glob/intel-python/versions/2018u2/intelpython3/lib/python3.6/site-packages/docs”
- git - 解决 Git 中的合并冲突时的新文件