如何获得全面的响应能力?

如何解决如何获得全面的响应能力?

我设计了一个HTML页面,该页面包含四个部分,并且还具有模式弹出功能。我已经做了很多尝试来实现响应能力,但是我不知道如何做到。我以某种方式实现了平板电脑视图,但是再次使窗口标签变大和变大时,它看起来也不正确,而且在模态弹出窗口中内容也不正确。请给我一些想法来实现这一目标。下面是我的代码

var modal1 = document.getElementById("myModal1");

// Get the button that opens the modal1
var btn1 = document.getElementById("btn1");

// Get the <span> element that closes the modal
var span1 = document.getElementsByClassName("close1")[0];

var modal2 = document.getElementById("myModal2");

// Get the button that opens the modal2
var btn2 = document.getElementById("btn2");

// Get the <span> element that closes the modal
var span2 = document.getElementsByClassName("close2")[0];

var modal3 = document.getElementById("myModal3");

// Get the button that opens the modal3
var btn3 = document.getElementById("btn3");

// Get the <span> element that closes the modal3
var span3 = document.getElementsByClassName("close3")[0];

var modal4 = document.getElementById("myModal4");

// Get the button that opens the modal4
var btn4 = document.getElementById("btn4");

// Get the <span> element that closes the modal4
var span4 = document.getElementsByClassName("close4")[0];



// When the user clicks the button,open the modal 
function handlefacebookmodal() {
  if(modal1.style.display != "block"){
    modal1.style.display = "block";
    modal2.style.display = "none";
    modal3.style.display = "none";
    modal4.style.display = "none";
  }else{
    modal1.style.display = "none";
  }
}


// When the user clicks on <span> (x),close the modal
span1.onclick = function() {
  modal1.style.display = "none";
}

// When the user clicks the button,open the modal 
function handleinstamodal() {
  if(modal2.style.display != "block"){
    modal2.style.display = "block";
    modal1.style.display = "none";
    modal3.style.display = "none";
    modal4.style.display = "none";
  }else{
    modal2.style.display = "none";
  }
}

// When the user clicks on <span> (x),close the modal
span2.onclick = function() {
  modal2.style.display = "none";
}

// When the user clicks the button,open the modal 3
function handlewhatsappmodal() {
  if(modal3.style.display != "block"){
    modal3.style.display = "block";
    modal2.style.display = "none";
    modal1.style.display = "none";
    modal4.style.display = "none";
  }else{
    modal3.style.display = "none";
  }
}

// When the user clicks on <span> (x),close the modal3
span3.onclick = function() {
  modal3.style.display = "none";
}

// When the user clicks the button,open the modal 4
function handletwittermodal() {
  if(modal4.style.display != "block"){
    modal4.style.display = "block";
    modal2.style.display = "none";
    modal3.style.display = "none";
    modal1.style.display = "none";
  }else{
    modal4.style.display = "none";
  }
}

// When the user clicks on <span> (x),close the modal4
span4.onclick = function() {
  modal4.style.display = "none";
}

window.addEventListener('click',function(e){
  if(btn1.contains(e.target)){
    handlefacebookmodal();
  }else if(btn2.contains(e.target)){
    handleinstamodal();
  }else if(btn3.contains(e.target)){
    handlewhatsappmodal();
  }else if(btn4.contains(e.target)){
    handletwittermodal();
  }else{
    modal1.style.display = "none";
    modal2.style.display = "none";
    modal3.style.display = "none";
    modal4.style.display = "none";
  }
});
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@500&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Ubuntu:wght@500&display=swap');

html,body{
  height: 100%;
  margin: 0;
  padding: 0;
}

button{
  width: 50%;
  height: 50%;
  float: left;
  margin: 0;
  padding: 0;
  cursor: pointer;
  text-align: center;
  position: relative;
}

button span {
  position: absolute;
  width: 100%;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  text-align: center;
  font-family: 'Ubuntu',sans-serif;
  font-size: 70px;
  color: transparent;
}

button img{
  width: 100%;
  height: 100%;
}

button:hover img{
  opacity: 0.4;
}

button:hover span{
  color: darkblue;
}

.modal {
  display: none;
  position: fixed;
  z-index: 1;
  left: 0;
  top: 0;
  width: 50%;
  height: 50%;
  border: 0;
}

.modal-content1 {
  position: relative;
  background-color: #fefefe;
  margin: 30% 50%;
  padding: 30px 5px 5px 5px;
  border: 1px solid #888;
  width: 100%;
  height: 68%;
  border-radius: 7px;
}

.modal-content2 {
  position: relative;
  background-color: #fefefe;
  margin: 30% 50%;
  padding: 30px 5px 5px 5px;
  border: 1px solid #888;
  width: 100%;
  height: 68%;
  border-radius: 7px;
}

.modal-content3 {
  position: relative;
  background-color: #fefefe;
  margin: 30% 50%;
  padding: 30px 5px 5px 5px;
  border: 1px solid #888;
  width: 100%;
  height: 75%;
  border-radius: 7px;
}

.modal-content4 {
  position: relative;
  background-color: #fefefe;
  margin: 30% 50%;
  padding: 30px 5px 5px 5px;
  border: 1px solid #888;
  width: 100%;
  height: 64%;
  border-radius: 7px;
}

#close {
  position: absolute;
  float: right;
  width: 1.5rem;
  line-height: 1.5rem;
  text-align: center;
  cursor: pointer;
  border-radius: 0.25rem;
  top: 1px;
  right: 1px;
  background-color: lightgray;
}

#close:hover,#close:focus {
  background-color: darkgray;
}

p,img{
  display: flex;
}

img{
  float: left;
  width: 45%;
  padding: 0;
  margin: 0;
}

p{
  float: right;
  text-align: justify;
  width: 50%;
  padding: 0;
  margin: 0;
  font-size: 20px;
}


@media (min-width: 320px) and (max-width: 767px){

}
@media (min-width: 768px) and (max-width: 1023px){
  button span{
    font-size: 30px;
    color: darkblue;
  }

  button img{
    opacity: 0.4;
  }

  .modal{
    transform: translate(-50%,-50%);
    width: 75%;
    height: 75%;
    top: 0;
    border: 0;
  }

  #modal-content{
    margin-left: 65%;

  }

  .modal-content1 {
    margin-top: 36%; 
  }

  .modal-content2 {
    margin-top: 36%; 
  }

  .modal-content3 {
    margin-top: 37%; 
  }

  .modal-content4 {
    margin-top: 37.3%; 
  }

  p{
    font-size: 15px;
    overflow-x: scroll;
  }  

}
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Nature</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <button id="btn1"><img src="https://images.unsplash.com/photo-1514361107497-ca601745d27a?ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80" alt=""><span>Himalaya</span></button>

    <div id="myModal1" class="modal">
      <div id="modal-content" class="modal-content1">
        <span id="close" class="close1">x</span>
        <img src="https://images.unsplash.com/photo-1577516311194-eb14c570a137?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80" id="image">
        <p id="content">
          The Himalayas are a mountain range in South Asia The Himalayas are a mountain range in South Asia.The west end is in Pakistan. They run through Jammu and Kashmir,Himachal Pradesh,Uttaranchal,Sikkim and Arunachal Pradesh states in India,Nepal,and Bhutan. The east end is in the south of Tibet. They are divided into 3 parts Himadri,Himachal and Shiwaliks.The 15 highest mountains in the world are in the Himalayas. 
        </p>
      </div>
    </div>

    <button id="btn2"><img src="https://images.unsplash.com/photo-1508831084156-40f6573bbe6b?ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80" alt=""><span>Waterfall</span></button>

    <div id="myModal2" class="modal">
      <div id="modal-content" class="modal-content2">
        <span id="close" class="close2">x</span>
        <img src="https://images.unsplash.com/photo-1493713838217-28e23b41b798?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80" id="image">
        <p id="content">
          Waterfalls are commonly formed in the upper course of a river where lakes fall into in steep mountains. Because of their landscape position,many waterfalls occur over bedrock fed by little contributing area,so they may be ephemeral and flow only during rainstorms or significant snowmelt. The further downstream,the more perennial a waterfall can be. Waterfalls can have a wide range of widths and depths.
        </p>
      </div>
    </div>

    <button id="btn3"><img src="https://images.unsplash.com/photo-1585889574476-af7bcb00d9c3?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80" alt=""><span>Raigad</span></button>

    <div id="myModal3" class="modal">
      <div id="modal-content" class="modal-content3">
        <span id="close" class="close3">x</span>
        <img src="https://mapio.net/images-p/122383921.jpg" id="image">
        <p id="content">
          Raigad is a hill fort situated in Mahad,Raigad district of Maharashtra,India. The Raigad Fort,formerly known as Rairi,was built by Chandraraoji More,the King of Jawali,who was then seized by Shivaji Maharaj who made it his capital in 1674 when he was crowned the King of the Maratha Kingdom which later developed into the Maratha Empire,eventually covering much of western and central India. The fort rises 820 metres above the sea level and is located in the Sahyadri mountain range.
        </p>
      </div>
    </div>

    <button id="btn4"><img src="https://images.unsplash.com/photo-1543763479-fb7533fcbf3b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80" alt=""><span>Lake</span></button>

    <div id="myModal4" class="modal">
      <div id="modal-content" class="modal-content4">
        <span id="close" class="close4">x</span>
        <img src="https://images.unsplash.com/photo-1531512073830-ba890ca4eba2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1144&q=80" id="image">
        <p id="content">
          A lake is an area filled with water,localized in a basin,surrounded by land,apart from any river or other outlet that serves to feed or drain the lake. Lakes lie on land and are not part of the ocean. Therefore,they are distinct from lagoons,and are also larger and deeper than ponds,though there are no official or scientific definitions. Lakes can be contrasted with rivers or streams,which are usually flowing. Natural lakes are generally found in mountainous areas.
        </p>
      </div>
    </div>

    <script src="script.js"></script>
  </body>
</html>

解决方法

不要使用最大宽度,它的总宽度是不必要的。按照我用于响应的模式(始终优先移动):

.custom-class{
  height: x
}
@media(min-width:576px){
  height: y
}
@media(min-width:768px){
  height: z
}
@media(min-width:1024px){
  height: u
}
@media(min-width:1280px){
  height: v
}

在您要实现响应性的每个元素上使用此模式。

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

相关推荐


使用本地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-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res