【发布时间】:2015-06-08 15:01:26
【问题描述】:
我正在制作一个网站,我希望它能够完全响应移动设备。我以为我已经用标题实现了这一点,直到我用我的 ipad 看了它。 “转换:translateX(-100%);”该语句适用于除 IOS 设备之外的所有设备,我在我的 android 手机上尝试过它,它运行良好。我已经尝试了很多东西,包括使用像 -webkit- 这样的前缀和使用“!important”语句。我一直在网上搜索,但找不到任何可以解决我问题的东西。这是代码。
HTML
<!DOCTYPE html>
<h<html lang="en">
<head>
<title>Home</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="style.css">
<link href='http://fonts.googleapis.com/css?family=PT+Sans' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Alegreya+Sans' rel='stylesheet' type='text/css'>
<script src="http://timthumb.googlecode.com/svn/trunk/timthumb.php"></script>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
<script src="js/header.js"></script>
</head>
<body>
<div class="header">
<div class="container">
<div class="logo">
</div>
<div class="wrapper">
<div class="menu-icon">
<div class="line first"></div>
<div class="line second"></div>
<div class="line third"></div>
</div>
<div class="nav">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="http://4para.net/forums">Forums</a></li>
<li><a href="about-us.html">About Us</a></li>
<li><a href="role-finder.html">Role Finder</a></li>
<li><a href="orbat.html">ORBAT</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<div class="featured">
<h1 class="devMode"> Development Mode</h1>
<p class="devModeText">Our 100% mobile friendly website is still under development. If you would like to provide feedback or suggestion please post them <a href="http://4para.net/forums/showthread.php?tid=28" target="window">here</a>, anything is helpful!</p>
</div>
</div>
</body>
</html>
CSS
@media screen and (max-width: 810px) {
/*header*/
.nav {
margin: 15px -40px ;
background-color: #3f3f3f;
transform: translateX(-100%);
transition: 0.6s ease;
-webkit-transform: translateX(-100%);
-ms-transform: translateX(-100%);
}
.menu-icon {
position: relative;
margin-left: 10px;
display: block;
height: 54px;
width: 54px;
background-color: #2a2a2a;
/*border: 0.75px solid #000;*/
border-radius: 50%;
}
.line {
width: 38px;
height: 2px;
background-color: #fff;
border: 1px solid #fff;
border-radius: 5px;
margin-top: 5px;
margin-bottom: 5px;
}
.logo {
float: right;
}
.nav ul li {
list-style: none;
display: block;
padding: 10px 120px 10px 30px;
}
.open {
transform: translateX(0);
-webkit-transform: translateX(0);
-ms-transform: translateX(0);
}
.first {
position: relative;
top: 15px;
margin: auto;
}
.second {
position: relative;
top: 20px;
margin: auto;
}
.third {
position: relative;
top: 25px;
margin: auto;
}
/*end of header*/
.container {
margin: 0 10px 0 10px;
}
}
JS
$(function() {
$('.menu-icon').on('click', function(){
$('.nav').toggleClass('open');
});
});
更新:我的网站实际上已被缓存,因此选择使用 Cloudflare 进入开发模式,结果证明这两种方法都有效。非常感谢所有与我不同回复如此迅速的人。
【问题讨论】:
-
iOS 的哪个版本?
-
我似乎记得IOS不能/不能处理单维转换。所以
translateX(-100%)不起作用,但translate(-100%,0)会 -
你是这样给的。我认为有一些关于此stackoverflow.com/questions/4919963/css3-transform-not-working 的旧帖子被引用
-
@RahulS 这里没有转换内联元素。
-
感谢您的所有回答和建议。我已经尝试了所有这些,但它们不起作用。我应该直接联系 Apple 还是应该以另一种方式创建移动标题(我是菜鸟,所以我需要一个教程链接)?
标签: javascript html ios css transform