Hallo, ich arbeite mit mehreren Tablets, iPad, Galaxy Tab, Acer Iconia, LG 3D Pad und so weiter.
Ich möchte das iPad nur mit einer CSS3-Medienabfrage ansprechen. Da die Gerätebreite von LG und iPad 768px ist - Ich habe Probleme, jedes Gerät zu trennen.
Ich habe Folgendes versucht, um mich zu trennen, aber es scheint nicht zu funktionieren:
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation : portrait) /* applied to lg also */
@media only screen and (min-resolution: 132dpi) and (max-device-width: 1024px) and (orientation : portrait) /* applies to lg also */
@media only screen and (device-aspect-ratio: 1024/768) and (orientation : portrait) /* does not work on iPad or LG */
Ich kenne das -webkit-Device-Pixel-Ratio und andere -webkit * -Optionen und deren Zielwerte für das iPad nicht. Ich möchte kein JavaScript für Stile verwenden, irgendwelche Ideen?
Endlich eine Lösung gefunden von: Verschiedene Geräteplattformen mit CSS erkennen
<link rel="stylesheet" media="all and (device-width: 768px) and (device-height: 1024px) and (orientation:portrait)" href="ipad-portrait.css" />
<link rel="stylesheet" media="all and (device-width: 768px) and (device-height: 1024px) and (orientation:landscape)" href="ipad-landscape.css" />
Um HTTP-Aufrufe zu reduzieren, kann dies auch in Ihrer vorhandenen allgemeinen CSS-Datei verwendet werden:
@media all and (device-width: 768px) and (device-height: 1024px) and (orientation:portrait) {
.ipad-portrait { color: red; } /* your css rules for ipad portrait */
}
@media all and (device-width: 1024px) and (device-height: 768px) and (orientation:landscape) {
.ipad-landscape { color: blue; } /* your css rules for ipad landscape */
}
Hoffe das hilft.
Weitere Referenzen:
Ich bin etwas spät dran, um darauf zu antworten, aber keines der oben genannten hat bei mir funktioniert.
Das hat bei mir funktioniert
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
//your styles here
}
Naja ganz gleiche Frage und es gibt auch eine Antwort =)
http://css-tricks.com/forums/discussion/12708/target-ipad-ipad-only./p1
@media only screen and (device-width: 768px) ...
@media only screen and (max-device-width: 1024px) ...
Ich kann es momentan nicht testen, also bitte testen =)
Auch noch einiges gefunden:
http://perishablepress.com/press/2010/10/20/target-iphone-and-ipad-with-css3-media-queries/
Oder Sie überprüfen den Navigator mit etwas Javascript und generieren/fügen eine CSS-Datei mit Javascript hinzu
Sie müssen das Gerät mit Hilfe eines Skripts auf den Benutzeragenten ausrichten. Der User Agent für das iPad ist:
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10
<html>
<head>
<title>orientation and device detection in css3</title>
<link rel="stylesheet" media="all and (max-device-width: 480px) and (orientation:portrait)" href="iphone-portrait.css" />
<link rel="stylesheet" media="all and (max-device-width: 480px) and (orientation:landscape)" href="iphone-landscape.css" />
<link rel="stylesheet" media="all and (device-width: 768px) and (device-height: 1024px) and (orientation:portrait)" href="ipad-portrait.css" />
<link rel="stylesheet" media="all and (device-width: 768px) and (device-height: 1024px) and (orientation:landscape)" href="ipad-landscape.css" />
<link rel="stylesheet" media="all and (device-width: 800px) and (device-height: 1184px) and (orientation:portrait)" href="htcdesire-portrait.css" />
<link rel="stylesheet" media="all and (device-width: 800px) and (device-height: 390px) and (orientation:landscape)" href="htcdesire-landscape.css" />
<link rel="stylesheet" media="all and (min-device-width: 1025px)" href="desktop.css" />
</head>
<body>
<div id="iphonelandscape">iphone landscape</div>
<div id="iphoneportrait">iphone portrait</div>
<div id="ipadlandscape">ipad landscape</div>
<div id="ipadportrait">ipad portrait</div>
<div id="htcdesirelandscape">htc desire landscape</div>
<div id="htcdesireportrait">htc desire portrait</div>
<div id="desktop">desktop</div>
<script type="text/javascript">
function res() { document.write(screen.width + ', ' + screen.height); }
res();
</script>
</body>
</html>
In diesen Tagen können Sie mit der Funktion Media Queries Level 4 prüfen, ob das Gerät die Fähigkeit hat über Elemente zu fahren .
@media (hover: hover) { ... }
Da das iPad keinen Schwebezustand hat, können Sie Touch-Geräte wie das iPad effektiv anvisieren.