gpt4 book ai didi

javascript - 仅对所有 iPhone 和 IPADS 进行样式设置的 CSS 样式

转载 作者:可可西里 更新时间:2023-11-01 02:40:56 26 4
gpt4 key购买 nike

问题:我的图像在除 iPhone 以外的所有平台上都具有响应能力。

在安卓版网站上,下图没有歪斜: enter image description here

在网站的 iphone 版本上,它正在炸毁图像,我不确定。

我认为以下内容可以解决除 IPHONES 和 IPADS 之外的倾斜问题

#homepage .carousel .item { 
height: auto !important;
}

#homepage .carousel .item img {
min-width: 100% !important;
max-width: 100% !important;
height: auto !important;
position: relative !important;
}

.carousel-indicators {
bottom: 2%;
}

话虽这么说,我还发布了我所做的其余 css,以使其响应不同的尺寸:

/***TEST 1.2***/
#homepage .carousel .item {
height: auto !important;
}

#homepage .carousel .item img {
min-width: 100% !important;
max-width: 100% !important;
height: auto !important;
position: relative !important;
}

.carousel-indicators {
bottom: 2%;
}

@media screen and (max-device-width: 375px) and (max-device-height: 667px) {
#homepage .carousel .item {
height: auto !important;
}

#homepage .carousel .item img {
min-width: 100% !important;
max-width: 100% !important;
height: auto !important;
position: relative !important;
}

.carousel-indicators {
bottom: 2%;
}
}

@media (max-width:331px){
.navbar-header{
margin-left:-20px;
}
.navbar-toggle{
position: relative;
float: right;
padding: 9px 10px;
margin-top: 8px;
margin-right: 0px;
margin-bottom: 8px;
background-color: transparent;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
}
}


@media screen and (max-width:331px) and (-webkit-min-device-pixel-ratio:0) {
#homepage .carousel .item img {
min-width: 100% !important;
width: 100% !important;
height: auto !important;
position: relative !important;
margin-top: 71px;
}
}
/*
@media only screen and (min-device-width: 375px) and (max-device-width: 667px) and (orientation : portrait) {
#homepage .carousel .item {
height: 200px !important;
}

#homepage .carousel .item img {
min-width: 100% !important;
width: 100% !important;
height: 200px !important;
position: relative !important;
}
}*/


@media (min-width:729px) and (max-width:748px){
#homepage .carousel .item img {
min-width: 100% !important;
width: 100% !important;
height: auto !important;
position: relative !important;
margin-top: 71px;
}
}

@media(max-width: 728px) and (orientation:portrait){
#homepage .carousel .item img {
min-width: 100% !important;
width: 100% !important;
height: auto !important;
position: relative !important;
margin-top: 71px;
}
}

@media screen and (max-width: 728px) and (orientation:portrait) and (-moz-images-in-menus:0){
#homepage .carousel .item img {
min-width: 100% !important;
width: 100% !important;
height: auto !important;
position: relative !important;
margin-top: 0px;
}
}

/*Firefox*/
@media screen and (max-width: 748px) and (-moz-images-in-menus:0) {
#homepage .carousel .item img {
min-width: 100% !important;
width: 100% !important;
height: auto !important;
position: relative !important;
margin-top: 0px;
}
}

@media(max-width: 768px) and (orientation:landscape){
#homepage .carousel .item img {
min-width: 100% !important;
width: 100% !important;
height: auto !important;
position: relative !important;
margin-top: 71px;
}
}

@media screen and (max-width: 768px) and (orientation:landscape) and (-moz-images-in-menus:0){
#homepage .carousel .item img {
min-width: 100% !important;
width: 100% !important;
height: auto !important;
position: relative !important;
margin-top: 0px;
}
}

@media (max-width: 767px){
.image-margin-top2 {
margin-top: 182px !important;
}
.eventMargin {
margin-top: -85px;
}
}

@media (max-width:748px){
#homepage .carousel .item {
height: auto !important;
}
}

@media screen and (min-width: 766px) and (max-width:1024px){
.carousel-caption{
right:20%;
left:15%;
top:-4%;
}
.titleSlide, h1{
font-size: 33px !important;
}
.content1{
font-size:20px !important;
}
}

@media screen and (min-width: 766px) and (max-width:1024px) and (orientation:landscape){
.carousel-caption{
right:20%;
left:15%;
top:14%;
}
.titleSlide, h1{
font-size: 33px !important;
}
.content1{
font-size:20px !important;
}
}


@media screen and (min-width: 1025px) and (max-width:1280px){
.carousel-caption{
right:20%;
left:20%;
top:20%;
}
}

@media (min-width:749px) and (max-width:767px){
#homepage .carousel .item {
height: auto !important;
/*margin-top:71px;*/
}
}

@media screen and (min-width:768px) and (max-width:991px) and (-webkit-min-device-pixel-ratio:0) {
#homepage .carousel .item {
height: auto !important;
margin-top:154px;
}
}

@media (min-width:783px) and (max-width:991px){
.eventMargin{
margin-top:-200px;
}
.image-margin-top2 {
margin-top: 60px !important;
}
}

@media (max-width:767px){
.image-margin-top2 {
margin-top: 176px !important;
}
}

@media (min-width:768px) and (max-width:782px){
.image-margin-top2 {
margin-top: 62px !important;
}

.eventMargin{
margin-top: -200px;
}

}

@media (min-width:992px){
.image-margin-top2 {
margin-top: 57px !important;
}
}

@media (min-width:992px) and (max-width:1024px){
#homepage .carousel .item {
height: auto !important;
margin-top:20px;
}
}

我使用以下站点定位 iPhone 和 iPad,但它对 iPhone 或 iPad 没有影响:http://stephen.io/mediaqueries/ .图像继续倾斜。

有没有办法检测网站何时显示在 iphone 和 ipad 上。一旦检测到它,调用另一个仅适用于 iphones 和 ipad 的 css 文件?

我能够找到一行代码来检测它是否在 iphone 上,但不确定如何为 iphone 和 ipad 修改它。我做了以下操作,但它似乎没有检测到是否检测到 iphone 或 ipad:

        <script language=javascript>
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
<link rel="stylesheet" href="/Regal-en-us/includes/themes/MuraBootstrap3/assets/bootstrap/css/iphone.css">
}
</script>

如有任何帮助,我们将不胜感激。

谢谢

更新

我使用以下方法检测用户使用的是 ipad 还是 iphone:

    <script language=javascript>
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
document.getElementsByTagName('head')[0].insertAdjacentHTML('beforeend', '<link rel="stylesheet" href="/includes/themes/MuraBootstrap3/assets/bootstrap/css/iphone.css">');
alert("Hello1.1!");
}
</script>

它确实检测到 iphone 和 ipad。但是,未检测到我正在做的样式。以下是我为 iphone 和 ipad 设置轮播图片样式的样式:

#homepage .carousel .item { 
height: auto !important;
}

#homepage .carousel .item img {
min-width: 100% !important;
max-width: 100% !important;
height: auto !important;
position: relative !important;
}

.carousel-indicators {
bottom: 2%;
}

/* Portrait and Landscape iphone and ipad*/
/*@media only screen
and (min-device-width: 375px)
and (max-device-width: 760px)
and (-webkit-min-device-pixel-ratio: 2) {
#homepage .carousel .item {
height: 139px !important;
margin-top:285px !important;
}
}*/
@media screen and (max-width:768px) and (orientation:portrait) and (-webkit-max-device-pixel-ratio:0) {
#homepage .carousel .item img {
/*min-width: 100% !important;
/*width: 100% !important;*/
height: 293px !important;*/
position: relative !important;
margin-top: 200px;
}
}

如您所见,它没有检测到媒体查询,但它被 IPAD 和 IPHONE 识别,因为警报消失了。

如有任何帮助,我们将不胜感激。

更新:

在这一点上,我只想在 iphone 和 ipad 上看起来不错。我已经为此工作了一段时间,但没有解决方案或进展

最佳答案

您的想法是正确的,您只需将链接标记插入到 DOM 中即可。

function isAppleSafari(userAgent){
var iPhone = userAgent.match(/iPhone/i) !== null;
var Apple = userAgent.match(/Apple/i) !== null;
var Mac = userAgent.match(/Mac/i) !== null;
var iPod = userAgent.match(/iPod/i) !== null;
var iOS = userAgent.match(/iOS/i) !== null;
var Safari = userAgent.match(/Safari/i) !== null;
return Safari && (iPhone || Apple || Mac || iPod || iOS);
}

// Use like this...
if(isAppleSafari(navigator.userAgent)){
document.getElementsByTagName('head')[0].insertAdjacentHTML('beforeend', '<link rel="stylesheet" href="/Regal-en-us/includes/themes/MuraBootstrap3/assets/bootstrap/css/iphone.css">');
}

我用了 insertAdjacentHTML 这里把它放在<head>页面的。

关于javascript - 仅对所有 iPhone 和 IPADS 进行样式设置的 CSS 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40597069/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com