I'm trying to make a navigation menu with tabs and I use negative margin to group the elements and I want the active element to stay over the inactive elements. I used position: absolute but it had no effect. How can I do this?
.nav-item {
margin: -40px;
}
.nav-link {
color: #F2BF5E !important;
font-weight: 700 !important;
}
.nav-link.active {
color: white !important;
font-weight: 700 !important;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"/>
<div style="margin-top: 10%" class="row">
<div class="col">
<ul style="display: flex; justify-content: center;" class="nav nav-pills nav-pills-warning" role="tablist">
<li (click)="teste('entrar')" class="nav-item" style="width: 200px;">
<a class="nav-link active" data-toggle="tab" href="#link1" role="tablist">
Entrar
</a>
</li>
<li (click)="teste('cadastrar')" class="nav-item" style="width: 200px;">
<a data-toggle="tab" class="nav-link" href="#link2" role="tablist">
Cadastrar
</a>
</li>
</ul>
</div>
</div>
Currently, this is what I have:
enter image description here
If I am understanding you correctly, you want an image to be on top of the other, and vice versa, based off of whether it is 'active' or not.
In this case, I would imagine using the z-index is what you would want. It is a CSS property that provides depth/stacking based off of an integer value.
.nav-link.active {
z-index:1;
position:absolute;
color: white !important;
font-weight: 700 !important;
}
You might have to modify your code a bit to get it to how you want exactly; I'm just trying to provide a concept. You can just toggle the z-index value based off of whether it is 'active'
Related
I want the active element to be centered in parent element when there is enough other child elements after and before it. When the active element is first of the children, it should remain on the left. When the active element is last of the children, it should remain on the right.
<div class="container">
<div class="recent-dates">
<a class="date-text" href="/14159#2020-08-05">Wed 05</a>
<a class="date-text" href="/14159#2020-08-06">Thu 06</a>
<a class="date-text" href="/14159#2020-08-07">Fri 07</a>
<a class="date-text" href="/14159#2020-08-08">Sat 08</a>
<a class="date-text" href="/14159#2020-08-09">Sun 09</a>
<a class="date-text" href="/14159#2020-08-10">Mon 10</a>
<a class="date-text" href="/14159#2020-08-11">Tue 11</a>
<a class="date-text" href="/14159#2020-08-12">Tue 12</a>
<a class="date-text" href="/14159#2020-08-13">Thu 13</a>
<a class="date-text active" href="/14159#2020-08-14">Fri 14</a>
<a class="date-text" href="/14159#2020-08-15">Sat 15</a>
<a class="date-text" href="/14159#2020-08-16">Sun 16</a>
</div>
</div>
.container {
width: 500px
}
.recent-dates {
display: flex;
justify-content: center;
align-items: center;
background-color: #181717;
height: 60px;
overflow: hidden;
}
.date-text {
font-weight: normal;
font-size: 16px;
color: rgba(255, 255, 255, 0.4);
padding: 10px;
}
.date-text.active {
font-weight: bold;
color: #62E479;
}
Jsfiddle to illustrate the problem https://jsfiddle.net/koyz1arv/
I could do this by my self with JavaScript but may be there is some CSS-only solution?
EDIT (to make it clearer)
The active element should be be in the middle of the parent when there is enough elements before and after it. Spaces between child elements must stay the same.
I'm trying to create a dropdown menu that can be navigated by using the keyboard. I can get the first level to work by using the tab key, but have been unable to access the second level. Example can be found here https://codepen.io/jjfash/pen/oNgqEjx
The html:
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="featuredTopics">
<a class="btn btn-semiTransparent dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" tabindex="0">News Archive</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu">
<li class="dropdown-submenu pull-right dropdown-item"><a tabindex="0" href="#">2017</a>
<div class="dropdown-menu">
<ul>
<li class="dropdown-item"><a tabindex="0" href="#">Q1</a></li>
<li class="dropdown-item"><a tabindex="0" href="#">Q2</a></li>
<li class="dropdown-item"><a tabindex="0" href="#">Q3</a></li>
<li class="dropdown-item"><a tabindex="0" href="#">Q4</a></li>
</ul>
</div>
</li>
<li class="dropdown-submenu pull-right dropdown-item"><a tabindex="0" href="#">2018</a>
<div class="dropdown-menu">
<ul>
<li class="dropdown-item"><a tabindex="0" href="#">Q1</a></li>
<li class="dropdown-item"><a tabindex="0" href="#">Q2</a></li>
<li class="dropdown-item"><a tabindex="0" href="#">Q3</a></li>
<li class="dropdown-item"><a tabindex="0" href="#">Q4</a></li>
</ul>
</div>
</li>
<li class="dropdown-submenu pull-right dropdown-item"><a tabindex="0" href="#">2019</a>
<div class="dropdown-menu">
<ul>
<li class="dropdown-item"><a tabindex="0" href="#">Q1</a></li>
<li class="dropdown-item"><a tabindex="0" href="#">Q2</a></li>
<li class="dropdown-item"><a tabindex="0" href="#">Q3</a></li>
<li class="dropdown-item"><a tabindex="0" href="#">Q4</a></li>
</ul>
</div>
</li>
<li class="dropdown-submenu pull-right dropdown-item"><a tabindex="0" href="#">2020</a>
<div class="dropdown-menu">
<ul>
<li class="dropdown-item"><a tabindex="0" href="#">Q1</a></li>
<li class="dropdown-item"><a tabindex="0" href="#">Q2</a></li>
<li class="dropdown-item"><a tabindex="0" href="#">Q3</a></li>
<li class="dropdown-item"><a tabindex="0" href="#">Q4</a></li>
</ul>
</div>
</li>
</ul>
</div>
</body>
</html>
The CSS:
/* Buttons */
.btn {
border:none;
padding:12px;
color:#fff;
border-radius:0;
box-shadow: 0px 2px 5px rgba(0,0,0,0.2);
}
.btn:hover,
.btn:focus,
.btn:active {
text-decoration:underline;
color:#fff;
}
.btn:focus {
box-shadow: 0px 2px 5px rgba(0,0,0,0.2);
}
.btn-semiTransparent:hover,
.btn-semiTransparent:focus,
.btn-semiTransparent:active {
background:rgba(0,0,0,.1);
color:#1f2a44;
}
.btn-semiTransparent:not(:disabled):not(.disabled):active {
box-shadow: inset 0px 0px 5px #666 !important; /* makes it look like you've pressed the button */
}
/* Dropdown Menu */
.dropdown-item {
margin:0;
padding:0;
text-align:left;
}
.dropdown-submenu .dropdown-menu {
left:100%;
top:-3px;
border-radius:0;
}
.dropdown-submenu {
position: relative;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu:hover>a:after {
border-left-color: #fff;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
right:100%;
}
.dropdown-item:focus,
.dropdown-item:hover,
.dropdown-item:active {
background:#e6e6e6;
}
.dropdown-toggle {
line-height:120%; /* makes the height of the button similar to the regular buttons. having the caret as an ::after is making it taller */
}
.dropdown-toggle::after {
font-family: 'FontAwesome';/* essential to enable caret symbol*/
content:"\f054" !important;
color:#a84300;
border:none !important;
min-width:16px;
position:relative;
top:4px;
}
.dropdown-toggle[aria-expanded="true"]::after{
content:"\f078" !important;
color:initial;
}
li.dropdown-submenu>a:after {
font-family: 'FontAwesome';/* essential to enable caret symbol*/
content:"\f054";
color:#a84300;
position:relative;
left:8px;
display:inline-block;
width:15px;
}
li.dropdown-submenu:hover > a {
text-decoration:none;
}
li.dropdown-submenu:hover > a:after {
content:"\f078" !important;
color:initial;
}
.dropdownPadding {
padding:0px 150px 50px;
background:transparent;
border:none;
right:calc(100% - 150px) !important;
}
.dropdownPadding ul {
border:1px solid #ccc;
margin:0;
padding:10px 0;
background:#fff;
}
At minimum, I'd like it so the menu is fully navigable using the keyboard for ADA compliance. My best case scenario would be working using arrow keys (not just the tab key) to navigate. I tried adding tabindex="0" to each element hoping that would work, but no luck so far.
There are a few ways to handle this but a great place to start is this W3C article about Menus as this covers a lot of the basics of menu design, sub menus, expected controls etc.
It also has some examples of how to set up the JavaScript for the expected functionality so that will help you.
One of the key parts is intercepting the enter key to open sub-levels, either directly on the menu item or as a separate drop down arrow next to the main menu item.
I personally prefer having any top level items not being a link and instead being used as toggles to open sub menus but it depends on your site architecture.
The last thing you want is to make each sub-menu accessible via just tabbing. At that point if someone wants to reach "2020 Q4" they would have to tab past 15 items.
What you want instead is for each 'quarter picker' to open after pressing either enter or the right arrow key.
That way to get to "2020 Q4" is just 4 tabs, enter (or right arrow), 4 tabs so only 9 key presses (instead of 15).
One last thing to consider is that your menu needs to work without JavaScript or offer an alternative.
What I tend to do is have a <noscript> element with a link to the complete HTML sitemap show if they don't have JavaScript enabled and I have a more complex menu such as this.
I have this older site (Bootstrap 3.3.6) I put together for a client and have noticed that a button in the navbar is noted as active and I can't seem to clear it.
It visually looks like this :
Screenshot of issue with buttons
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav navbar-right">
<!-- Hidden li included to remove active class from about link when scrolled up past about section -->
<li class="hidden">
<a class="page-scroll" href="#page-top"></a>
</li>
<li>
<a class="page-scroll" href="#registration">REGISTRATION & PROGRAMS</a>
</li>
<li>
<a class="page-scroll" href="#coaches">OUR COACHES</a>
</li>
<li>
<a class="page-scroll" href="#contact">CONTACT</a>
</li>
<li>
<img src="img/FB-f-Logo50px.png" alt="Find us on Facebook!">
</li>
</ul>
</div>
When I view it under active circumstances the button for CONTACT displays as such :
<li class="active">
<a class="page-scroll" href="#contact">CONTACT</a>
</li>
CSS :
a {
font-family: "HypatiaSansPro-Regular";
color:#CC3333;}
.btn {
background-color: #CC3333;
outline-color: #CC3333;}
.btn:hover,
.btn:focus,
.btn.active {
background-color: #993333;
outline-color: #CC3333;}
.contact-section {
padding-top: 100px;
padding-top: 100px;
padding-bottom: 50px;
text-align: center;
background: #eee;}
If I change the order of the buttons I will get the same issue for any of the buttons that are last.
This is a one page bootstrap site, the page has 3 anchors. I can send private messages of the site in question if it helps.
It's a minor issue, but it is really bothering me that there is a conflict and I cannot clear it. Any feedback?
Bootstrap adds a class that highlights the active element:
.navbar-nav>.active>a{
color: #555;
background-color: #e7e7e7;
}
You can overwrite that selector by placing the same selector with the values you want in a css stylesheet loaded after bootstrap's css.
.navbar-nav>.active>a{
color: #777;
background-color: transparent;
}
Alternatively you can to remove the .active class somehow. But I think bootstrap adds that automatically. So that would probably be a hassle to do.
We have tabs working correctly using this HTML
<div class="col-lg-3 col-md-3 panel-container">
<ul class="nav nav-pills nav-stacked">
<li class="active"><a data-toggle="pill" href="#general" ng-class="{true: 'invalid-tab', false: ''}[form.editTemplateGeneralForm.$invalid]">#Labels.general</a></li>
<li><a data-toggle="pill" href="#startingValues" ng-class="{true: 'invalid-tab', false: ''}[form.editTemplateStartingValuesForm.$invalid]">#Labels.startingValues</a></li>
</ul>
</div>
The invalid-tab used to work fine, and when the tab was invalid it was shown in red. Now it's no longer working and we suspect it's the newest version of AngularJS that broke that functionality. We're using v1.3.13.
Do you know what should be adjusted in that syntax above to make it work again (that is used in many pages of our application).
Here is the invalid-tab from our site.css:
.widget .invalid-tab * {
background-color: #F9EAF3;
/*color: #F9EAF3;*/
color: #d43f3a;
}
.widget .invalid-tab:hover * {
background-color: #E06B6C;
color: #ffffff;
}
The correct way to define ng-class is as follows: ng-class="{classname: expresstion}"
You also need to remove the asterisk from the css-selector - as you are selecting any child element. But the .invalid-tab has no child elements.
Another solution would be to move the .invalid-tab class out to the parent li-element
angular.module('myApp', [])
.directive('testApp', function(){
return {
link: function(scope) {
scope.form = {
editTemplateStartingValuesForm: {$invalid: true},
editTemplateGeneralForm: {$invalid: false}
};
}
};
});
.widget .invalid-tab {
background-color: #F9EAF3;
/*color: #F9EAF3;*/
color: #d43f3a;
}
.widget .invalid-tab:hover {
background-color: #E06B6C;
color: #ffffff;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js"></script>
<div ng-app="myApp" class="widget" test-app>
<div class="col-lg-3 col-md-3 panel-container">
<ul class="nav nav-pills nav-stacked">
<li class="active">
<a data-toggle="pill" href="#general" ng-class="{'invalid-tab': form.editTemplateGeneralForm.$invalid}">#Labels.general</a>
</li>
<li>
<a data-toggle="pill" href="#startingValues" ng-class="{'invalid-tab': form.editTemplateStartingValuesForm.$invalid}">#Labels.startingValues</a>
</li>
</ul>
</div>
</div>
I'm designing a website using Twitter's Bootstrap, and I'm having difficulty with the responsive navbar. In bootstrap, the navbar allows a mobile user to click an icon to extend the navbar and display navigation links. I'm unable to find how to adjust the maximum height... when I try and use one of the drop down bars, the navbar doesn't change size accordingly, and the user is unable to see any of the links.
Thanks for any help you can provide.
-A
EDIT: here's the code that I'm using for the navbar (html) the css that I'm using is the standard bootstrap.css and bootrstrap-responsive.css:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="http://example.com">organization</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li>Home</li>
<li class="active">Contact</li>
<li>Now Playing</li>
<li class="dropdown">
Public Resources <b class="caret"></b>
<ul class="dropdown-menu">
<li>Observatory</li>
<li>Planetarium</li>
<li class="divider"></li>
<li class="nav-header">For Teachers and Schools</li>
<li>Programs</li>
<li>Host an Event</li>
<li>Educational Initiatives</li>
</ul>
</li>
<li class="dropdown">
Undergraduate Resources <b class="caret"></b>
<ul class="dropdown-menu">
<li>Observatory</li>
<li>Planetarium</li>
<li class="divider"></li>
<li class="nav-header">Physics</li>
<li>Physics Homepage</li>
<li>Physics and Astronomy</li>
</ul>
</li>
<li>Volunteer</li>
<li>FAQ</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
The default navbar html code is the following:
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#">Title</a>
<ul class="nav">
<li class="active">Home</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
And if you inspect the navbar element you will find that the inside div (navbar-inner) has the class:
.navbar-inner {
min-height: 40px;
}
You can remove this value and find that the navbar remains the same height, that's normal, because the height of the navbar is set to "auto". Therefore if you remove the min-height the height will depend of the link tags padding, inside the <ul></ul>, and the <a class="brand"></a> padding as well.
.navbar .nav > li > a {
float: none;
**padding: 10px 15px 10px;**
color: #777;
text-decoration: none;
text-shadow: 0 1px 0 #FFF;
}
.navbar .brand {
display: block;
float: left;
**padding: 10px 20px 10px;**
margin-left: -20px;
font-size: 20px;
font-weight: 200;
color: #777;
text-shadow: 0 1px 0 #FFF;
}
If you change it, you will find that the height of the "navbar" parent will automatically change. You can also maintain the min-height property and just change its value, adjusting the padding of the elements I've mentioned above.
For the responsive part, you can edit all the styles in the bootstrap-responsive.css, inside the specific media query for the resolution that you want to edit.
EDIT: Just saw your HTML, check the padding of your link tags inside the navbar, reduce it, change the .navbar-inner min-height too, and play with the values.
Ok, the way I fixed the first part (having a header that didn't resize when I wanted to) was by changing the min width value in the bootstrap-responsive.css like so:
#media (min-width: 1200px) {
.nav-collapse.collapse {
height: auto !important;
overflow: visible !important;
}
}
where 1200px was changed to 1200 from 980. Tricky tricky... for the record, it's on line 1104.