移动端H5页面强制横屏显示

HTML结构:

<div class="container">
    <div class="mb-3">
        <label for="exampleFormControlInput1" class="form-label">账号</label>
        <input type="email" class="form-control" id="exampleFormControlInput1" placeholder="请输入账号">
    </div>
    <div class="mb-3">
        <label for="exampleFormControlInput1" class="form-label">密码</label>
        <input type="email" class="form-control" id="exampleFormControlInput1" placeholder="请输入密码">
    </div>
    <div class="mb-3">
        <label for="exampleFormControlTextarea1" class="form-label">备注</label>
        <textarea class="form-control" id="exampleFormControlTextarea1" rows="3" placeholder="请输入备注"></textarea>
    </div>
</div>

CSS

.container {
    position: absolute;
    padding: 20px;
    box-sizing: border-box;
    overflow: hidden;
}

/* 竖屏 */
@media screen and (orientation: portrait) {
    .container {
        width: 100vh;
        height: 100vw;
        top: calc((100vh - 100vw) / 2);
        left: calc((100vw - 100vh) / 2);
        transform: rotate(90deg);
        /* transform-origin: 50% 50%; */
        /* transform-origin: center center; */
        /* transform-origin: center; */
    }
}

/* 横屏 */
@media screen and (orientation: landscape) {
    .container {
        width: 100vw;
        height: 100vh;
        top: 0;
        left: 0;
        transform: none;
        /* transform-origin: 50% 50%; */
        /* transform-origin: center center; */
        /* transform-origin: center; */
    }
}

transform-origin:更改一个元素变形的原点

rotate()函数的转换原点是旋转中心

默认的转换原点是 center,所以如果是以center为旋转中心,可以不写transform-origin属性,或者写transform-origin: 50% 50%;transform-origin: center center;transform-origin: center;都可以。

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
在jQuery移动端H5页面开发中,我们可以使用以下技巧和方法: 1. 使用viewport设置移动端页面的宽度和缩放比例,例如: ```html <meta name="viewport" content="width=device-width, initial-scale=1.0"> ``` 2. 使用CSS3媒体查询来适配不同的屏幕尺寸,例如: ```css @media screen and (max-width: 768px) { /* 在屏幕宽度小于等于768px时应用的样式 */ } ``` 3. 使用jQuery Mobile框架来快速构建移动端页面,例如: ```html <!-- 引入jQuery Mobile库 --> <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <!-- 使用jQuery Mobile组件 --> <div data-role="page"> <div data-role="header"> <h1>Header</h1> </div> <div data-role="content"> <p>Content</p> </div> <div data-role="footer"> <h4>Footer</h4> </div> </div> ``` 4. 使用touch事件来处理移动端的触摸事件,例如: ```javascript $(document).on("touchstart", function(event) { // 处理touchstart事件 }); $(document).on("touchmove", function(event) { // 处理touchmove事件 }); $(document).on("touchend", function(event) { // 处理touchend事件 }); ``` 5. 使用CSS3动画来实现移动端页面的动态效果,例如: ```css @keyframes myanimation { 0% { transform: translateX(0); } 50% { transform: translateX(100px); } 100% { transform: translateX(0); } } .myelement { animation: myanimation 1s ease-in-out infinite; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值