boostrap sidebar collapse in icon when opens first time - html

I have 2 collapse links, test3 and test
test3 is already collapsed so used in
test is not collapsed has no in
the problem:
this just happen when opens first time I don't know why, the arrow is already down in the link test should not, but after few clicks the arrow backs to work normal.
so test link should be arrow to the left because is not collapsed yet, right now if you see is already to arrow down, someone knows why?
jsfiddle: http://jsfiddle.net/Wc4xt/4399/
HTML:
<div class="sidebar">
<div class="sidebar-wrapper">
<ul class="sidebar-nav">
<li>
<i class="pull-left fa-lg fa fa-book" aria-hidden="true"></i>
<div class="collapse-link">
<a data-toggle="collapse" data-target="#collapseExample1" aria-expanded="false" aria-controls="collapseExample1">test3
</a>
</div>
<div class="collapse in collapse-styled" id="collapseExample1">
<i class="pull-left fa fa-lg fa-list" aria-hidden="true"></i>
test List
<i class="pull-left fa fa-lg fa-list" aria-hidden="true"></i>
Create
</div>
</li>
<li>
<i class="pull-left fa fa-lg fa-book" aria-hidden="true"></i>
<div class="collapse-link">
<a data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">test
</a>
</div>
<div class="collapse collapse-styled" id="collapseExample">
<i class="pull-left fa fa-lg fa-list" aria-hidden="true"></i>
link List
<i class="pull-left fa fa-lg fa-list" aria-hidden="true"></i>
test
</div>
</li>
</ul>
</div>
</div>
CSS:
.sidebar-wrapper {
height: 100%;
overflow-y: auto;
background: #2f3f4d;
-webkit-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.sidebar-nav li {
text-indent: 22px;
line-height: 60px;
border-bottom: 1px solid #455b6f;
}
.sidebar-nav li a {
display: block;
height: 65px;
}
.collapse-link a:after {
font-family: 'Glyphicons Halflings';
content: "\e114";
color: $white;
background-color: black;
}
.collapse-link a.collapsed:after {
content: "\e080";
background-color: red;
}
.collapse-link a.collapsed {
color: white;
}
a {
text-decoration:none;
}
ul li {
list-style:none;
}

As you can see in your CSS, your arrow depends on collapsed class (not in).
You should add collapsed class to you link:
<a class="collapsed" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">test</a>
JSFIDDLE

insert : class="collapsed" in your <a>

Related

How to add top navigation to html that have side navigation

Try to add top navigation that has side navigation already. But how I put the top navigation to the main page seems wrong. How to make side nav and top nav be in the same position. The image I put below. Top nav at the above. and the side nav goes below the top nav. I want to make it looks parallel. How to do it in the correct way?
In this case, my topnav height is 60 px. Is there any better way than just add margin-top -60px to my sidebar?
TopNavigation.jsp
<div class="top_nav">
<div class="nav_menu">
<nav class="" role="navigation">
<ul class="nav navbar-nav navbar-right">
<li class="">
<a href="javascript:;"
class="user-profile dropdown-toggle" data-toggle="dropdown"
aria-expanded="false">
<img
src="
<c:url value="/resources/images/user.png"/>
"><%=session.getAttribute("usrname")%>
<span class=" fa fa-angle-down"></span>
</a>
</ul>
</nav>
</div>
</div>
SideNavigation.jsp
<nav id="sidebar">
<div class="custom-menu">
<button type="button" id="sidebarCollapse" class="btn btn-primary">
<i class="fa fa-bars"></i> <span class="sr-only">Toggle Menu</span>
</button>
</div>
<div class="p-4">
<h1>
<img src=""/>">
</h1>
<ul class="list-unstyled components scrollBarNav mb-5">
<li class="active"><a href="#"><span class="fa fa-camera "></span>
</a>
</li>
<li><span class="fa fa-code-fork"></span>
</li>
<li><a href="#"><span class=""><i class="fa fa-user-plus" aria-hidden="true"></i></span>
</a>
</li>
</ul>
<div class="footer">
<span class="fa fa-sign-out"></span>
</div>
</div>
</nav>
Main Page
<body>
<jsp:include page='TopNavigation.jsp'></jsp:include>
<div class="wrapper d-flex align-items-stretch">
<jsp:include page='SideNavigationManagement.jsp'></jsp:include>
<div id="content" class="p-4 p-md-5 pt-5">
<h2 class="mb-4">Sidebar #05</h2>
<p>Lorem ipsum </p>
</div>
</div>
</body>
CSS
#sidebar {
min-width: 270px;
max-width: 270px;
background: #3445b4;
color: #fff;
-webkit-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
position: fixed;
height:100%;
}
#content {
width: 100%;
padding: 0;
min-height: 100vh;
-webkit-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
margin-left:270px;
}
//TopCss .main_container .top_nav {
display: block;
margin-left: 270px;
}
.nav_menu {
float: left;
background: #EDEDED;
border-bottom: 1px solid #D9DEE4;
margin-bottom: 10px;
width: 100%;
position: relative;
}
.navbar-right {
margin-right: 0;
}
.top_nav .navbar-right {
margin: 0;
width: 70%;
float: right;
}
.top_nav .navbar-right li {
display: inline-block;
float: right;
position: static;
}
Result Image :

How to keep a div stayed in same position css

Well, I have a category panel picture and I am trying to create it into HTML.
I have tried this code but I hover over a category a sub_category panel appears but every panel seems to have margin at top. I want to have every panel same position just like in picture.
I tried top: 0 but it didn't have any affect. Can anyone help?
.category_nav {
height: 40px;
margin-top: 28px;
}
.category_nav_ul {
list-style-type: none;
padding: 0;
}
.category_nav_ul>li {
display: inline-block;
}
#category_nav_ul_category {
width: 380px;
cursor: pointer;
}
#category_nav_div {
margin-top: 5px;
width: 380px;
position: absolute;
background-color: white;
padding-bottom: 10px;
}
.category {
padding-top: 6px;
padding-bottom: 6px;
margin-bottom: 1px;
margin-left: 0 !important;
border-radius: 0 !important;
border: 0 !important;
}
.category:hover {
border: 2px;
background: linear-gradient(to right, red 0px, #E5002B 3px, transparent 3px);
background-color: white;
border-top: 1px solid grey !important;
border-bottom: 1px solid grey !important;
}
.fa-chevron-right {
font-weight: 100px !important;
font-size: 10px !important;
}
.left-menu-ul {
list-style: none;
}
.left-mega-menu {
background: #fff none repeat scroll 0 0;
left: 90%;
position: absolute;
top: 0;
width: 470px;
opacity: 0;
visibility: hidden;
z-index: 2345;
transition: .3s;
padding-top: 20px;
padding-bottom: 20px;
padding-left: 20px;
padding-right: 60px;
}
.left-menu ul li:hover>.left-mega-menu {
opacity: 1;
visibility: visible;
left: 100%;
}
.sub_categories {
border-radius: 0 !important;
padding-top: 6px;
padding-bottom: 6px;
border-left: 2px solid #E5002B;
border-top: 0px !important;
border-right: 0px !important;
width: 200px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div id="category_nav_div" class="light-border">
<div class="left-menu collapse in" id="left-menu">
<nav>
<ul class="left-menu-ul list-group">
<li class="category list-group-item">
<i class="fa fa-camera fa-fw"></i>
<a href="/mystore/category/Camera">Camera
<i aria-hidden="true" class="fa fa-angle-right pull-right"></i>
</a>
<div class="left-mega-menu light-border">
<div class="row">
<ul class="list-group">
<div class="col-lg-6">
<a href="/mystorecategory/Camera/sub_cat/">
<li class="list-group-item sub_categories">Camera</li>
</a>
</div>
</ul>
</div>
</div>
</li>
<li class="category list-group-item">
<i class="fa fa-angle-right fa-fw"></i>
<a href="/mystore/category/Clothes">Clothes
<i aria-hidden="true" class="fa fa-angle-right pull-right"></i>
</a>
<div class="left-mega-menu light-border">
<div class="row">
<ul class="list-group">
<div class="col-lg-6">
<a href="/mystorecategory/Clothes/sub_cat/">
<li class="list-group-item sub_categories">Clothes</li>
</a>
</div>
</ul>
</div>
</div>
</li>
<li class="category list-group-item">
<i class="fa fa-mobile fa-fw"></i>
<a href="/mystore/category/Mobiles">Mobiles
<i aria-hidden="true" class="fa fa-angle-right pull-right"></i>
</a>
<div class="left-mega-menu light-border">
<div class="row">
<ul class="list-group">
<div class="col-lg-6">
<a href="/mystorecategory/Mobiles/sub_cat/">
<li class="list-group-item sub_categories">Mobiles</li>
</a>
</div>
<div class="col-lg-6">
<a href="/mystorecategory/Tablet/sub_cat/">
<li class="list-group-item sub_categories">Tablet</li>
</a>
</div>
</ul>
</div>
</div>
</li>
<li class="category list-group-item">
<i class="fa fa-angle-right fa-fw"></i>
<a href="/mystore/category/Graphics Cards">Graphics Cards
<i aria-hidden="true" class="fa fa-angle-right pull-right"></i>
</a>
<div class="left-mega-menu light-border">
<div class="row">
<ul class="list-group">
<div class="col-lg-6">
<a href="/mystorecategory/Graphics Cards/sub_cat/">
<li class="list-group-item sub_categories">Graphics Cards</li>
</a>
</div>
<div class="col-lg-6">
<a href="/mystorecategory/Computer/sub_cat/">
<li class="list-group-item sub_categories">Computer</li>
</a>
</div>
<div class="col-lg-6">
<a href="/mystorecategory/DVDs/sub_cat/">
<li class="list-group-item sub_categories">DVDs</li>
</a>
</div>
<div class="col-lg-6">
<a href="/mystorecategory/Laptop/sub_cat/">
<li class="list-group-item sub_categories">Laptop</li>
</a>
</div>
</ul>
</div>
</div>
</li>
<li class="category list-group-item">
<i class="fa fa-television fa-fw"></i>
<a href="/mystore/category/Television">Television
<i aria-hidden="true" class="fa fa-angle-right pull-right"></i>
</a>
<div class="left-mega-menu light-border">
<div class="row">
<ul class="list-group">
<div class="col-lg-6">
<a href="/mystorecategory/Television/sub_cat/">
<li class="list-group-item sub_categories">Television</li>
</a>
</div>
</ul>
</div>
</div>
</li>
</ul>
</nav>
</div>
</div>
Remove position relative from category li and apply it to its parent
.left-menu-ul {
list-style: none;
position: relative;
}
fiddle

Tiny bootstrap NavBar on mobile

So the site I am working on will be a mobile only version of a main site. So I naturally decided to go with bootstrap. We forced the navbar to always be collapsed with some css, and when viewed from within a desktop browser and shrunk the window size, the navbar looks fine. Nice size compared to the body text. However, when we uploaded it to the server to test on actual mobile devices, the body text is a good readable size, but the navbar font and icons are tiny and are definitely not suitable for mobile users. I'm not to sure about what code to show, so I'll include the custom css file that deals with navbar colour change and the always collapsed look.
.navbar-custom {
background-color:#6BC1C2;
color:#ffffff;
border-radius:0;
}
.navbar-custom .navbar-nav > li > a {
color:#fff;
}
.navbar-custom .navbar-nav > li > a:hover{
color: #378182;
background-color: #76CBCC;
}
.navbar-custom .navbar-nav > .active > a, .navbar-nav > .active > a:hover, .navbar-nav > .active > a:focus {
color: #378182;
background-color:#84E3E4;
}
.navbar-custom .navbar-brand {
color:#eeeeee;
}
.navbar-custom .navbar-toggle:hover,
.navbar-custom .navbar-toggle:focus {
background-color: #1FACAD;
}
.navbar-custom .navbar-toggle .icon-bar {
background-color: #888;
}
.nav-icons{
padding-right: 25px;
}
.btn-Link{
color: white;
}
a{
text-decoration: none;
}
.navbar-header {
float: none;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin: 7.5px -15px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.navbar-collapse.collapse.in {display: block !important; }
HTML for Navbar
<body>
<!--Navigation Bar starts here!-->
<nav class="nav navbar-custom">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navigationBar" aria-expanded="false" aria-controls="navbar"> <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" href="index.html">Website</a>
<div class="navbar-left nav-icons">
<ul class="navbar-nav" style="list-style-type: none;">
<li> <span class="fa-stack fa-lg">
<a href="tel: 1-705-503-3455" class="btn-Link">
<i class="fa fa-square-o fa-stack-2x"></i>
<i class="fa fa-phone fa-stack-1x"></i>
</a>
</span>
<span class="fa-stack fa-lg">
<a href="https://maps.google.com/maps?q=80 Bradford Street Barrie Ontario" class="btn-Link">
<i class="fa fa-square-o fa-stack-2x"></i>
<i class="fa fa-map-marker fa-stack-1x"></i>
</a>
</span>
</li>
</ul>
</div>
</div>
<div class="collapse navbar-collapse" id="navigationBar">
<ul class="nav navbar-nav navbar-left">
<li class="active">Home<span class="sr-only">(current)</span> <i class="fa fa-home fa-lg"></i>
</li>
<li>About Us <i class="fa fa-info-circle fa-lg"></i>
</li>
<li>Services <i class="fa fa-wrench fa-lg"></i>
</li>
<li>Contact <i class="fa fa-envelope fa-lg"></i>
</li>
<li>Addiction & Trauma Center <i class="fa fa-commenting fa-lg"></i>
</li>
<li>Resources <i class="fa fa-archive fa-lg"></i>
</li>
</ul>
</div>
</div>
</nav>
<!--Navigation Bar Ends here!-->
</body>
JSFiddle
Image of the navbar on Mobile, ignore the Icons. They were fine until we started playing around with it.

Showing submenu for an icon button

I try to create a navigation menu. Some of the items should get a submenu which will be shown by clicking/hovering the arrow-icon.
But I got some problems to position the submenu correctly
JSFiddle: http://jsfiddle.net/g651mwdu/
<nav>
<div class="nav-button-group"> <span class="nav-button-group-title">Title</span>
<div class="nav-button-container"> <span class='fa fa-plus button-icon'></span>
<span class="button-text">Add</span>
<div class="button-arrow-down"></div>
<div class="submenu">Show some more elements</div>
</div>
<div class="nav-button-container"> <span class='fa fa-cog button-icon'></span>
<span class="button-text">Change</span>
<div class="button-arrow-down"></div>
</div>
<div class="nav-button-container"> <span class='fa fa-link button-icon'></span>
<span class="button-text">Link</span>
</div>
<div class="nav-button-container"> <span class='fa fa-comment-o button-icon'></span>
<span class="button-text">Tooltip</span>
</div>
<div class="nav-button-container"> <span class='fa fa-trash-o button-icon'></span>
<span class="button-text">Remove</span>
</div>
</div>
</nav>
CSS
.nav-button-container {
display: inline-block;
width: 2em;
height: 2.5em;
padding: .25em;
text-align: center;
color: #555;
}
.button-text {
display: block;
font-size: .5em;
margin: .5em 0;
}
.button-icon {
vertical-align: middle;
font-size: 1.3em;
}
.button-arrow-down {
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #B4B4B4;
margin: 0 auto;
}
.line-separator {
display: inline-block;
width: 1em;
}
nav {
background-color: #f2f2f2;
padding: .3em 0;
border-radius: 7px;
}
.nav-button-group {
display: inline-block;
background-color: #fafafa;
padding: .3em;
border-radius: 5px;
}
.nav-button-group-title {
display: block;
font-weight: bold;
font-size: .7em;
color: #555;
padding: 0 .5em;
background-color: #F2F2F2;
border-radius: 4px;
}
Is this what you are trying to achieve (navigation with font awesome icons aligned to the drop-down text)?
You're using buttons to build your menu which isn't necessary (or recommended). Use ul unordered lists and list items li to build your nav. Then inserting icons is pretty straight forward.
<li><i class="fa fa-pencil-square-o fa-fw"></i> Drafts
Example Snippet
.navbar {
border-radius: 0px;
}
.dropdown-submenu {
position: relative;
}
.dropdown-submenu > .dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
-webkit-border-radius: 0px;
-moz-border-radius: 0px 6px 6px 6px;
border-radius: 0px;
}
.dropdown-submenu:hover > .dropdown-menu {
display: block;
}
.dropdown-submenu > a:after {
display: block;
content: " ";
float: right;
width: 0px;
height: 0px;
border-color: transparent;
border-style: solid;
border-width: 5px 0px 5px 5px;
border-left-color: #cccccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover > a:after {
border-left-color: #ffffff;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left > .dropdown-menu {
left: -100%;
margin-left: 10px;
-webkit-border-radius: 6px 0px 6px 6px;
-moz-border-radius: 6px 0px 6px 6px;
border-radius: 6px 0px 6px 6px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav role="navigation" class="navbar navbar-inverse">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle"> <span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button> Brand
</div>
<!-- Collection of nav links, forms, and other content for toggling -->
<div id="navbarCollapse" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home
</li>
<li>Profile
</li>
<li class="dropdown"> <a data-toggle="dropdown" class="dropdown-toggle" href="#">Messages <b class="caret"></b></a>
<ul role="menu" class="dropdown-menu">
<li><i class="fa fa-envelope-o fa-fw"></i> Inbox
</li>
<li><i class="fa fa-pencil-square-o fa-fw"></i> Drafts
</li>
<li><i class="fa fa-paper-plane-o fa-fw"></i> Sent Items
</li>
<li class="divider"></li>
<li><i class="fa fa-trash-o fa-fw"></i> Trash
</li>
</ul>
</li>
<li>Hello
</li>
<li class="dropdown"> <a data-toggle="dropdown" class="dropdown-toggle" href="#">Things <b class="caret"></b></a>
<ul role="menu" class="dropdown-menu">
<li><i class="fa fa-envelope-o fa-fw"></i> Inbox
</li>
<li><i class="fa fa-pencil-square-o fa-fw"></i> Drafts
</li>
<li><i class="fa fa-paper-plane-o fa-fw"></i> Sent Items
</li>
<li class="divider"></li>
<li><i class="fa fa-trash-o fa-fw"></i> Trash
<li class="dropdown-submenu"> <a tabindex="-1" href="#"><i class="fa fa-hand-o-right fa-fw"></i> Profile</a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#"><i class="fa fa-calendar-o fa-fw"></i> Account</a>
</li>
<li><a tabindex="-1" href="#"><i class="fa fa-folder-open-o fa-fw"></i> Users</a>
</li>
<li><a tabindex="-1" href="#"><i class="fa fa-file-o fa-fw"></i> Login</a>
</li>
</ul>
</li>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Login
</li>
</ul>
</div>
</nav>

Slightly off-centered buttons

I need these buttons to be horizontally centered within their container..as you can see, they are floating to the left. That is because I have a float: left; attribute on them.
However, when I remove the float: left; attribute and apply text-align: center; to the container, this is what happens...
Almost centered, but not quite. What's the deal? Thanks! :)
The container's CSS:
#navbar {
background: #303030;
width: 100%;
box-sizing: border-box;
text-align: center;
}
Each button's CSS:
a.button {
width: 16.3%;
background: #4d4d4d;
height: 50px;
display: inline-block;
text-decoration: none;
color: #fff;
text-align: center;
max-width: 250px;
padding-top: 12px;
box-sizing: border-box;
font-size: 145%;
transition-property: background, z-index, font-size, color;
transition-duration: 0.35s;
}
The relevant HTML
<div id ="navbar">
<i class="fa fa-home"></i> HOME
<i class="fa fa-question"></i> Q&A
<i class="fa fa-comment"></i> FORUMS
<i class="fa fa-phone"></i> CONTACT
<i class="fa fa-life-ring"></i> SUPPORT
<i class="fa fa-info-circle"></i> ABOUT
</div>
</div>
The misalignment is probably due to a space character between each link. This is a common problem when using display: inline-block;. You can remove with a couple of methods.
Method 1:
Set a negative letter-spacing. This depends on font-family and font-size, so try a couple of different values.
#navbar {
letter-spacing: -4px;
}
a.button {
letter-spacing: normal;
}
Method 2:
Remove any space/linebreaks between the links. This will of course make the code pretty unreadable.
<i class="fa fa-home"></i> HOME<i class="fa fa-question"></i> Q&A<i class="fa fa-comment"></i> FORUMS<i class="fa fa-phone"></i> CONTACT<i class="fa fa-life-ring"></i> SUPPORT<i class="fa fa-info-circle"></i> ABOUT
Method 3:
Ommit the closing </a> for all links but the last. This is still valid HTML. An <a> element will automatically close when it's followed by another <a>.
<a href="https://www.answers.legal" class="button"><i class="fa fa-home"></i> HOME
<a href="https://www.answers.legal/questions" class="button"><i class="fa fa-question"></i> Q&A
<a href="https://www.answers.legal/forums" class="button"><i class="fa fa-comment"></i> FORUMS
<a href="https://www.answers.legal/contact" class="button"><i class="fa fa-phone"></i> CONTACT
<a href="https://www.answers.legal/support" class="button"><i class="fa fa-life-ring"></i> SUPPORT
<i class="fa fa-info-circle"></i> ABOUT