From what I have been able to find on the net this is not possible, but I cannot be certian of this.
What I would like to do is to disable my nav bar stylesheet and switch to another nav bar stylesheet based on browser width. This would eliminate the need of having to disable all of the features that the wide-screen nav bar has before I implement the small viewport nav bar.
Well you could technically write your mobile (or larger screen) stylesheet to cancel out the properties of the other stylesheet. Other than that, perhaps Javascript might be able to help you or PHP.
So in conclusion; either make the stylesheet cancel the other one out (reset to defaults), or use Javascript for this.
@RyanReese
Thanks for the comments. I was afraid that was going to be the answer, but thatâs fine. Setting my nav bar back to its default is not a problem. I think it would be great if we could have this capability. Someday??
As @kirkbeard says, this is the purpose of media queries. You donât have to disable anything, but rather just target your rules to the appropriate screen size.
If using media queries, you also need to add the viewport meta element to the head of your pages. E.g.
I think you missed Santafeâs point in that he doesnât want to cancel out previous styles with media queries but start with a clean slate for the mobile nav.
You could do it with a simple class change on the nav using a script and then target each nav using the class that you added. Of course that makes the page reliant on a script to work (although most mobile menus are in initiated with a script toggle anyway).
Usually itâs not that hard to undo styles anyway.
For the latest versions of Firefox and webkit you can use the âallâ keyword to reset an element to its default.
I thought that might be what @santafe meant, but generally speaking, itâs the wrong way to go about things. If you write clean HTML/CSS then @media queries are quite easy to work with, and have been designed to achieve exactly what @santafe is after.
If you want your visitors to be able to choose which stylesheet they want to use themselves and to disable the rest then this can be easily done using a few lines of JavaScript to change the rel attributes. Simply set up the active one with rel=âstylesheetâ and the inactive ones with rel=âalternate stylesheetâ and give eash a title attribute to identify them. You can then call the following script passing the title of the one you want to use to switch to using that one:
function changeStyle(title) {
var lnks = document.getElementsByTagsName('link');
for (var i = lnks.length - 1; i >= 0; i--) {
if (lnks[i].getAttribute('rel').indexOf('style')> -1 && lnks[i].getAttribute('title')) {
lnks[i].disabled = true;
if (lnks[i].getAttribute('title') == title) lnks[i].disabled = false;
}}}
This also works without the JavaScript in browsers that have a stylesheet switcher built in.
As pointed out above, you donât need to disable stylesheets where all of the information to determine what to use is available at the start. You can disable stylesheets though if you want your visitors to be able to switch the stylesheet themselves.
First of all, I want to say Thank you!! to all who have offered their help and suggestions. Every post has been a tremendous help to me and I sincerely appreciate all the time everyone has spent on my behalf. I have only been at this HTML/CSS business for a month and I have learned a ton, but regardless, I am still a rookie - and I know that. No problem. I get it.
That said, I think I am trying to have my cake and eat it, too. By that I mean that I want to have the nice animated nav menu that is currently on this test website. But - at the same time, I want to have a completely different nav bar when the viewport width is reduced to about 960px or so. I âthinkâ I have the skill to simply incorporate a âhamburgerâ style nav menu when the viewport is reduced via a media query, but in truth, this is not an easy tack for me to accomplish.
The smart thing for me to do would be for me to abandon my animated nav menu and just go the âhamburgerâ menu route and be done with it. This would save me a lot of time and grief in so doing. I have a working model at the moment and it works fine. So that is where it stands for the time being.
Again, thanks to everyone who has posted their suggestions and help.