TWBS Navbar on mobile device, disable dropdown menu and use link instead - ios

Is there a way to disable the dropdown menu in Twitter Bootstrap 3 navbar when viewing on an iPhone and similar device sizes and then to replace it with a link to another screen.
The menu takes up a lot of space. On a desktop (even a tablet) this doesn't matter. On a mobile phone I would like it to take you to a different page and disable the dropdown altogether.

CSS Approach
I would use the responsive classes for this. It's probably not ideal to have extra markup for hidden elements, but it is the easiest and most reliable approach and requires no Javascript.
demo
...
<li class="visible-xs-block"><span class="glyphicon glyphicon-user" aria-label="My profile"></span> My Profile</li>
<li class="dropdown hidden-xs">
<span class="glyphicon glyphicon-user"></span> My Profile <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li><span class="glyphicon glyphicon-signal"></span> Statistics</li>
<li><span class="glyphicon glyphicon-certificate"></span> Certificates</li>
<li><span class="glyphicon glyphicon-star"></span> Favorites</li>
<li class="divider"></li>
<li><span class="glyphicon glyphicon-log-out"></span> Logout</li>
</ul>
</li>
...
In the above snippet, you'll see that I'm using the visible-xs-block class on the <li> with the link to your alternative page. This will insure that that this element is hidden, except on mobile devices. On the dropdown, I've used the hidden-xs class, which will hide the dropdown only on mobile devices.
Javascript Approach
You can do this with Javascript as suggested by #cvrebert, and if you don't have to worry about support for IE8 or IE9, you can do this easily with matchMedia.
JS (no support for IE8/9)
if (window.matchMedia("(max-width: 768px)").matches) {
/* the view port is less than 768 pixels wide */
/* hide your dropdown and display your link */
} else {
/* the view port is at least 768 pixels wide */
/* show your dropdown and hide your link */
}
It's a bit more complicated if you want a Javascript solution and need to support IE8/IE9 because you'll have to monitor the window resize event. To do this efficiently, you'll probably want to debounce or use a timeout.
Again, to me, the best way is the CSS approach above.

Related

How to use Bootstrap 5 for a typical home page layout instead of CSS?

CodePen https://codepen.io/david263/pen/zYNaoRQ shows an example simple home page layout that fits the browser viewport perfectly and centers some div content (choose Change View > Full Page View in CodePen to see the page clearly). But note the CSS style elements used to set div heights and the many Bootstrap 5 classes used to achieve vertical centering. It took several days to get this working, but it fails to use only simple Bootstrap 5 classes.
<header id=jumbo class="px-5 d-flex justify-content-center align-items-center bg-dark" style="height:70vh">
<div class="row col-12 text-center text-light">
<h1 class="font-weight-bold display-4">Vertically Centered Jumbo Content</h1>
<h3 class="font-weight-bold">A great starter layout for a landing page</h3>
</div>
</header>
My attempt to use the usual container, row, and col classes (see https://codepen.io/david263/full/xxgzLPj) failed to achieve the full height demonstrated by the first example.
<header id=jumbo class="container-fluid bg-dark">
<div class="h-50 row align-items-center col-12 text-center text-light">
<div class="col py-auto">
<h1 class="font-weight-bold display-4">Vertically Centered Jumbo Content</h1>
<h3 class="font-weight-bold">A great starter layout for a landing page</h3>
</div>
</div>
</header>
And these difficulties were encountered before adding a background image, which doesn't seem possible in Bootstrap 5 at all.
Don't get me wrong; I'm not opposed to using CSS when necessary. It's just that it's hard to tell exactly what the limits are for Bootstrap 5 so that custom CSS becomes necessary.
Many websites have a home page containing a large photo or video in the background, with text centered horizontally and vertically in the foreground, so this example represents something that is very often used. Surely such a frequent layout must be possible in Bootstrap 5.
Bootstrap isn't a silver bullet - its a framework (think of it as a chassis that you need build on top of). Bootstrap offers a few "helper" classes so that one does not need to add a whole bunch of repetitive CSS .. but that's all it can do. A clear understanding of CSS helps a lot too in using Bootstrap.
For example, the h-50 class is only height: 50%; in CSS. That's 50% of it's parent .. but your <header id="jumbo" does not have a height .. so 50% of what .. 0 .. is unknown?? (This may vary from browser to browser)
It's not clear what you're trying to achieve - but if you head on over to https://getbootstrap.com/docs/5.0/examples/ you'll see a whole bunch of examples and starting points for you to get to where you need to be. I think the Cover example is a good spot to land on. (Once there, right click and "view page source" ...)

Is there a way around whatever the iPad is doing with my site?

I have recently taken up web design and I am in no way an expert. I am developing this site for myself and I seem to be having some problems. This site looks about the same (it's still under development) across all browsers and I've been working on tablet and mobile phone specific css. While doing testing for the iPad (I use the xCode iOS Sim) I noticed that my menu bar was not working except in what seem like random moments (usually when I was zoomed in). I had a family member test this on their physical iPad and they couldn't use the nav bar at all. This jsFiddle link contains the html and css that run the navbar. I will be spending the next few hours working on this and will update or remove this post if I figure it out, but if I do not, any help is appreciated.
This is the html only, the css is too long.
<h2>Auburn PC Repair<br>& Building</h2>
<div id="header-image">
<h1></h1>
</div>
<nav id="buttonbar">
<ul>
<li id="services-button"><div class="buttonHighlight"></div>
<h3>Our Services</h3><p>how can we help you</p>
<ul>
<li>PC Repair</li>
<li>Mobile Device</li>
<li>Networking</li>
<li>PC Building</li>
</ul>
</li>
<li id="contact-button"><div class="buttonHighlight"></div>
<h3>Contact Us</h3><p>phone and email</p>
</li>
<li id="about-button"><div class="buttonHighlight"></div>
<h3>About Us</h3><p>all about us</p>
</li>
</ul>
</nav>
EDIT: The navbar was designed around www.panic.com/coda navbar. It works just fine on the iPad.
EDIT: The current setup works on all non-iOS devices.
Your navigation relies on hover events to trigger menu content to appear.
A hover event is triggered by the mouse moving over an element.
Touch devices, such as all iOS devices, as well as most, if not all, contemporary smartphones and tablets, do not have a mouse and as such there is no way for a hover event to be triggered.
You cannot achieve what you want on contemporary touch devices using only CSS.
There are various touch-related events that can be fired and responded to using JavaScript. You will need to opt not for a CSS-based menu-triggering approach and instead use a JavaScript-based approach where both hover and touch events are handled to produce the menu system you desire.

Twitter bootstrap accordion strange behavior

I am using the bootstrap accordion (collapse) in my project, but unfortunately the result is not the desire one. I have around 8 items in the accordion, some of them having lot of text inside (sometimes more than half a page).
I am trying to collapse/expand items in accordion, but the behavior is totally strange and unpredictable. I just copied the example on their site and added more items.
My expectations was that each time I click on a closed item it will open and the open div will receive focus. Sometimes I see page scrolling very fast and focus is positioned in a wrong place or item is opened but focus is too low on the page and title is not visible.
Any idea on how to handle accordion properly or what's the correct behavior ?
Here's a working example http://jsfiddle.net/panchroma/RdK8t/
It's taken directly from the bootstrap example with extended content added to one of the elements.
The typical code is:
<div class="accordion" id="accordionParent"> <!-- start #accordionParent wrap -->
<!-- start typical content group -->
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordionParent" href="#collapseOne">
Collapsible Group Item #1
</a>
</div>
<div id="collapseOne" class="accordion-body collapse in">
<div class="accordion-inner">
content
</div>
</div>
</div>
<!-- end typical content group -->
</div> <!-- end accordionParent wrap -->
You could validate your page to ensure there isn't a nesting problem, and double check that if your aren't using the full bootstrap js file, make sure you are including the transitions plugin.
Hope this helps!

jquery mobile & swipe.js

I created a carousel with swipe.js , it works fine in iOS4 and iOS5. But in iOS6, without acceleration of hardware, when we swipe, there is a lag that can not be accepted.
I have tried to create a carousel without jquery mobile, the performance is really great, but when we use JQM and listview (data-role="listview"), it became slower and the more elements in the list, the slower carousel is.
In html code, we have a carousel list and a normal listview, it seems if there are more elements in the listview, the carousel swipe will be slower. and they are two elements independent.
Here is html code
<div id='slider' class='swipe' style='width:250px'>
<ul>
<li style='display:block'><div>1</div></li>
<li style='display:none'><div>2</div></li>
<li style='display:none'><div>3</div></li>
<li style='display:none'><div>4</div></li>
<li style='display:none'><div>5</div></li>
</ul>
</div>
and a normal list view
<section class="nav_univers">
<h1>Toutes les catégories</h1>
<nav>
<ul class="categories" data-role="listview" data-inset="true">
<li>Livre<a class="xt_books"></a></li>
<li>Musique<a class="xt_music"></a></li>
<li>Video<a class="xt_video"></a></li>
<li>Jeux<a class="xt_video_games"></a></li>
<li>AAA<a class="xt_phone_gps"></a></li>
<li>QQQ<a class="xt_computing"></a></li>
<li>DDS<a class="xt_multimedia"</a></li>
<li>VVV<a class="xt_home"></a></li>
<li>GGG<a class="xt_sports"></a></li>
<li>HHH<a class="xt_mode"></a></li>
</ul>
</nav>
</section>
and with Swipejs to create an object
var slider1 = new Swipe(document.getElementById('slider'));
You can find our site here:
www.priceminister.com with user agent set to mobile device.
anyone can help me?
I had the same problem,
Change your css with :
.swipe
{
....
....
/* IOS6 issue*/
-webkit-perspective: 1000;
-webkit-backface-visibility: hidden;
}

JQuery Mobile Tabs

Does anyone know if JQuery Mobile does Tabs that stick to the bottom like the iphone native apps?
Thanks
Yes, they have tabs that stay fixed to the bottom:
http://jquerymobile.com/demos/1.0a4.1/#docs/toolbars/footer-persist-a.html
They behave slightly differently in that they disappear while scrolling and then reappear after the scrolling is finished.
You can also watch the navbar section for more examples:
http://jquerymobile.com/test/docs/toolbars/docs-navbar.html
Example code:
<div data-role="navbar">
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</div><!-- /navbar -->

Resources