This code works great for centering a Navigation Bar when it is just text. Both Horizontally and Vertically.
But when I try use an image for the Home (house image) - it offsets and is no longer centered in the middle vertically.
.navt {
list-style: none;
margin: 0;
padding: 0;
text-align: center;
background-color: black;
}
.navt li {
display: inline;
}
.navt a {
display: inline-block;
padding: 12px;
font-weight: normal;
color: white;
}
.navt li a:hover {
color: white;
background-color: pink;
}
<ul class="navt">
<li>
<a href="_index.cfm">
<img src="../images/hm_wht_tr30.png" height="20" border="0">
</a>
</li>
<li>This
</li>
<li>And
</li>
<li>That
</li>
<li>Here
</li>
<li>There
</li>
</ul>
If you add .navt img { vertical-align: middle; } you make the image align vertically in regards to the text.
.navt {
list-style: none;
margin: 0;
padding: 0;
text-align: center;
background-color: black;
}
.navt li {
display: inline;
}
.navt a {
display: inline-block;
padding: 0 12px;
font-weight: normal;
color: white;
height: 44px;
line-height: 44px;
}
.navt li a:hover {
color: white;
background-color: pink;
}
.navt img {
vertical-align: middle;
}
<ul class="navt">
<li>
<a href="_index.cfm">
<img src="../images/hm_wht_tr30.png" height="20" border="0">
</a>
</li>
<li>This
</li>
<li>And
</li>
<li>That
</li>
<li>Here
</li>
<li>There
</li>
</ul>
Related
I have left side side bar and right side content. I used flex box to separate them. It works fine. But when scrolling the content the side bar on the left side also scrolls along with the content. I wan to fix the side bar in the same position.
This is the Side bar html
<nav id="sidebar">
<ul class="list-unstyled components">
<li>
<a href="#usersMenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle"
>Users</a
>
<ul class="collapse list-unstyled" id="usersMenu">
<li>
<a routerLink="/admins">Admins</a>
</li>
<li>
<a routerLink="/sellers">Sellers</a>
</li>
<li>
<a routerLink="/customers">Customers</a>
</li>
<li>
<a routerLink="/delivery-boys">Delivery Boys</a>
</li>
</ul>
</li>
<li>
<a routerLink="/shop/categories">Categories</a>
</li>
<li>
<a routerLink="/shop/brands">Brands</a>
</li>
<li>
<a routerLink="/shop/products">Products</a>
</li>
<li>
<a routerLink="/shop/orders">Orders</a>
</li>
<li>
<a routerLink="/shop/deliveries">Deliveries</a>
</li>
</ul>
</nav>
This is the Side bar css
a,
a:hover,
a:focus {
color: inherit;
text-decoration: none;
transition: all 0.3s;
}
#sidebar {
min-width: 250px;
max-width: 250px;
background: #1d5ea8;
color: #fff;
transition: all 0.3s;
height: 100%;
margin-top: 56px;
}
#sidebar.active {
margin-left: -250px;
}
#sidebar ul.components {
padding: 20px 0;
border-bottom: 1px solid #1d5ea8;
}
#sidebar ul p {
color: #fff;
padding: 10px;
}
#sidebar ul li a {
padding: 10px;
font-size: 1.1em;
display: block;
}
#sidebar ul li a:hover {
color: #7386d5;
background: #fff;
}
#sidebar ul li.active > a,
a[aria-expanded='true'] {
color: #fff;
background: #1d5ea8;
}
a[data-toggle='collapse'] {
position: relative;
}
.dropdown-toggle::after {
display: block;
position: absolute;
top: 50%;
right: 20px;
transform: translateY(-50%);
}
ul ul a {
font-size: 0.9em !important;
padding-left: 30px !important;
background: #1d5ea8;
}
This is the app-component.html
<div class="wrapper">
<app-side-nav-bar *ngIf="checkLogin()"></app-side-nav-bar>
<app-horizontal-nav-bar *ngIf="checkLogin()"></app-horizontal-nav-bar>
<div id="content">
<router-outlet></router-outlet>
<app-footer *ngIf="checkLogin()"></app-footer>
</div>
</div>
This is the wrapper and content css
.wrapper {
display: flex;
width: 100%;
align-items: stretch;
}
#content {
width: 100%;
min-height: 100vh;
transition: all 0.3s;
}
Image 1
Image 2
You have to set #content to overflow-y: auto so that the scroll bar scrolls inside the content section and not the whole body.
I'm having an issue with my anchors not covering full width of the sidebar (for instance, 'Search'). I realise that this is because of padding, but I'm not sure how to overcome the issue whilst keeping the padded effect. I have tried to add a class (like, '.no-submenu) on the <li> and did .no-submenu a { margin: 0 -1.5rem; padding: 0 3rem; }, but it only partially solved the problem - my icons were off, they go all the way to the left:
I couldn't find the place online to upload SVG files (my icons are SVG), so I created a minimal example without icons. Icons are handled as background-image on the anchors.
<div class="sidebar">
<nav>
<ul class="menu">
<li id="search">
<a class="sidebar-icon" href="/search/notes/">Search</a>
</li>
<li id="dashboard">
<a class="sidebar-icon">Dashboard</a>
</li>
<li id="notebooks" class="has-submenu">
<div class="menu-item">
<span class="sidebar-icon">Notebooks</span>
<span class="arrow"></span>
</div>
<ul class="submenu">
<li id="new-notebook"><a class="sidebar-icon" href="/notebooks/create/">New Notebook</a></li>
<li id="view-notebooks"><a class="sidebar-icon" href="/notebooks/">View Notebooks</a></li>
</ul>
</li>
<li id="tags" class="has-submenu">
<div class="menu-item">
<span class="sidebar-icon">Tags</span>
<span class="arrow"></span>
</div>
<ul class="submenu">
<li id="view-tags"><a class="sidebar-icon" href="/tags/">View Tags</a></li>
</ul>
</li>
<li id="account" class="has-submenu">
<div class="menu-item">
<span class="sidebar-icon">Account</span>
<span class="arrow"></span>
</div>
<ul class="submenu">
<li id="settings"><a class="sidebar-icon" href="/accounts/settings/">Settings</a></li>
<li id="logout"><a class="sidebar-icon" href="/accounts/logout/">Logout</a></li>
</ul>
</li>
</ul>
</nav>
</div>
CSS:
#import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,600);
#font-face { font-family: "ionicons"; src: url("https://code.ionicframework.com/ionicons/2.0.1/fonts/ionicons.eot?v=2.0.1"); src: url("https://code.ionicframework.com/ionicons/2.0.1/fonts/ionicons.eot?v=2.0.1#iefix") format("embedded-opentype"), url("https://code.ionicframework.com/ionicons/2.0.1/fonts/ionicons.ttf?v=2.0.1") format("truetype"), url("https://code.ionicframework.com/ionicons/2.0.1/fonts/ionicons.woff?v=2.0.1") format("woff"), url("https://code.ionicframework.com/ionicons/2.0.1/fonts/ionicons.svg?v=2.0.1#Ionicons") format("svg"); font-weight: normal; font-style: normal; }
.sidebar {
width: 200px;
height: 100vh;
padding: 1rem 1.5rem;
background-color: #348ceb;
font-family: 'Source Sans Pro';
font-size: 14px;
position: fixed;
box-sizing: border-box;
}
ul {
list-style: none;
}
ul, li {
padding: 0;
margin: 0;
}
li {
padding: 0.5rem 0;
}
.submenu {
display: none;
overflow-y: hidden;
margin: 0 -1.5rem;
background-color: #3287e3;
}
.submenu li:first-child {
padding: 0.1rem 0 0 1.5rem;
}
.submenu li:last-child {
padding: 0 0 0.1rem 1.5rem;
}
.submenu li {
padding: 0.5rem 1.5rem;
}
.menu > li:hover {
background-color: #3287e3;
}
.menu > li {
position: relative;
color: #F9FAFC;
font-weight: bold;
margin: 0 -1.5rem;
padding: 0.5rem 1.5rem;
}
.menu > li > a {
display: block;
color: #F9FAFC;
text-decoration: none;
font-weight: bold;
}
.menu > li > a:hover {
color: white;
}
.submenu > li > a {
display: block;
color: #F9FAFC;
text-decoration: none;
}
.submenu > li > a:hover {
color: white;
}
.submenu > li {
font-weight: normal !important;
}
.arrow {
display: inline-block;
width: 10px;
transition: all 0.5s ease-in-out;
transform-origin: left center;
font-size: 0.5em;
position: absolute;
right: 0.75em;
}
.arrow:after {
content: '\f125';
font-family: 'ionicons';
color: white;
}
.rotated {
transform: rotate(90deg);
transition: transform 0.5s ease;
}
.menu-item {
display: flex;
align-items: center;
}
.menu-item > span:first-child {
flex: 1;
}
.sidebar-icon {
background-repeat: no-repeat;
padding-left: 25px;
}
JS (jQuery):
$(document).ready(function() {
$('.has-submenu').click(function() {
$(this).toggleClass('active');
$(this).children('.menu-item').children('.arrow').toggleClass('rotated');
if ($(this).hasClass('active')) {
$(this).children('.submenu').slideDown("slow");
}
else {
$(this).children('.submenu').slideUp("slow");
}
});
});
How can I overcome the issue?
Here is the demo.
#EDIT:
so, I want this:
but the menu item has to be fully clickable, i.e. you can click on any part of it and it brings you to, say, Search. To see the area it currently covers, right-click on the anchor or inspect the element.
I guess this is what you want:
<li style="padding: 0.5rem 0" id="search">
<a style="width: 100% !important; padding: none" class="sidebar-icon" href="/search/notes/">
<i style="padding-right: 10px">#</i>Search</a>
</li>
Wrestling with mutli-drop menu. (97% working) Select United States 1 menu, then pick Nevada menu item. There's a gray bar at the bottom. Same for US -> California. Gray bar below Los Angeles. I've played with margins and padding for a while. The :hover I was hoping would highlight the entire li portion. "Seems" to for all but most bottom menu item. (BTW: US -> California -> San Francisco -> SOMA. You'll see top left corner doesn't quite touch. That's maybe related.)
Any tips welcome. Thanks. Milton.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#nav_wrapper {
margin-top: 20px;
background: #b3c2bf; /* BG color across screen */
}
#nav_wrapper ul
{
list-style:none;
margin: 0;
padding: 0;
background: #b3c2bf; /* BG color across screen */
}
#nav_wrapper ul li
{
display: inline-block;
position:relative;
margin: 0;
padding: 0;
min-width: 150px;
max-width: 150px;
text-align: left;
}
#nav_wrapper ul li a
{
display: block;
/* white here gives the text white color */
color: white;
font-family: Arial, sans-serif;
font-weight: 200;
font-size: 16px;
text-decoration:none;
padding: 0;
margin 0;
}
#nav_wrapper ul ul
{
display:none;
position:absolute;
top: 100%; /* 100% of height of the li element */
padding: 0;
margin 0;
}
#nav_wrapper ul ul a
{
line-height: 120%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
#nav_wrapper ul ul ul {
top: 0;
left:100%;
}
p.menutextpadder { padding-left: 12px; padding-top: 4px; padding-bottom: 4px; }
#nav_wrapper ul li:hover > ul { display:block; }
#nav_wrapper ul li:hover { background-color: Blue; color: white; }
</style>
<body>
<nav id="nav_wrapper">
<ul class="topmenu">
<li><p class="menutextpadder">United States 1
<ul>
<li class="dir"><p class="menutextpadder">Arizona</p></li>
<li class="dir"><p class="menutextpadder">California
<ul>
<li><p class="menutextpadder">San Francisco
<ul>
<li><p class="menutextpadder">Pacific Heights</p></li>
<li><p class="menutextpadder">SOMA
<ul>
<li class="dir"><p class="menutextpadder">Spear Street</p></li>
<li class="dir"><p class="menutextpadder">Moscone Center</li>
</ul>
</li>
</ul>
</li>
<li><p class="menutextpadder">Los Angeles</p></li>
</ul>
<li class="dir"><p class="menutextpadder">Nevada</p></li>
</ul>
</li>
</ul>
</nav>
</body>
</html>
add the css rule below
ul{
font-size: 0;
}
Snippet below
#nav_wrapper {
margin-top: 20px;
background: #b3c2bf;
/* BG color across screen */
}
#nav_wrapper ul {
list-style: none;
margin: 0;
padding: 0;
background: #b3c2bf;
/* BG color across screen */
}
#nav_wrapper ul li {
display: inline-block;
position: relative;
margin: 0;
padding: 0;
min-width: 150px;
max-width: 150px;
text-align: left;
}
#nav_wrapper ul li a {
display: block;
/* white here gives the text white color */
color: white;
font-family: Arial, sans-serif;
font-weight: 200;
font-size: 16px;
text-decoration: none;
padding: 0;
margin 0;
}
#nav_wrapper ul ul {
display: none;
position: absolute;
top: 100%;
/* 100% of height of the li element */
padding: 0;
margin 0;
}
#nav_wrapper ul ul a {
line-height: 120%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
#nav_wrapper ul ul ul {
top: 0;
left: 100%;
}
p.menutextpadder {
padding-left: 12px;
padding-top: 4px;
padding-bottom: 4px;
}
#nav_wrapper ul li:hover > ul {
display: block;
}
#nav_wrapper ul li:hover {
background-color: Blue;
color: white;
}
#nav_wrapper .menutextpadder {} ul {
font-size: 0;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<body>
<nav id="nav_wrapper">
<ul class="topmenu">
<li>
<a href="#">
<p class="menutextpadder">United States 1</a>
<ul>
<li class="dir">
<a href="#">
<p class="menutextpadder">Arizona</p>
</a>
</li>
<li class="dir">
<a href="#">
<p class="menutextpadder">California</p>
</a>
<ul>
<li>
<a href="#">
<p class="menutextpadder">San Francisco</a>
<ul>
<li>
<a href="#">
<p class="menutextpadder">Pacific Heights</p>
</a>
</li>
<li>
<a href="#">
<p class="menutextpadder">SOMA</a>
<ul>
<li class="dir">
<a href="#">
<p class="menutextpadder">Spear Street</p>
</a>
</li>
<li class="dir">
<a href="#">
<p class="menutextpadder">Moscone Center</a>
</li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#">
<p class="menutextpadder">Los Angeles</p>
</a>
</li>
</ul>
<li class="dir">
<a href="#">
<p class="menutextpadder">Nevada</p>
</a>
</li>
</ul>
</li>
</ul>
</nav>
</body>
</html>
I've been stuck on this for a while. Please see image attached. I need to make a circle with a centered letter inside it and a line to text aligned centre to the circle. I need help with rest of the code.
.lettercircle {
font-family: Helvetica, sans-serif;
background-color: #009cda;
color: #fff;
padding: 5px 12px;
border-radius: 50%;
font-size: 28px;
}
#div {
width: 499px;
height: 166px;
}
<div id="div">
<ul>
<li> <span>A</span>
DREAMWEAVER
</li>
<li> <span>B</span>
PHOTOSHOP
</li>
</ul>
</div>
How about this:
.lettercircle {
font-family: Helvetica, sans-serif;
background-color: #333;
color: #fff;
padding: 5px 9px;
border-radius: 50%;
font-size: 12px;
display: table-cell;
vertical-align: middle;
}
.title {
padding-left: 10px;
display: table-cell;
vertical-align: middle;
}
#div {
width: 499px;
background: red;
height: 100%;
padding: 10px;
}
#div > ul {
padding: 0;
display: table-cell;
vertical-align: middle;
}
#div > ul > li {
list-style: none;
padding: 10px;
font-family: Helvetica, sans-serif;
text-transform: uppercase;
display: table;
}
<div id="div">
<ul>
<li>
<span class="lettercircle">A</span>
<span class="title">DREAMWEAVER</span>
</li>
<li>
<span class="lettercircle">B</span>
<span class="title">PHOTOSHOP</span>
</li>
</ul>
</div>
I think you just forgot to add your class to your spans.
.lettercircle {
font-family: Helvetica, sans-serif;
background-color: #009cda;
color: #fff;
padding: 5px 12px;
border-radius: 50%;
font-size: 28px;
}
#div {
width: 499px;
height: 166px;
}
<div id="div">
<ul>
<li> <span class="lettercircle">A</span>
DREAMWEAVER
</li>
<li> <span class="lettercircle">B</span>
PHOTOSHOP
</li>
</ul>
</div>
Faced a small problem in firefox: http://jsfiddle.net/3jmeS/, when clicking on the link active style fires on all element, but i need only on current. Is there a fix?
HTML:
<nav>
<div id="left-nav">
<ul>
<li class="active">
Dashboard
</li>
<li>
Dashboard
</li>
<li>
Dashboard
</li>
<li>
Dashboard
</li>
<li>
Dashboard
</li>
</ul>
</div>
</nav>
CSS:
#left-nav {
float: left;
font-family: Tahoma;
font-size: 13px;
height: 38px;
position: relative;
width: 600px;
min-width: 600px;
}
#left-nav li{
display: inline-block;
padding: 0 12px;
}
#left-nav li a {
color: #fff;
display: block;
line-height: 35px;
padding: 0 11px;
}
#left-nav li a:active{
position: relative;
top:1px;
}
#left-nav li.active a{
display: block;
}