how to fix my position sticky with navigation bar problem - html

I'm building a responsive website with a header above the navigation bar and my goal is then of course to have the navigation bar stick to the top when scrolling down.
I'm new to HTML and CSS, so I'm not really sure if the order in what should be in the top of the CSS class code for the navbar should be. But just in case I've put position:sticky; at the top and then the top:0; value second to that. I've also tried to put it directly in the head. But to no avail. I'll include the code for you to see.
.navbar {
position: sticky;
top: 0;
display: flex;
flex-direction: row;
justify-content: space-evenly;
align-items: center;
background-color: black;
height: 74px;
overflow: hidden;
margin: 0px 1px 0px 1px;
border: 1px;
border-radius: 4px;
border-style: solid;
border-color: #A6A6A6;
}
<nav>
<div class="navbar">
<a href="#">
<button class="btn text1">Text 1</button>
</a>
<a href="#">
<button class="btn text2">Text 2</button>
</a>
<a href="#">
<button class="btn text3">Text 3</button>
</a>
<a href="#">
<button class="btn text4">Text 4</button>
</a>
<a href="#">
<button class="btn text5">Text 5</button>
</a>
</div>
</nav>

Add position:sticky to the parent.
(Also make sure you always check for browser compatibilty)
nav {
position: sticky;
top: 0;
}
.navbar {
display: flex;
flex-direction: row;
justify-content: space-evenly;
align-items: center;
background-color: black;
height: 74px;
overflow: hidden;
margin: 0px 1px 0px 1px;
border: 1px;
border-radius: 4px;
border-style: solid;
border-color:#A6A6A6;
}
Working fiddle:
https://jsfiddle.net/9fvwp7x1/5/

Make the navbar class fixed. It will stick it there.
Either way it wont stick. Example;
.navbar{
position: fixed;
top: 0;
}

Related

How do i align multiple elements in mat-card-content angular css html

i am trying to right-align and center the button vertically within the mat-card-content, but it is not working properly and if i try to add more divs or change my html it looks even worse or does not align properly. My title should be left-aligned and also vertically centered as it is right now.
(I used ugly background-colors to understand what it does whenever I change something)
<div>
<div *ngFor ="let recipe of cookbook">
<mat-card class="recipe">
<mat-card-content class="title"> {{recipe.title}}
<button mat-icon-button [matMenuTriggerFor]="menu" class="more">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu">
<button mat-menu-item>
<span>Edit</span>
</button>
<button mat-menu-item>
<span>Delete</span>
</button>
</mat-menu>
</mat-card-content>
</mat-card>
</div>
</div>
.recipe {
width : 400px;
height: fit-content;
background-color: #d4d4d4;
padding: 15px;
margin: 15px;
border-radius:4px;
}
.more {
right:-20%;
background-color: red;
}
.title{
background-color: green;
text-align: left;
}
The only thing I tried that somewhat worked how i wanted was using right: for my .more button in my css but it is not consistent depending on how long my title is or at some point exceeds the mat-card
Any other ideas on how I could fix this?
You can do what you are trying to do with flex
Try something like this
I also made a quick Stackblitz too https://stackblitz.com/edit/angular-ivy-mvecpg
You might want to have a read of the custom theming https://material.angular.io/guide/theming-your-components
.recipe {
display: flex;
flex-direction: column;
width: 400px;
}
.recipe__card {
background-color: #d4d4d4;
border-radius: 4px;
box-shadow: 0 4px 2px -2px #ccc;
padding: 8px;
margin-bottom: 12px;
}
.recipe__card-content {
padding-bottom: 0 !important;
padding-top: 0 !important;
display: flex;
justify-content: space-between;
align-items: center;
background-color: green;
padding: 4px 8px;
}
.recipe__title {
font-weight: bold;
}
.recipe__more-btn {
background: red;
border: none;
margin: 8px;
}
<section class="recipe" *ngFor="let recipe of cookbook">
<mat-card class="recipe__card">
<mat-card-content class="recipe__card-content">
<span class="recipe__title">{{recipe.title}}</span>
<button mat-icon-button [matMenuTriggerFor]="menu" class="recipe__more-btn">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu">
<button mat-menu-item>
<span>Edit</span>
</button>
<button mat-menu-item>
<span>Delete</span>
</button>
</mat-menu>
</mat-card-content>
</mat-card>
</section>

Can't move my div using float-right inside container

I have a container where i store 2 div's. ".logo" and ".navbar-list" how can I move my ".navbar-list" to the right edge of container.
Previously everything worked but when I switched bootstrap to version 4.3.1 my div's overlapped .I've tried float:right but is not working.
container {
font-family: sans-serif;
height: 100%;
margin-left: auto;
margin-right: auto;
float: none;
padding: 0;
}
.logo {
width: 380px;
margin-right: 0;
position: absolute;
height: 100%;
margin-left: 10px;
}
.navbar-list {
color: white;
width: 300px;
height: 100%;
}
<div class="container">
<div class="logo">
<a class="navbar-brand" href="#"><img src="img/640px-HSV-Logo.png" /></a>
<h1>WITAJ W <span>DOMU!</span></h1>
</div>
<div class="navbar-list ">
<ul>
<li>
<span class=" glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> Sklep
</li>
</ul>
<ul>
<li> <button type="button" class="btn btn-danger btn-md ">
<span class="glyphicon glyphicon-user" aria-hidden="true"></span> Zaloguj się
</button></li>
</ul>
</div>
</div>
There are lots of methods of achieving your desired result! In my opinion, Flexbox would be your best option. You should add display: flex to your .container. You can add the flex to the .logo container as well, if you want the logo and h1 to sit side by side.
You should also avoid using float, as this often makes HTML behave unexpectedly. You can replace this with justify-content: space-between.
I've amended your example above to incorporate my amends:
.container {
font-family: sans-serif;
padding: 0;
height: 80px;
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
width: 380px;
/*margin-right: 0; */
/*position: absolute; */
height: 100%;
margin-left: 10px;
display: flex;
align-items: center;
}
.navbar-list {
color: white;
width: 300px;
height: 100%;
}
<div class="container">
<div class="logo">
<a class="navbar-brand" href="#"><img src="img/640px-HSV-Logo.png" /></a>
<h1>WITAJ W <span>DOMU!</span></h1>
</div>
<div class="navbar-list ">
<ul>
<li>
<span class=" glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> Sklep
</li>
</ul>
<ul>
<li> <button type="button" class="btn btn-danger btn-md ">
<span class="glyphicon glyphicon-user" aria-hidden="true"></span> Zaloguj się
</button></li>
</ul>
</div>
</div>
From a high level, the go-to method for this situation is using flexbox instead of floats. Not sure about Bootstrap in your case or why you had that change happen.
.container {
display: flex;
justify-content: flex-end; /* and many more positioning options */
}
just add float: right; to your .navbar-list css then you can move your div to right side
.navbar-list {
color: white;
width: 300px;
height: 100%;
float: right;
}

Navbar to follow wherever I scroll

I'm trying to set my navbar to be on top whenever I scroll, but when i use position: fixed; the navbar disappears. Here's my html and css respectively.
<nav>
<div class="navbar">
<button class="btn button"> Home <A href="#"> </button>
<button class="btn button"> About Me </button>
<button class="btn button"> Portfolio</button>
<button class="btn button"> Contact Me </button>
</div>
</nav>
<div class="background-img">
</div>
<div class="portfolio">
<img src="https://www.google.com/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&cad=rja&uact=8&ved=0ahUKEwjP5v6bzfDWAhXEto8KHc_gBDoQjRwIBw&url=http%3A%2F%2Fhomequity.us%2Fdesignhouse%2Fbungalow_house_design_malaysia.html&psig=AOvVaw3hVzFHYi5ropXAhSrn1oIx&ust=1508087256948636">
</div>
The CSS
nav{
background-color: transparent;
position: fixed;
}
.btn{
background-color: Black;
color: white;
font-size: 30px;
padding: 10px;
margin: 10px 193px 10px 0px;
}
.background-img {
background: url(https://images.unsplash.com/photo-1497215842964-222b430dc094?dpr=1&auto=compress,format&fit=crop&w=2100&h=&q=80&cs=tinysrgb&crop=);
background-size: 100% 100%;
background-repeat: no-repeat;
width: 100vw;
height: 100vh;
position: relative;
}
`
You still need to define it's fixed position as top:0.
nav{
background-color: transparent;
position: fixed;
top:0;
width:100%;
z-index:15;
}
The reason is z-index value. And one more thing you probably forget to close the a tag in nav section.
nav{
background-color: transparent;
position: fixed;
z-index:99999; /* add z-index value maximum */
}
.btn{
background-color: Black;
color: white;
font-size: 30px;
padding: 10px;
margin: 10px 193px 10px 0px;
}
.background-img {
background: url(https://images.unsplash.com/photo-1497215842964-222b430dc094?dpr=1&auto=compress,format&fit=crop&w=2100&h=&q=80&cs=tinysrgb&crop=);
background-size: 100% 100%;
background-repeat: no-repeat;
width: 100vw;
height: 100vh;
position: relative;
}
<nav>
<div class="navbar">
<button class="btn button"> Home </button><!-- You need to close the a tag -->
<button class="btn button"> About Me </button>
<button class="btn button"> Portfolio</button>
<button class="btn button"> Contact Me </button>
</div>
</nav>
<div class="background-img">
</div>
<div class="portfolio">
<img src="https://www.google.com/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&cad=rja&uact=8&ved=0ahUKEwjP5v6bzfDWAhXEto8KHc_gBDoQjRwIBw&url=http%3A%2F%2Fhomequity.us%2Fdesignhouse%2Fbungalow_house_design_malaysia.html&psig=AOvVaw3hVzFHYi5ropXAhSrn1oIx&ust=1508087256948636">
</div>

Bootstrap Navbar Expands when Window gets smaller

Regular
Smaller
My bootstrap 3.0 navbar expands when the window gets to mobile sizes. I've included pictures of the two views above and where the issue is.
I am trying to get my navbar to not expand when the screen gets smaller and cover part of my page.
It may have something to do with the search bar and the buttons near it. I managed to get the search form stay the same size when it expanded across the entire screen behind the sidebar before.
Any help would be great.
HTML
`
<a class="navbar-brand" style="margin-left: -20px">GCImage</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="navbar-right">
<form class="navbar-form" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search" align="right" ng-model="nav.keyword" uib-popover="Not Implemented Yet" popover-placement="bottom" popover-trigger="focus">
</div>
<button type="submit" class="btn btn-default" align="right" uib-popover="Not Implemented Yet" popover-placement="bottom" popover-trigger="focus">
<i class="fa fa-search"></i>
</button>
<a class="btn btn-default" href="underConstruction.html"><i class="fa fa-filter"></i></a>
</form>
</div>
</div>
`
CSS
.panel-green {
border-color: #5cb85c;
background-color: #5cb85c;
color: #ffffff;
}
.panel-orange {
border-color: #ff7e47;
background-color: #ff7e47;
color: #ffffff;
}
.shadow {
-moz-box-shadow: 1px 1px 2px 3px #ccc;
-webkit-box-shadow: 1px 1px 2px 3px #ccc;
box-shadow: 1px 1px 2px 3px #ccc;
}
.panel-footer {
color: #000000;
}
.btn-file {
position: relative;
overflow: hidden;
}
.btn-file input[type=file] {
position: absolute;
top: 0;
right: 0;
min-width: 100%;
min-height: 100%;
font-size: 100px;
text-align: right;
filter: alpha(opacity=0);
opacity: 0;
outline: none;
background: white;
cursor: inherit;
display: block;
}
.body{
margin-left:175px
}
.navbar .navbar-form{
padding: 0 15px;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
.box{
border-radius:0;
}
.navbar-collapse.collapse{
display: block !important;
}
.navbar-nav>li, .navbar-nav{
float: left !important;
}
.navbar-nav.navbar-right:last-child{
margin-right: -15px !important;
}
.navbar-right{
float: right !important;
}
It looks like the icons are wrapping underneath the search bar
I played around with your code a little and came up with a solution, however the icons eventually wrap when the screen gets really small (less than 250px wide)
Try changing this code:
<button type="submit" class="btn btn-default" align="right" uib-popover="Not Implemented Yet" popover-placement="bottom" popover-trigger="focus">
<i class="fa fa-search"></i>
</button>
<a class="btn btn-default" href="underConstruction.html"><i class="fa fa-filter"></i></a>
To this code:
<div class="icons">
<ul class="icon-list">
<li class="icon">
<button type="submit" class="btn btn-default" align="right" uib-popover="Not Implemented Yet" popover-placement="bottom" popover-trigger="focus">
<i class="fa fa-search"></i>
</button>
</li>
<li class="icon">
<a class="btn btn-default" href="underConstruction.html"><i class="fa fa-filter"></i></a>
</li>
</ul>
</div>
And add this to your stylesheet:
.icons {
float: right;
}
ul.icon-list {
padding: 0px;
margin: 0px 0px 0px 4px;
}
li.icon {
display: inline;
list-style: none;
}
.form-group {
display: inline-block !important;
}
This solution isn't perfect, and could be improved (make a backup of your old code before trying this)
Just add
.navbar-header{
display: inline-block; or display: inline-block!important;
}
in your stylesheet. I hope this is what you expect. :)

Parent div container hiding dropdown menu

Its pretty hard to recreate this in jsfiddle so I'm going to go ahead and paste a screenshot, HTML and CSS:
I'm having problem displaying the dropdown in the image above.
HTML and CSS:
<div class="row-fluid profile-gallery-image-container">
<div class="span12">
<img src="#"/>
<div class="image-options">
<div class="dropdown">
<i class="icon-cog icon-white"></i>
<ul class="dropdown-menu">
<li>test</li>
</ul>
</div>
</div>
<div class="delete-image">
<a href="javascript:void(0);"/></a>
</div>
</div>
</div>
.profile-gallery-image-container {
max-width: 130px;
max-height: 110px;
margin-bottom: 0px;
display: inline-block;
position: relative;
border: 2px solid rgba(140,140,140,1);
z-index: 0;
}
.image-options {
float: right;
top: 0px;
right: 0px;
position: absolute;
padding-top: 2px;
border-left: 2px solid rgba(255,128,64,1);
border-bottom: 2px solid rgba(255,128,64,1);
width: 15px;
height: 15px;
}
What am i doing wrong?
This could be to do with z-index levels or could be overflow settings.
Setting the parent container to have "overflow:visible;" would be a start - but then I'd look at position: relative on the menu CSS - that often helps matters.
But ultimately without seeing a working demo I can't figure it out.