I have checked many sites using bootstrap menu, it collapse after certain screen size , I am using 22 inch screen and navbar collapse when I see my website..
You have to use media query for your screen size in terms of pixels.
For example:
// Landscape phones and below
#media (max-width: 480px) { ... }
// Landscape phone to portrait tablet
#media (max-width: 768px) { ... }
// Portrait tablet to landscape and desktop
#media (min-width: 768px) and (max-width: 980px) { ... }
// Large desktop
#media (min-width: 1200px) { .. }
Bootstrap menu can be resized for almost many kind of screens like mobile, tablet, ipad, laptop, desktop etc. But some resolutions may have missed out in their media query. For ex: as you told " I am using 22 inch screen ".. your desktop's max-width may not have listed in their inbuilt media query.
So, what I suggest is it is better to write your own media query for that types of cases.
For example,
#media (max-width: 1080px) { ... }
#media (max-width: 1440px) { ... }
Related
I have a webpage that is 1800x1200px in dimension (made for desktop PCs). On tablets the page isn't viewed entirely, part of it spans over the right viewport. What I want to achieve is that the webpage displays correctly on tablets using a smaller zoomfactor. I'm absolute beginner with javascript, can anyone explain the js code to me to do that?
Try adding this in the <head> section
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Also you might have to use CSS media queries. If you are not familiar with that, Its better to learn it first.
For the time being, use the below media queries in your css
#media (min-width:320px) { /* smartphones, iPhone, portrait 480x320 phones */ }
#media (min-width:481px) { /* portrait e-readers (Nook/Kindle), smaller tablets # 600 or # 640 wide. */ }
#media (min-width:641px) { /* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */ }
#media (min-width:961px) { /* tablet, landscape iPad, lo-res laptops ands desktops */ }
#media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
#media (min-width:1281px) { /* hi-res laptops and desktops */ }
Sample usage
/* Use a media query to add a breakpoint at 768px: */
#media screen and (min-width: 768px and max-width: 1023px) {
.main{
width: 80%; /* The main class's width is 80% , when the viewport is gretaer than 768px or smaller than 1023px which is ideal for tablets (not big tablets) */
}
}
You can use media queries for achieving this behaviour, example as follows -
#media only screen and (max-width: 600px) {
body {
background-color: lightblue;
}
}
This will apply a background color when the screen size will be 600px or smaller.
The best answer i can give right now is to use css zoom
body{zoom:30%}
body:after{content:"lol"}
I'am creating new web site. My intention is creating one page for desktop and mobile and set styles depend of device (mobile or desktop). I know I can achieve everything with pure javascript, but I would like to use also CSS and media queries. My question is: how can I set style only for mobile devices using CSS media queries? I was trying to use:
#media only screen{
style...
}
But it works for both, mobile and dekstop browsers.
You can not simply target mobile but have to give break point in order for it to work. You will have to use min-width or max-width for that to work
/* Smartphones (portrait and landscape) ----------- */
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen and (max-width : 320px) {
/* Styles */
}
Example: This will hide div with class of sidebar and set container width to 100% on smaller screens
#media only screen and (max-width : 321px) {
.sidebar {
display:none;
}
.container{
width:100%;
}
}
Have you tried setting your styles based on screen-size rather than device?
https://css-tricks.com/snippets/css/media-queries-for-standard-devices/
If the styling, and even content, is entirely different from mobile to desktop, using a framework like Bootstrap makes this really easy. You can follow their strategy by creating hidden-xs and visible-xs classes with your own media queries, and apply those classes to different divs. Not the DRYest way of doing it, but gets the job done.
#media only screen
and (min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {
.hidden-xs {
display: none;
}
.visible-xs {
display: block;
}
}
I still don't have a solution can anyone help me with this must be easy. I think that the solution must be find in the javascript and not the media query, because that didn't work for me.
I got a responsive navigation that shows a nav-btn when screen is smaller than 1000px, but after using the nav-btn open+close the menu items disappear when resizing screen width, the horizontal menu items need to return in the place, but because of the js the menu-items disappear.
You see it when resize the screen so you see 4 menu items horizontal inline and when smaller than 1000px you see the responsive menu after open and close and resize the screen larger than 1000px 3 of the 4 menu-items are gone.
$(function() {
$('.nav-btn').click(function(event) {
$('nav ul').fadeToggle(300);
});
});
FIDDLE
I had same problem and solved it using CSS #media anotation:
#media screen and (max-width: 1000px) {
// your needed style here
}
Also if you have different sizes / needs check here.
IMPORTANT: to me I need to define ALL sizes to have correct behaviour when we have transitions in screen size, so to avoid weird things you must define something like this:
#media screen and (min-width: 769px) {
/* COMPUTER STYLES HERE */
}
#media screen and (min-device-width: 481px) and (max-device-width: 768px) {
/* TABLET STYLE HERE */
}
#media only screen and (max-device-width: 480px) {
/* MOBILE PHONE STYLE HERE */
}
I Use This Code To Automatically Detect Users Screen Resolution And Redirect To Another Page
<script>
if (screen.width==1367 && screen.height==768)
{
window.location="http://www.yoursite.com"
}
</script>
But For Every Screen Resolution I Cant Edit The Site.
Is It Possible That I Just Make Single Page That Can Automatic Fit To Screen.
Thank-You IN Advance.
You could use CSS3 media queries rather than javascript to detect the device and load the page accordingly.
#media only screen and (max-width: 999px) {
/* rules that only apply for canvases narrower than 1000px */
}
#media only screen and (device-width: 768px) and (orientation: landscape) {
/* rules for iPad in landscape orientation */
}
#media only screen and (min-device-width: 320px) and (max-device-width: 480px) {
/* iPhone, Android rules here */
}
You would also need to add the meta port view tag as below:
<meta name="viewport" content="initial-scale=1.0">
You can use media queries and specify different stylesheets for different screens.
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries
for example
<style>
#media (max-width: 600px) {
.facet_sidebar {
display: none;
}
}
</style>
For examples of already put up websites see: http://mediaqueri.es/
'defau1t' is write. Also you can set it by css like=> "width:100%"; you can check http://www.w3schools.com/js/js_window.asp too. Everything depends on your requirements.
From http://www.w3.org/TR/css3-mediaqueries/ we can see that there are many ways to declare media queries, eg:
(1) #media screen and (min-width: 400px) and (max-width: 700px) { … }
(2) #media handheld and (min-width: 20em),
screen and (min-width: 20em) { … }
(3) #media screen and (device-aspect-ratio: 16/9) { … }
(4) #media screen and (device-width: 800px) { … }
And so on.
I would like to know if there is any way in javascript or in the browser that we can find which width ranges certain media queries apply to.
Eg (1) would be between 400 and 700 and (4) would be exactly 800
It seems like it would be tedious to parse the media query strings to determine this information. Is there an easier way?
Try this mediaquery bookmarklet: http://fhemberger.github.com/mediaquery-bookmarklet/