CSS - Detecting Media And Writing Css For Them
Is there a way to detect whether someone is using a mobile device, and write specific CSS according to whether the viewer is using a computer or Iphone/ Blackberry or other mobile device?
Any links or info is appreciated. thanks - Similar TutorialsHi I have some css styles that work like I want when displayed in a browser but when I print the screen to a PDF, almost all the info is lost, reverting to a single long column of text. Do you need to define separate 'screen' and 'print' versions of a style? If so, how do you include them in a page? Do you have to jump through any special hoops to insure the browser uses the correct media type (screen/print) for the correct media? TIA Hi im trying to detect ie or mozilla but i cant get it to work.. could somebody please tell me what is wrong with my code.. thanx in advance !!! Code: Code: <head> <script language="javascript"> <!-- Begin browser_version = parseInt(Navigator.appVersion); browser_type = navigator.appName; if (browser_type == "Microsoft Internet Explorer" && (browser_version >= 4)) { document.write("<link REL='stylesheet' HREF="style.css" TYPE='text/css'>") ; } else if (browser_type == "Netscape" && (browser_verson >= 4)) { document.write("<link REL='stylesheet' HREF="stylemozilla.css" Type='text/css'>") ; } // --></script> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>---</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <style type="text/css"> <!-- .Style9 { font-size: 26px; color: #85AC1E; } .Style13 {color: #85AC1E} .Style15 {font-size: 19px} .Style16 {font-size: 22px} --> </style> </head> From what I see, I can do the samething without it. So when exactlly would I used it? Thanks. I put together the following site ... http://www.themax.co/ I am trying to create a style sheet for the PRINT pages, but I ran into some problems (the main site looks fine, but the print page doesn't). First, go to the page... http://www.themax.co/?page_id=6 When you go to print, and look at the print preview (in Firefox). most of the content is pushed to the second page. I assume this is because of the style .pagesidebox (which is a column that spans the entire page) ... I think this is causing the rest of the content to go to the next page. Any idea how to fix this? Second, I have a logo that goes against the black background (on the website) and a white logo that is supposed to appear on the print page. So, in the print.css stylesheet, I called the background-image to point to the new image. However, the new image is not showing up when printing. I assume this is because the image is a BACKGROUND image, and the print settings are set to NOT show backgrounds. Is there a way around this (using CSS)? Since there are two logos (one on white, and one on black), I can't place the image inside the html page (I have to use CSS). Please let me know. Thanks! Hi, I am trying to serve another menu than my hover dropdown menu to touchscreens, and I am trying to do it using @media First I tried to only add a max-width using display none, it worked when I clicked but sometimes when the next page opened the page opened with the menu open, so I added an @media for the min-width also, and I think, not 100% sure that it works now. So I wonder If I want to have a diferent style for a class or div do I have to put @media on all classes or should it be enough to do only on one of them. Also Im not sure if the max-widht is to high, I did as I wanted to include tablets in non hover, but dont want to exclude pcs.... Well this is what I got so far, the css for the menu: Code: @media screen and (max-width: 1025px){ #menu ul ul .level2{ display:none} #menu ul ul .level3 { display:none} #menu ul ul .level4 { display:none} #menu ul ul .level5 { display:none} #menu ul ul .level6 { display:none} #menu ul ul .level7 { display:none} #menu ul ul ul {top:-1px; left:100%;} div#menu ul ul, div#menu ul li:hover ul ul, div#menu ul ul li:hover ul ul {display: none;} div#menu ul li:hover ul, div#menu ul ul li:hover ul, div#menu ul ul ul li:hover ul {display: none;} } @media screen and (min-width: 1025px){ #menu ul ul ul {top:-1px; left:100%;} div#menu ul ul, div#menu ul li:hover ul ul, div#menu ul ul li:hover ul ul {display: none;} div#menu ul li:hover ul, div#menu ul ul li:hover ul, div#menu ul ul ul li:hover ul {display: block;} } Thanks Hello, I understand that there are at least 7+ media types for CSS and more may be added later. http://www.w3.org/TR/REC-CSS2/media.html I want a special stylesheet for print but all other media should use the same stylesheet. Code: <style type="text/css" media="print">@import "print.css";</style> <style type="text/css" media="all except print">@import "main.css";</style> The following is a bad idea because it does not cover media that may be added in the futu Code: <style type="text/css" media="aural, braille, embossed, handheld, projection, screen, tty, tv">@import "main.css"; <style type="text/css" media="print">@import "main.css"; I've set up a simple responsive design at [redacted] (my first such attempt at responsive design). The media queries seem to work fine when I resize my browser. However, when using my phone it seems to work with Opera Mini but not Opera Mobile or Androids built in browser. Ok, I guess I can't post the URL so hopefully this is something that someone has experienced before and can point me in the right direction. I've been running into a problem where iPod Touch and iPad are applying styles from media queries they shouldn't be. This seems to be a bug, but maybe I'm doing something wrong. Here's a simple test page: Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Mobile test</title> <style> @media screen and (max-device-width: 480px){ /* ipod/iphone */ BODY {background: orange;} } @media screen and (max-device-width: 1024px){ /* ipad */ BODY {background: green;} } </style> </head> <body> </body> </html> This shows green on the iPad, and green on the iPod. If I change to something crazy: Code: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Mobile test</title> <style> @media screen and (max-device-width: 480px){ /* ipod/iphone */ BODY {background: orange;} } @media screen and (max-device-width: 6000px){ /* ipad */ BODY {background: green;} } </style> </head> <body> </body> </html> iPod: green iPad: green If I switch the order: Code: @media screen and (max-device-width: 1024px){ /* ipad */ BODY {background: green;} } @media screen and (max-device-width: 480px){ /* ipod/iphone */ BODY {background: orange;} } Correct. iPad: green iPod: orange Back to crazy: Code: @media (max-device-width: 60000px){ /* ipad */ BODY {background: green;} } @media (max-device-width: 4800000px){ /* ipod/iphone */ BODY {background: orange;} } iPod: orange iPad: orange I COULD go back and refactor my code to put all the iPad specific stuff first, but I'm hesitant to do that with a system that seems broken. Is it actually broken, or am I doing something wrong? Both devices are running iOS 4.3. Hi all, I am developing a website and kiosk display hardware. I want to target the kiosk display using a specific stylesheet. What is the best way? @media display and height:??px and width ??px or using @media ???kiosk??? etc. What other specifics can I target to define which style sheet is used? Thanks for any help. Dale. In the media=print style sheet I want to change the location of the div containing the material to be printed. Using this in the print style sheet does not move the div. #divname {position: absolute; left:50px; top:100px; width:200px;} Can a div be moved with a new style sheet. Hi, Opened a new post as its better. I am trying to do things for smaller devices such as mobiles and tablets. If I add something very simple in the stylecheat to the @media query such as background color of the body using this: @media screen and (max-device-width: 2000px){ body { width:766px; margin:auto; background-color:#00FF00;}} Or if I do this wich seem to have the same affect: @media screen and (max-width: 2000px){body { width:766px; margin:auto; background-color:#00FF00;}} I dont get the green background on the body, I only get it on my pc, on my samsung mini, on blackberry I dont get the green background and using adobe advice central on samasung tab and ipone 4 and maybe some more I get it, on the rest no background color. This is so strange, I imagen all have greater width than 2000px. If I set to max-width to 500 px I dont get it on my samsung mini either...????? it have a very small resolution, only 240 x something. I just dont get it I dont have any background color declared except the one in the @media query What i am trying to do is when the user tries to print out the HTML document, then the printer prints out what is in this: <link rel=alternate media=print href="printthis.doc"> It works in IE but it doesn't work in Mozilla Firefox. Does anyone know a way on how this is done in Mozilla Firefox or even both...?? Cheers, Jackson I've got a pain of a problem. Firstly I've got my styles as Code: <!-- styles that need applying in all browser (including IE/NS 4.x) <link ... /> <!-- styles that need applying in modern browsers (IE 5> etc.) --> <style type="text/css" media="screen"> @import "/screen.css"; </style> <style type="text/css" media="print"> @import "/print.css"; </style> The problem is that IE 5 & 5.5 seem to ignore the media attribute on the style blocks so they include all the styles. I read somewhere that using @media will solve this problem, so I did: Code: <!-- styles that need applying in all browser (including IE/NS 4.x) <link ... /> <!-- styles that need applying in modern browsers (IE 5> etc.) --> <style type="text/css"> @media screen { @import "/screen.css"; } @media print { @import "/print.css"; } </style> This works fine in IE 5.x and IE 6, but now for some reason Firefox (1.0.7) is not including ANY of the imported sheets. However if I add normal rules within the @media ... {} sections then they are applied. Can anybody verify this, and does anyone have a solution? Thanks in advance, -D Or do I have to replicate every CSS class in print? That would double the size of my CSS file! What's the correct way? Will this work as I hope? Code: div.news { width:690px; padding:10px; margin:0; float:left; background-color: #DDDDDD; } .button_div { width:180px; padding:10px; background-color:#953956; cursor:pointer; } .body_text { color:#284186; line-height:130%; font-size:11px; } @media print { div.news {background-color:#EEEEEE;} .button_div {display:none;} .body_text {color:#000000;} } Also, is it ok to do this? Any issues I should be aware of? Code: // CSS p.italic {font-style: italic;} p.large {font-size: 150%;} // HTML <p class="italic large">Italic and large.</p> Thanks, Basically I'm trying to create a word processor feel on a web page. I need a contentEditable div/iframe that will display as legal paper size sections, like a word processor would. So that when the text starts to over flow page 1, it would move to page 2, etc... Any ideas? I'm willing to pay for a good solution at this point... I've looked over my syntax a hundred times, but I can't get the print preview in IE to match the style declarations I've put in my css document. None of them work, so obviously it's something i've messed up in the overall structure of the code, and not minor errors. This is at the end of my .css document that I linked to my html: Code: @media print {body {font-family: arial, helvetica, sans-serif} a {text-decoration: none; color:pink} img {border-width: 0px} #hideprint {display: none} #instruction {display: none} #lpmap {page-break-after: always} .notes {page-break-inside: avoid; margin: 30px 30px 30px 30px; }} Thanks Hi Apologies if this is in the wrong forum but it stradles CSS, HTML and PHP. Is it possible to use @media within a style tag in html like so: <div style="@media screen { background-image: url(<?php echo $imageurl; ?>); background-repeat: repeat-x; background-position: left bottom;}"></div> The reason I am not not using it in the stylesheet directly is because I echo out all my template images dynamically with php. It seemed to work initially but then stopped. Anyone done this before? Garrett Hi, For some reason my css sheet for printing is producing huge text on the printouts in the main section of the page and I can't figure out why. style sheet included by: <link rel='stylesheet' href='print.css' type='text/css' media='print'> section in question: .pr{color : #000000; font-family: verdana; font-size: 10px} for some reason the font size is being ignored and the text come s out massive. the whole code for the page is too long to post but the section in question has a lot of tables enclosed in: <span class='pr'> </span> I know the stylesheet is being included properly cos it is hiding lots of other sections. Anyone got any ideas? Thanks Hi, Trying to get this widget to disappear using responsive design when the browser is less than 800px. I'm using WordPress and the theme is already responsive. Here's the media query in the style sheet now: @media only screen and (max-width: 800px) { /* and I added this part below (not working!) */ .page-title .widget-area { display:none !important; } } Please see http://simplemethod.ca to check it out. I'm trying to remove my big fancy title widget with the signup form in it (since it breaks in an ugly way when the responsive design kicks in!) Thanks for helping friends. I hope my post made some sense! Perhaps I'm using the wrong class names for the style change... This part has got me a bit stumped. Best Regards, Drew |