I am failry new to bootsrap and wanted to ask, is there anyway, that when the device screen is in Portrait to always use "md" size columns, and when it is in landscape to always use "xs" columns?
Extend Bootstrap CSS using new or altered media queries. Normally leaving the original bootstrap.css file and extending it with the changes is the best way, or future upgrades will be troublesome. You might only want to recreate the grid classes you want to use, for example:
#media (min-width: 992px) and (orientation:landscape) {
.col-md-4 {
// some properties
}
}
#media (min-width: 992px) and (orientation:portrait) {
.col-md-4 {
// redefined
}
}
As mentioned by Skelly, there is no orientation switch built into Bootstrap itself at this time.
Here is my actual solution, maybe helps someone
#media (orientation: portrait){
.portrait{
width: 100%;
}
/*div[class^='col-xs'], div[class*='col-xs']{
width: 100%;
}*/
}
Two solutions:
1- is to add "portrait" class to any div that you want to see in portrait with width=100%.
2- Uncomment and use the second rule on the media that applies width:100% to any div that have a class name that starts width col-xs
As far as I know, there is no way to do this "out of the box".. Bootstrap uses media queries that are based on screen width, not orientation.
Related
I have a website. The page width is perfect in 15.6 laptops.
But when it comes to larger displays, it gets ruined. Can you please help?
any #media styles to be added?
Thanks
It seems you have written that CSS specially for your screen's resolution. To fix that you need to use media queries. Example:
#media (min-width: 1280px) {
width: 1120px;
}
I checked and you have a similar problem on smaller screens. You would like to apply a mobile-first strategy, so the layout looks good on all screens. Apply the same strategy (media queries) to set diffences sizes for different resolutions. The most common solution is to use 3 breakpoints. Example:
#media (min-width: 768px) { }
#media (min-width: 1280px) { }
#media (min-width: 1440px) { }
The CSS that you write inside those media-queries will target different screen sizes, but also the CSS in the smallest media-query will work in the next ones if it is not overrriden.
Please give width by % value if you give that in px it will change for different
I'm having a bit of trouble with my media queries.
Building a site using a purchased responsive wordpress theme, and am now customising it.
I'm running into an issue where, because of how the design behaves over a range of screen widths, I am using media queries to make adjustments whenever the design breaks.
Trouble is, various elements are breaking in different ways at different widths (not surprising).
So instead of getting a nice, exclusive range of media query sizes (eg: max-width: 480px, min-width: 481px --> max-width: 780px, min-width: 781px --> max-width: 960px, minwidth 961px) it's turning into an overlapping mess of queries.
Here is a sample of what I've got in my CSS so far, with CSS removed just to save space:
#media only screen and (max-width: 961px) {
/* upto 961px */
#media only screen and (min-width: 885px) and (max-width: 961px) {
/* 885px upto 961px */
#media only screen and (min-width: 768px) and (max-width: 884px) {
/* 768px upto 884px */
#media only screen and (min-width: 480px) and (max-width: 767px) {
/* upto 767px */
#media only screen and (max-width: 550px) {
/* Shrinks top nav text size for smaller screens*/
#media only screen and (min-width: 481px) and (max-width: 550px) {
/* Adjusts search bar location*/
#media only screen and (max-width: 565px) {
/* Toggles correct Justified Image Grid for home page buttons */
#media only screen and (min-width: 566px) and (max-width: 721px) {
/* Toggles correct Justified Image Grid for home page buttons */
#media only screen and (min-width: 722px) and (max-width: 902px) {
/* Toggles correct Justified Image Grid for home page buttons */
#media only screen and (min-width: 903px) {
/* Toggles correct Justified Image Grid for home page buttons */
Pretty messy huh? Please be nice, am still learning this stuff :)
So my main problem now is: the elements I'm controlling with the last 4 media queries (targeting the Justified Image Grid) contain very simple declarations - basically making certain elements display or not. I thought I'd defined these queries fairly exclusively, but they are not working the way I expect them to.
Is the problem possibly with my mess of other queries? (Even though the Justified Image Grid are not referenced in other queries?)
More than happy to take suggestions on how to handle queries in this kind of situation, which I'd imagine happens quite frequently with web builds...
EDIT:
Here is the link to the test page: http://dev.thecyclery.net.au/home-test/
There are two image grid elements, and I only want to display one at a time.
Thanks!
Jon
one way to simplify things a bit is to remove the min-width portions of the queries that have both a min and a max. Then while using only max-width queries you order them from largest to smallest.
#media only screen and (max-width: 961px) {
}
#media only screen and (max-width: 884px) {
}
#media only screen and (max-width: 767px) {
}
These will automatically override each other when the screen gets below each respective setting.
Personally I only use the max-width settings and adjust them accordingly, hopefully you can get away with the same thing if you set it up correctly.
One reason that you may be having trouble is that if two queries have some of the same size parameters (overlapping conditions) whichever one is located last will take precedence over the other, and this might not be your intended outcome.
(Also, my personal experience with purchased wordpress themes has been less than satisfactory, you are typically better off customizing _s or one of the twenty___ themes that come with wordpress. The trouble with purchased themes is that they are usually designed with a specific intent (or specific plugins)... an intent that is almost never the same as your own intent.)
I want to change the width of a div\grid via a media query for desktop users, but can't get the style to apply.
Here is the div in Chrome dev tools:
So I want to set the width of my .ticketInforHeader div. I tried to do this, but it does not do anything:
#media screen and (min-width: 992px) {
.ticketInfoHeader {
width 30%;
}
}
Try using
#media screen and (min-width: 992px) {
.ticketInfoHeader {
width 30% !important;
}
}
I guess if you're using Bootstrap's grid the width of the columns will be defined by the already existing classes like .col-md-4
You might need to add an !important to overwrite the Bootstrap style
#media screen and (min-width: 992px) {
.ticketInfoHeader.col-md-4 {
width 30% !important;
}
}
but that doesn't look really good in the code and I feel it breaks the logic of using bootstrap's grid.
I'm trying to create a responsive design using Twitter bootstrap. Everything is going well but I cannot figure out how to set a minimum width for desktop users.
When a user is on a desktop I don't want them to be able to shrink the browser to the point where they see responsive features meant for the phone (e.g. the navbar mobile button). I would rather just have a horizontal scroll bar when the browser gets too small. How can I get this functionality without affecting the mobile layout?
You can address this with a media-query. The only problem is that you have to set a fixed width for this, min-width doesn't seem to work in this case (tested in Firefox and Chrome). If this is fine for you, you can try the following example:
// Should be something > 1024
#media only screen and (min-device-width: 1300px) {
body {
width: 1300px;
}
}
To replicate the way that logicvault.com have their site working you would need to change the Bootstrap CSS so that you only have one media query which kicks in at 480px.
Here's the media query they have set:
#media only screen and (max-width: 480px){
// styles here
}
I was able to achieve this functionality by using Frederic's advice:
// Should be something > 1024
#media only screen and (min-device-width: 1024px) {
body {
min-width: 1025px;
}
}
However, I also needed to adjust the bootstrap responsive files so the styles were only applied to touch devices. I ended up including Modernizr on my page and looking for the touch class.
E.g. change:
#media (min-width: 768px) and (max-width: 979px) {
// Styles are here
}
to:
#media (device-min-width: 768px) and (device-max-width: 979px) {
.touch {
// Styles go here
}
new to css3 media queries and responsive design.
I would like to know how to show something (say a div) on small screens only but not on large screens.
I've tried something like:
#media (max-width: 480px) {
.show-on-small-only{ display:block; visibility:visible;}
}
...
and anything larger has eg:
#media (max-width: 768px) {
.show-on-small-only{ display:hidden; visibility:none;}
}
it doesn't seem to work as intended.
might be worth pointing out that i'm using bootstrap 2.0
It's a better practice to make all your default style mobile-friendly and then use min- media queries to size up:
div { /*put whatever your default styles are first*/ }
/* Then use the media query to hide it at 481 and wider */
#media all and (min-width:481px) {
div { display:none }
}
Look at 320andup and Skeleton and the CSS of this page for examples. Look at the helper classes towards the bottom of this CSS for differences between invisible/hidden etc.
You can put this first
/* for small screens, only execute in if statement */
#media only screen and (min-width : 320px) and (max-width : 768px) {
.smallOnly {
visibility:visible!important;
display:block!important;
}}
Then at the bottom of it put it for large screens (always execute since not in if statement)
.smallOnly {
visibility: none;
display: none;}
The important tg makes it so that anything with important always overwrite everything else and it will be the master rule regardless of where it is in the file.