dropdown doesn't obey centering - twitter-bootstrap-3

I am trying to get a series of controls positioned vertically and centered horizontally. The controls are coming out fine, but when I cause the dropdown to drop down, the dropdown text appears left justified on the screen rather than under the centered dropdown control. I've spend a couple of hours on it and I can't get it right. Help would surely be appreciated. Here is what I am using:
<div style="margin-top:50px; text-align: center;">
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Shift / Project2
<span class="caret"></span></button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a class="dropdown-item" href="#">HTML</a></li>
<li><a class="dropdown-item" href="#">CSS</a></li>
<li><a class="dropdown-item" href="#">JavaScript</a></li>
</ul>
</div>
<input autocorrect="off" autocapitalize="off" spellcheck="false" type="text" id="xxx" style="margin-top:50px;">
</div>

You could solve this issue using css like i did here:
http://www.bootply.com/zck8H4EVt4
Just add this to your CSS:
.dropdown-menu {
left: 50%;
transform: translate(-50%, 0);
}
// EDIT:
Sorry, i've forgot about the btn-group class...
Just remove the CSS part from the first solution, add .btn-group to your dropdown and use .clearfix after your btn-group like i did here:
<div style="margin-top:50px; text-align: center;">
<div class="dropdown btn-group">
<button class="btn btn-primary dropdown-toggle" id="dropdownMenu1" aria-expanded="false" aria-haspopup="true" type="button" data-toggle="dropdown">Shift / Project2
<span class="caret"></span></button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a class="dropdown-item" href="#">HTML</a></li>
<li><a class="dropdown-item" href="#">CSS</a></li>
<li><a class="dropdown-item" href="#">JavaScript</a></li>
</ul>
</div>
<div class="clearfix"></div>
<input id="xxx" style="margin-top:50px;" spellcheck="false" type="text" autocapitalize="off" autocorrect="off">
</div>
Working example: http://www.bootply.com/lryEFqtmdp

Related

My bootstrap nav menu doesn't collapse when a li choice is made

I'm trying to start my own business and looking to save a bit of money by using a bootstrap 3 based template I purchased.
The menu on mobiles doesn't collapse when a menu item is chosen nor when someone clicks outside the menu. Apparently it's not supposed to which strikes me as wildly counterintuitive but there we go. How might I go about getting it to collapse when a subject is chosen OR someone clicks outside the menu, please? There are similar questions here but none of them have worked for me thus far. I'm probably doing something stupid though.
<nav class="navbar navbar-default">
<div class="row">
<div class="navbar-header col-md-3 col-sm-3">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#nav-res"> <span class="sr-only">Toggle navigation</span> <span class="fa fa-navicon"></span> </button>
<!--======= LOGO =========-->
<div class="logo col-2"><img src="images/pdriving4.png" alt="" ></div>
</div>
<!--======= MENU =========-->
<div class="col-md-9 col-sm-9">
<div class="collapse navbar-collapse" id="nav-res">
<ul class="nav navbar-nav">
<li class="dropdown active"> Home </li>
<li class="dropdown"> About Paul</li>
<li class="dropdown"> Passed Gallery </li>
<li class="dropdown"> Courses </li>
<li>Contact</li>
<li class="dropdown"> FAQs </li>
<li class="dropdown"> Book Now </li>
</ul>
</div>
</div>
</div>
</nav>

make dropdown over my datatabe

after click in my single button ,the dropdown is under my datatables !
my code :
<div class="dropdown">
<button type="button" class="btn btn-icon" aria-label="btnGroup" data-toggle="dropdown" >
<i class="icon icon-dots-vertical"></i>
</button>
<div class="dropdown-menu" aria-labelledby="btnGroup">
<a class="dropdown-item" href="#">Modifier Contrat</a>
<a class="dropdown-item" href="#">Supprimer Contrat</a>
</div>
</div>
If you want the dropdown to stay within your modal without adjusting the z-index you can align the dropdown the the right edge of your button using the class 'dropdown-menu-right' on the 'dropdown-menu' div:
<div class="dropdown">
<button type="button" class="btn btn-icon" aria-label="btnGroup" data-toggle="dropdown" >
<i class="icon icon-dots-vertical"></i>
</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="btnGroup">
<a class="dropdown-item" href="#">Modifier Contrat</a>
<a class="dropdown-item" href="#">Supprimer Contrat</a>
</div>

Bootstrap3 Navbar Link Positioning

So I'm running into an issue with my navbar and media queries. I can get it to switch from regular logo to a smaller logo with no problems. The visible-sm class is giving me issues as for the life of me, I cannot get the text links to the right to reduce the margin forcing the smaller logo up and making the navigation a horror. Did I miss something in the documentation? It seems like something really simple to reduce the rela estate the links are using when hitting the 767px media query. I apologize in advance if this has already been answered I couldn't find a question specific to this issue.
Here be a picture
Here be the Bootply
Here be my HTML
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand visible-xs" href="#"><img src="images/logobug.jpg" alt="" /></a>
<a class="navbar-brand visible-sm" href="#"><img src="images/logosm.jpg" alt=""></a>
<a class="navbar-brand visible-md" href="#"><img src="images/logomd.jpg" alt=""/></a>
<a class="navbar-brand visible-lg" href="#"><img src="images/logolg.jpg" alt=" Logo" /></a>
</a>
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right pull-right">
<li>HOME</li>
<li> EVENTS</li>
<li>CONTACT US</li>
<li>DIRECTIONS</li>
<li>SPONSERS</li>
<li>VENUES</li>
<li>ABOUT</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
Here be my CSS:
.navbar-right {
float: right;
margin-right: -25 px;
}
I think that's what you want , I removed pull right because navbar right do the same
a forked bootply

Bootstrap Header Text Ellipssing

I am looking to ellipse one of the header Text components when the viewport size is small to prevent the header from wrapping and becoming two lines.
Details here : https://jsfiddle.net/3L8ch5bo/7/ As you change the width of the viewport - you will see that the header goes into two lines.
I would like it to the ellipse in this way : https://jsfiddle.net/vsj896as/1/
The problem with ellipsing shown above is that it forces the header to be a fixed length. Is there a way to have it ellipsed based on size of the viewport (using max-width: calc(..) for example).
Please note that the "Left Text" on the header is non-standard bootstrap header component and is causing the complexity. It is needed and cannot be shortened and should be displayed in full.
Any help is greatly appreciated..
Here is the html code :
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="pull-left headComp">Left Text</div>
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#menu-items-collapse" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-brand ellipsed">How to Ellipse This Very Very Long Header Text</div>
</div>
<div class="collapse navbar-collapse" id="menu-items-collapse">
<ul class="nav navbar-nav">
<li class="active"><a target="_blank" href="url1">Home</a></li>
<li class="active"><a target="_blank" href="url2">Getting Started</a></li>
<li class="active"><a target="_blank" href="url3">Contact</a></li>
<li class="active"><a target="_blank" href="url4">Videos</a></li>
</ul>
</div>
</div>
</nav>
<div class="jumbotron container-fluid" style="text-align: center;">
<h1>Jumbo Message</h1>
</div>
</body>
Here is a quick way to complete what you want. The code attached and in the provided jsfiddle checks the viewport size on document.ready. If the size is less than 768px the text within the .navbar-brand will shorten.
The .resize event triggers the responsive part. If viewport is greater than 768px then the original text will show else if the viewport is less than the shortened text will show.
Hope that helps or at least points you in the right direction.
view jsfiddle here
$(function(){
var $startingView = $(window).width();
var $startingBrand = $('.navbar-brand');
if($startingView < 768) {
$startingBrand.text("How To...")
}
$(window).resize(function(){
var $viewportWidth = $(window).width();
var $brand = $(".navbar-brand");
var originalTitle = "How to Ellipse This Very Very Long Header Text";
var shortTitle = "How To...";
if($viewportWidth < 768) {
$brand.text(shortTitle);
}else{
$brand.text(originalTitle);
}
});
});
.headComp {
color: white;
margin-top: 16px;
width: 95px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="pull-left headComp">Left Text</div>
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#menu-items-collapse" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-brand">How to Ellipse This Very Very Long Header Text</div>
</div>
<div class="collapse navbar-collapse" id="menu-items-collapse">
<ul class="nav navbar-nav">
<li class="active"><a target="_blank" href="url1">Home</a></li>
<li class="active"><a target="_blank" href="url2">Getting Started</a></li>
<li class="active"><a target="_blank" href="url3">Contact</a></li>
<li class="active"><a target="_blank" href="url4">Videos</a></li>
</ul>
</div>
</div>
</nav>
<div class="jumbotron container-fluid" style="text-align: center;">
<h1>Jumbo Message</h1>
</div>
</body>

Bootstrap 3 navbar-toggle jumping on open and not opening at all on iPhone?

I have a Bootstrap 3 nav-pills menu which collapses on mobile devices however when you click the navbar-toggle menu, the menu opens and then immediately jumps up about 40-50 pixels?
It doesn't open at all on iPhone. :(
It's here:
http://www.portpatrick.me.uk/rickwood/hotel-rooms-portpatrick.php
Have double checked the CSS and I can't see, wood for the trees maybe, why it's doing this. Hope someone can help point out the obvious.
Thank you.
NJ
Menu..
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#rickwoodcollapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="rickwoodcollapse">
<ul class="nav nav-pills nav-justified">
<li role="presentation">Home</li>
<li role="presentation">Rooms</li>
<li role="presentation">Dining</li>
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false" id="attractions">Attractions <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li>Beaches & Coast</li>
<li>Gardens</li>
<li>Mull of Galloway</li>
</ul>
</li>
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false" id="activities">Activities <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li>Walking
<li>Walking in Portpatrick</li>
<li>Further Afield</li>
<li>Mull of Galloway Trail</li>
<li>Golf Courses</li>
<li>Cycling</li>
</ul>
</li>
<li role="presentation">Location</li>
<li role="presentation">News</li>
<li role="presentation">Contact</li>
</ul>
</div>
The CSS...
http://www.portpatrick.me.uk/rickwood/styles.css
I will endeavour to learn how to do a jsfiddle or github or whatever it's called. Thank you.
NJ
On your styles.css file (currently line 158) there is this line that is including a line-height.
.nav .open > a, .nav .open > a:focus, .nav .open > a:hover {
height: 60px;
background-color: #14214D;
}
Remove the height: 60px; and the menu doesn't jump anymore. I tested on an iPhone Emulator and it worked fine. I do not own an iPhone (gasp!) so I cannot test on an actual device.