html - 锁定页面内容纵横比
问题描述
如何锁定我的页面的纵横比,例如示例?响应 16:9(例如响应 1920x1080 和 2560x1440),但当用户的显示为 21:9 或 32:9 时显示 16:9。我尝试了媒体查询和纵横比,但它不像我想要的那样工作。
解决方案
使用此代码:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body {
background-color: black;
text-align: center;
color: white;
font-family: Arial, Helvetica, sans-serif;
}
.lock{
max-height:400px;width:90%;margin:auto;border:1px solid #ddd;overflow:hidden;
}
</style>
</head>
<body>
<div id="wrapper" class="">
<Button id="btnLock" onclick="GetLock()">Get Lock</Button>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>Edit the code in the window to the left, and click "Run" to view the result.</p>
<img src="avatar.png" alt="Avatar" style="width:200px">
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>Edit the code in the window to the left, and click "Run" to view the result.</p>
<img src="avatar.png" alt="Avatar" style="width:200px">
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>Edit the code in the window to the left, and click "Run" to view the result.</p>
<img src="avatar.png" alt="Avatar" style="width:200px">
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>Edit the code in the window to the left, and click "Run" to view the result.</p>
<img src="avatar.png" alt="Avatar" style="width:200px">
</div>
<script>
var lock=false;
function GetLock()
{
if(lock)
{
var element = document.getElementById("wrapper");
element.classList.remove("lock");
lock=false;
}
else
{
var element = document.getElementById("wrapper");
element.classList.add("lock");
lock=true;
}
}
</script>
</body>
</html>
推荐阅读
- java - 如何从java中的输出中删除'['']'
- angular - 在用户打开弹出窗口后加载组件,但在关闭弹出窗口后不销毁它
- objective-c - 自定义 CTLine 结构
- ruby-on-rails - 如何在显示页面中实现轮播或几张照片(Ruby on Rails)
- string - 使拆分字符串获取最后一个元素
- c++ - 一次读取 ULONG 的文件
- google-maps - 如何使用 VueJs 在谷歌地图中添加我的位置按钮?
- ios - 触发 iOS swift 的后台邮件
- spring-boot - Spring Boot 降级 postgres 版本
- java - 对象 [id=1] 不属于指定的子类