HTML + CSS-调整图片大小仅适用于移动设备

如何解决HTML + CSS-调整图片大小仅适用于移动设备

我将直接向您展示而不是说明。

这是我的网站在浏览器上的外观:

enter image description here

这是在移动设备上查看我的网站时的样子:

enter image description here

有人给我任何有关如何解决它的建议吗?我尝试了引导程序和媒体查询,但一直在努力寻找一些方法来将图像调整为足够小的尺寸,以便它们在移动设备上彼此相邻显示。

头:

img.mob-img {
  width: 220;
  height: 333;
}   
  @media screen and (max-width: 992) {
    img.mob-img {
      width: 100px;
      height: auto;
    }       
  }
  @media screen and (max-width: 600) {
    img.mob-img {
      width: 100px;
      height: auto;
    }       
  }
<head>
  <title>DrinkMania - Drink or Dare</title>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
  <meta name="robots" content="index,follow">
  <meta name="description" content="Drink or Dare! - Truth or dare developed with students in mind!">
  <meta name="keywords" content="kings,ring of fire,drinking games,drinkmania,drinking games online,student,frat,dirty pint,kings cup,app,mobile website,android,ios,reddit,scott montford,playing cards,university,party,friends,talisman webs">
  <link rel="stylesheet" href="assets/css/main.css" />
  <link rel="icon" href="favicon.ico" type="image/x-icon"/>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  <!-- Global site tag (gtag.js) - Google Analytics -->
  <script async src="https://www.googletagmanager.com/gtag/js?id=UA-145322216-2"></script>
  <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js',new Date());

      gtag('config','');
  </script>
</head>
<body class="is-preload">

Section of the body:

  <!-- Banner -->
  <section id="banner" data-video="images/banner">
    <div class="inner">
      <header>
        <h1>Drink or Dare</h1><br>
        <p id="kingCount"></p><br>
        <img id="drinks" class="mob-img" src="assets/js/games/Cards/card-placeholder.png" > OR
        <img id="wildcard" class="mob-img" src="assets/js/games/Cards/card-placeholder.png" >
      </header>
      <ul class="actions special">
        <li><a href="#" class="button primary large" onclick="drawCard()">Draw 2 Cards</a></li><br>
      </ul>
    </div>
    <a href="#one" class="more">Learn More</a>
    <video src="images/banner.mp4" muted autoplay loop playsinline></video>
  </section>
</body>

解决方法

我将图像设置到容器<div style="display:flex; justify-content:center;">中,并将max-width添加到图像css

img.mob-img {
  width: 220px;
  height: 333px;
}   
@media screen and (max-width: 992) {
  img.mob-img {
    max-width: 100px;
    height: auto;
  }       
}
@media screen and (max-width: 600) {
  img.mob-img {
    max-width: 100px;
    height: auto;
  }       
}
<head>
  <title>DrinkMania - Drink or Dare</title>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
  <meta name="robots" content="index,follow">
  <meta name="description" content="Drink or Dare! - Truth or dare developed with students in mind!">
  <meta name="keywords" content="kings,ring of fire,drinking games,drinkmania,drinking games online,student,frat,dirty pint,kings cup,app,mobile website,android,ios,reddit,scott montford,playing cards,university,party,friends,talisman webs">
  <link rel="stylesheet" href="assets/css/main.css" />
  <link rel="icon" href="favicon.ico" type="image/x-icon"/>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  <!-- Global site tag (gtag.js) - Google Analytics -->
  <script async src="https://www.googletagmanager.com/gtag/js?id=UA-145322216-2"></script>
  <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js',new Date());

      gtag('config','');
  </script>
</head>

<body class="is-preload">

Section of the body:

  <!-- Banner -->
  <section id="banner" data-video="images/banner">
    <div class="inner">
      <header>
        <h1>Drink or Dare</h1><br>
        <p id="kingCount"></p><br>
        <div style="display:flex; justify-content:center;">
          <img id="drinks" class="mob-img" src="https://cdn.pixabay.com/photo/2020/01/31/07/10/billboards-4807268_960_720.jpg" > OR
          <img id="wildcard" class="mob-img" src="https://cdn.pixabay.com/photo/2018/03/06/20/25/dog-3204497_960_720.jpg" >
        </div>
      </header>
      <ul class="actions special">
        <li><a href="#" class="button primary large" onclick="drawCard()">Draw 2 Cards</a></li><br>
      </ul>
    </div>
    <a href="#one" class="more">Learn More</a>
    <video src="images/banner.mp4" muted autoplay loop playsinline></video>
  </section>
</body>

,

好的,当您输入的最大宽度相同时,您无需设置两个不同的最大宽度。如果您需要此尺寸,我会将宽度设置为100%,最大宽度为100px。我不是像您一样喜欢嵌入式CSS的人。我将重命名已应用flex的div,然后将代码与其他样式一起放入,这样就不会遍地开花了。如果可以的话,将它集中到一处是很有帮助的。

   <div id="cards">
          <img id="drinks" class="mob-img" src="https://cdn.pixabay.com/photo/2020/01/31/07/10/billboards-4807268_960_720.jpg" > OR
          <img id="wildcard" class="mob-img" src="https://cdn.pixabay.com/photo/2018/03/06/20/25/dog-3204497_960_720.jpg" >
        </div>

CSS

#cards {
display:flex;
justify-content:center;
}

img.mob-img {
  width: 220px;
  height: 333px;
}   
@media screen and (max-width: 992px) {
  img.mob-img {
    width: 100%;
    max-width: 100px;
    height: auto;
  }       
    
}
,

这是您要尝试做的吗?我确保它也能响应。因为您说您正在使用引导程序,所以我不需要使用您提供的任何CSS。

我还通过添加更多div获得了结果,对HTML进行了一些更改。

如果这不是您想要的输出,请在评论中让我知道,我会尽力帮助您。

Ps。我评论了该视频,因为它导致水平滚动。

.image-container {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}

.image-holder {
  padding: 10px;
}
<!-- CSS only -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">


<section id="banner" data-video="images/banner">
  <div class="inner">
    <header>
      <h1>Drink or Dare</h1><br>
      <p id="kingCount"></p><br>
      <div class="holder">
        <div class="image-container">
          <div class="image-holder">
            <img id="drinks" class="mob-img img-fluid" src="https://picsum.photos/200">
          </div>
          <span>OR</span>
          <div class="image-holder">
            <img id="drinks" class="mob-img img-fluid" src="https://picsum.photos/201">
          </div>
        </div>
      </div>
    </header>
    <ul class="actions special">
      <li><a href="#" class="button primary large" onclick="drawCard()">Draw 2 Cards</a></li><br>
    </ul>
  </div>
  <a href="#one" class="more">Learn More</a>
  <!-- <video src="images/banner.mp4" muted autoplay loop playsinline></video> -->
</section>


<!-- JS,Popper.js,and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous">
</script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous">
</script>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-