Behold the following image of a .page-header I currently have:
As you can see, I'd like to have the page header in the center and buttons aligned to the left and right.
This works because both buttons have the same size. Now, if I increase the size of the left button, look what happens:
You see? The header isn't aligned to the center anymore, it's pushed to the right by the left button. Which is undesirable in my case. I would like to have the header centered, no matter what the size of the buttons are. If the buttons are too big, it would be even okay if they overlap the header.
Here is a code sample and a jsfiddle:
<div class="container">
<div class="page-header">
<a class="btn btn-primary pull-left" role="button" href="#">
<span class="glyphicon glyphicon-plus"></span>
</a>
<a class="btn btn-success pull-right" role="button" href="#">
<span class="glyphicon glyphicon-plus"></span>
</a>
<h3 class="text-center">Header</h3>
</div>
<div class="alert alert-danger" role="alert">No results</div>
</div>
You just need to use positions to make them consistent with the size.
.page-header .pull-left {position: absolute; left: 15px;}
.page-header .pull-right {position: absolute; right: 15px;}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
<div class="page-header">
<a class="btn btn-primary pull-left" role="button" href="#">
<span class="glyphicon glyphicon-plus"></span>
</a>
<a class="btn btn-success pull-right" role="button" href="#">
<span class="glyphicon glyphicon-plus"></span>
</a>
<h3 class="text-center">Header</h3>
</div>
<div class="page-header">
<a class="btn btn-primary pull-left" role="button" href="#">
<span class="glyphicon glyphicon-plus"></span> text pushes to right
</a>
<a class="btn btn-success pull-right" role="button" href="#">
<span class="glyphicon glyphicon-plus"></span>
</a>
<h3 class="text-center">Header</h3>
</div>
<div class="alert alert-danger" role="alert">No results</div>
</div>
Preview
This is one way, but obviously, this has issues with sizing. When the width is very less, there might be overlaps.
Related
I'm trying to edit bootstrap dropdown to my liking but having problem with setting the dropdown-menu width, need it to have 80% of body width which cannot use width: 80% because it's father ain't the body.
I've tried: width: 80%; width: 80vw;
second one works but is not responsive.
first one makes 80% relative to the father div (the one with btn-group class)
<div class="btn-group float-right pt-2 pr-5 ">
<button type="button" class="btn btn-outline-dark pl-4 py-2 dropdown-toggle city_btn" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<span class="ml-3"></span> <i class="fas ml-2 fa-map-marker-alt"></i><span class="cityactive">0</span>
</button>
<div class="dropdown-menu mydropdownoptions">
<span class="mydropdownitems">
<span class="dot"></span>
<a class="" href="#">1</a>
</span>
<span class="mydropdownitems">
<span class="dot"></span>
<a class="" href="#">2</a>
</span>
</div>
I am trying to have 3 icons in a navbar at positions left, right and center
The left and right ones are at correct position but the center link is not in the center but towards the left i.e. contiguous with the left glyphicon
Any idea how to center it?
<div class="navbar navbar-default navbar-fixed-bottom">
<div class="container">
<a href="/left_link" class="btn btn-info btn-lg pull-left hidelink">
<span class="glyphicon glyphicon-log-out"></span> Left
</a>
<a href="/center_link" class="btn btn-info btn-lg hidelink">
<span class="glyphicon glyphicon-log-out"></span> Center
</a>
<a href="/right_link" class="btn btn-info btn-lg pull-right hidelink">
<span class="glyphicon glyphicon-log-out"></span> Right
</a>
</div>
</div>
Add the text-center class to your container div:
<div class="container text-center">
Bootply example
I wrote the following HTML page :
<html lang="en">
<head>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Bootstrap theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="media">
<div class="media-body">
Some text, some text, some text, some text
</div>
<div class="media-right">
<a class="btn btn-default" href="#">
<span class="glyphicon glyphicon-pencil"></span>
Edit
</a>
<a class="btn btn-default" href="#">
<span class="glyphicon glyphicon-trash"></span>
Delete
</a>
</div>
</div>
</div>
</body>
</html>
The output is :
Is there a way to obtain the edit and delete button on the same line ? The media div is not mandatory. I just use it as a trick to put something on the left and something else on the right.
EDIT :
I changed line 14 according the answer :
The results is :
The buttons are now on the same line, but not on the same line as the text.
Something like this? If you are using bootstrap why not make use of the bootstrap grid? Here you can read more about bootstrap grid.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" >
<div class="container">
<div class="col-md-8 col-xs-8">
<span>Some text</span>
<span>Some text</span>
<span>Some text</span>
</div>
<div class="col-md-4 col-xs-4">
<a class="btn btn-default" href="#">
<span class="glyphicon glyphicon-pencil"></span> Edit
</a>
<a class="btn btn-default" href="#">
<span class="glyphicon glyphicon-trash"></span> Delete
</a>
</div>
</div>
Add display: inline-block;
<div class="media-right" style="display: inline-block;">
<a class="btn btn-default" href="#">
<span class="glyphicon glyphicon-pencil"></span>
Edit
</a>
<a class="btn btn-default" href="#">
<span class="glyphicon glyphicon-trash"></span>
Delete
</a>
</div>
I'm using Bootstrap 3 to make a button:
<a class="btn btn-primary btn-lg" href="#">
<span class="glyphicon glyphicon-shopping-cart" style="font-size: xx-large"></span>
Buy Now<br/>
<span class="small">Instant and secure</span><br/>
</a>
The glyph is, as I intend, large. But I want the two lines of text to both push to the left to make room for the glyph.
What I get currently is this:
What I'm aiming for is this:
How can I do this?
You could use pull-left in the icon, and change the btn to text-align:left:
CSS
.btn-lg {
text-align:left;
width:190px;
}
HTML
<a class="btn btn-primary btn-lg" href="#">
<span class="glyphicon glyphicon-shopping-cart pull-left" style="font-size:xx-large;margin:5px;"></span>
Buy Now<br>
<small>Instant and secure</small>
</a>
Demo: http://bootply.com/86858
I have two questions:
When an item is clicked, how can I show it and hide all other items
How to get a collapsible responsive sidebar like navbar
At first my jsFiddle Demo: http://jsfiddle.net/JpJqD/1/
I'm working to do collapsible sidebar menu.
As you can see in the demo; when i click articles, should be collapse(hide) others. Then if click to users, articles and other items that have sublevel should be collapse(hide). So always should be one opened menu.
I tried with collapse from Bootstrap document, but i couldnt with following codes:
$('#sidebar a').on('click', function () {
$(this).closest('div').find('.collapse').collapse('hide');
$(this).collapse('show');
});
I can do this with accordion but i dont wanna it cause of required panel class for all items.
BTW I want to make responsive sidebar like navbar menus for mobile and tablets? I used like in Bootstrap document but didnt work.
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
This is what i did , hope it fits your need :
<div class="panel panel-default">
<div class="panel-heading">
<h3>Navigation</h3>
</div>
<div id="sidebar" class="list-group">
<a href="#" class="list-group-item active">
<i class="icon-dashboard"></i> Dashboard
</a>
<a href="#users" class="list-group-item" data-parent="#sidebar">
<i class="icon-group"></i> Users
<span class="badge bg_danger">0</span>
</a>
<div id="users" class="list-group subitem collapse">
<a href="#" class="list-group-item">
<i class="icon-caret-right"></i> Users
<span class="badge bg_danger">0</span>
</a>
<a href="#" class="list-group-item">
<i class="icon-caret-right"></i> Create User
</a>
<a href="#" class="list-group-item">
<i class="icon-caret-right"></i> Create Group
</a>
</div>
<a href="#articles" class="list-group-item" data-parent="#sidebar">
<i class="icon-file-text"></i> Articles
<span class="badge bg_danger">0</span>
</a>
<div id="articles" class="list-group subitem collapse">
<a href="#" class="list-group-item bg_warning">
<i class="icon-caret-right"></i> Articles
<span class="badge bg_danger">0</span>
</a>
<a href="#" class="list-group-item">
<i class="icon-caret-right"></i> Create Article
</a>
</div>
</div>
</div>
And this is the corresponding js :
$('#sidebar > a').on('click', function (e) {
e.preventDefault();
if(!$(this).hasClass("active")){
var lastActive = $(this).closest("#sidebar").children(".active");
lastActive.removeClass("active");
lastActive.next('div').collapse('hide');
$(this).addClass("active");
$(this).next('div').collapse('show');
}
});
If you are looking for auto collapsible sidebar with animation this is the best according to me
Code
https://github.com/IronSummitMedia/startbootstrap-simple-sidebar
Demo
http://ironsummitmedia.github.io/startbootstrap-simple-sidebar