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>
Related
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;
}
I was wondering how do I position my Login button at the bottom centre of the screen and have the image displayed over it? I want this to be essentially the homepage. My image is not displaying either for some reason.
Code:
<div class="container-fluid">
<img alt="Sportly logo" src="~#/assets/sportly.png">
<div class="row">
<div class="col-md-12">
<h3>Login</h3>
<button class="btn btn-primary"
#click="signIn">
<i class="fa fa-twitter"></i>
Sign In with Twitter
</button>
</div>
</div>
</div>
</template>
<script>
export default {
methods: {
signIn () {
this.$store.dispatch('signIn')
}
}
}
</script>
<style scoped>
h3 {
font-weight: 700;
}
button {
background-color: #1dcaff;
border: 1px solid #1dcaff;
}
div button:hover {
background-color: #00aced;
border: 1px solid #00aced;
}
</style>
If you want the sign in button to be on top of an image, it would be easier to set a div with a background image and put the button on top of that. Your question is worded so that the image goes over the button, which is probably not what you want.
CSS
.mybackground {
background-image: url('yourimage.jpg');
}
HTML (get rid of img tag)
<div class="container-fluid mybackground">
<div class="row">
<div class="col-md-12">
<h3>Login</h3>
<button class="btn btn-primary"
#click="signIn">
<i class="fa fa-twitter"></i>
Sign In with Twitter
</button>
</div>
</div>
</div>
I used position: fixed + bottom: XXpx to send the div to the bottom of the page, width: 100% + margin: 0 auto + text-align: center to center the elements, and position: relative + z-index: 1 to overlap the login button and the image. Here are the results:
h3 {
font-weight: 700;
}
button {
background-color: #1dcaff;
border: 1px solid #1dcaff;
}
div button:hover {
background-color: #00aced;
border: 1px solid #00aced;
}
.loginarea {
position: fixed;
bottom: 20px; /* Distance from window bottom */
width: 100%;
}
.loginarea .center {
margin: 0 auto;
width: 200px; /* Width of logo */
}
.loginarea .logo {
position: relative;
display: block;
}
.loginarea .row {
position: absolute;
text-align: center;
width: 200px; /* Width of logo */
z-index: 1;
}
<div class="container-fluid loginarea">
<div class="center">
<div class="row">
<div class="col-md-12 logindiv">
<h3>Login</h3>
<button class="btn btn-primary"
#click="signIn">
<i class="fa fa-twitter"></i>
Sign In with Twitter
</button>
</div>
</div>
<img class="logo" alt="Sportly logo" src="http://placekitten.com/200/100">
</div>
</div>
I need my background-image to display underneath my website transparent navigation bar. The image is located under the .header div
http://prntscr.com/p2moi0
<!Navigation Bar>
<nav>
<div class="navigation-bar">
<img class="logo" src="images/logo-black.png">
Home
Services
Pricing
faq
Contact
</div>
</nav>
<div class="header">
<h1>Website development<br> made easy</h1>
<h3>Not just a business but a reliable business partner</h3>
<button type="button" class="button button-1">get started</button>
<button type="button" class="button button-2">get a quote</button>
</div>
</body>
.header{
background-image: url('images/main-background-header.png');
background-position: center;
height: 100%;
background-repeat: no-repeat;
position: relative;
top: 0;
text-align: center;
.navigation-bar {
width: 100%;
height: 80px;
background-color: transparent;
}
to make it work add background div to your header with height equal to full header height + your navbar height
. your navbar should have a z-index of -1 and the background div should have an absolute position relative to the header:
*{
margin:0;
padding:0;
}
.image{
background-image: url('https://picsum.photos/800');
background-position: center;
height: calc(100% + 80px);
width:100%;
background-repeat: no-repeat;
position: absolute;
z-index:-1;
top: -80px;
text-align: center;
}
.navigation-bar {
width: 100%;
height: 80px;
background-color: transparent;
}
.header{
position:relative;
text-align:center;
color:white;
padding:10px 0px;
}
.navigation-bar{
display:flex;
background:rgba(255,255,255,0.5);
align-items:center;
}
.navigation-bar img{
margin-right:10px;
}
.navigation-bar a{
margin-left:10px;
color:white;
padding:10px;
text-decoration:none;
}
.navigation-bar a:hover{
background-color:white;
color:black;
}
<!Navigation Bar>
<nav>
<div class="navigation-bar">
<img class="logo" src="images/logo-black.png">
Home
Services
Pricing
faq
Contact
</div>
</nav>
<div class="header">
<div class="image"></div>
<h1>Website development<br> made easy</h1>
<h3>Not just a business but a reliable business partner</h3>
<button type="button" class="button button-1">get started</button>
<button type="button" class="button button-2">get a quote</button>
</div>
</body>
Just reset the elements margin and it will work. That is done by making every element
margin:0.
See the example bellow:
*{
margin: 0;
}
.header{
background-image: url('https://i.cbc.ca/1.4955357.1545355364!/fileImage/httpImage/image.jpg_gen/derivatives/16x9_780/man-works-late-at-office-computer.jpg');
background-position: center;
height: 100%;
background-repeat: no-repeat;
position: relative;
top: 0;
text-align: center;
}
.navigation-bar {
width: 100%;
height: 80px;
background-color: transparent;
}
<nav>
<div class="navigation-bar">
<img class="logo" src="images/logo-black.png">
Home
Services
Pricing
faq
Contact
</div>
</nav>
<div class="header">
<h1>Website development<br> made easy</h1>
<h3>Not just a business but a reliable business partner</h3>
<button type="button" class="button button-1">get started</button>
<button type="button" class="button button-2">get a quote</button>
</div>
try like this
HTML
<div class="banner">
<nav>
<div class="navigation-bar">
<img class="logo" src="images/logo-black.png">
Home
Services
Pricing
faq
Contact
</div>
</nav>
<div class="header">
<h1>Website development<br> made easy</h1>
<h3>Not just a business but a reliable business partner</h3>
<button type="button" class="button button-1">get started</button>
<button type="button" class="button button-2">get a quote</button>
</div>
</div>
css
.banner{
background-image: url('https://image.freepik.com/free-psd/abstract-background-design_1297-73.jpg');
background-position: center;
height: 100%;
background-repeat: no-repeat;
position: relative;
top: 0;
text-align: center;
padding:40px 0;
}
.nav {
width: 100%;
height: 80px;
background-color: transparent;
text-align:center;
}
I cant figure out why the red buttons are not displayed properly in firefox. In chrome it looks good.
Here is the fiddle:
Fiddle
That is my chrome:
That is my firefox:
My HTML:
<div class="bilder_bearbeiten col-lg-12">
<div class="img-element-del">
<img src="http://ghk.h-cdn.co/assets/cm/15/11/54ff82285cf02-lving-room-green-gold-modern-de.jpg"/>
<a class="btn btn-danger deletebtn" href="/user/logged_in/edit_room/22/delete6"> Entfernen </a>
</div>
<div class="img-element-del">
<img src="http://ghk.h-cdn.co/assets/cm/15/11/54ff82285cf02-lving-room-green-gold-modern-de.jpg"/>
<a class="btn btn-danger deletebtn" href="/user/logged_in/edit_room/22/delete7"> Entfernen </a>
</div>
<div class="img-element-del">
<img src="http://ghk.h-cdn.co/assets/cm/15/11/54ff82285cf02-lving-room-green-gold-modern-de.jpg"/>
<a class="btn btn-danger deletebtn" href="/user/logged_in/edit_room/22/delete8"> Entfernen </a>
</div>
<div class="img-element-del">
<img src="http://ghk.h-cdn.co/assets/cm/15/11/54ff82285cf02-lving-room-green-gold-modern-de.jpg"/>
<a class="btn btn-danger deletebtn" href="/user/logged_in/edit_room/22/delete9"> Entfernen </a>
</div>
<div class="img-element-del">
<img src="http://ghk.h-cdn.co/assets/cm/15/11/54ff82285cf02-lving-room-green-gold-modern-de.jpg"/>
<a class="btn btn-danger deletebtn" href="/user/logged_in/edit_room/22/delete10"> Entfernen </a>
</div>
</div>
My CSS:
.bilder_bearbeiten img {
width: 155px;
height: 100px;
margin-bottom: 5px;
border-radius: 2px;
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
.img-element-del {
padding-bottom: 40px;
display: inline-block;
}
.deletebtn {
border-radius: 0;
width: 155px;
position: absolute;
color: white;
text-align: center;
text-decoration: none;
padding: 5px 0;
}
Well I dont know what details to add. I tried to change everything in firefox browser dev tools but could never achieve the same behaviour as in chrome.
https://jsfiddle.net/7vz89t4d/2/
.img-element-del {
position: relative; /* this is new */
padding-bottom: 40px;
display: inline-block;
}
.deletebtn {
border-radius: 0;
width: 155px;
color: white;
text-align: center;
text-decoration: none;
padding: 5px 0;
position: absolute;
bottom: 0; /* this is new */
left: 0; /* this is new */
}
Short explanation:
If using position:absolute; do also set position:relative; to the parent. Then absolute is always from the parent.
This picture might help:
the picture is from css-tricks.com/absolute-positioning-inside-relative-positioning which explains it even a little further.
The above picture in code would look like:
.parent {
position: relative;
width: 400px;
height: 300px;
border: solid 3px CHOCOLATE;
}
.absolute-one,
.absolute-two,
.absolute-three {
position: absolute;
background-color: CHOCOLATE;
color: white;
padding: 10px;
width: 100px;
height: 100px;
}
.absolute-one {
top: 0;
left: 0;
}
.absolute-two {
bottom: 5px;
left: 10px;
}
.absolute-three {
top: 30%;
right: -25px;
}
<div class="parent">
<div class="absolute-one">
top: 0;
left: 0;
</div>
<div class="absolute-two">
bottom: 5px;
left: 10px;
</div>
<div class="absolute-three">
top: 30%;
right: -25px;
</div>
</div>
I've updated your fiddle here -> https://jsfiddle.net/7vz89t4d/3/
/* Latest compiled and minified CSS included as External Resource*/
/* Optional theme */
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
body {
margin: 10px;
}
.bilder_bearbeiten img {
width: 155px;
height: 100px;
margin-bottom: 5px;
border-radius: 2px;
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
.img-element-del {
padding-bottom: 40px;
display: inline-block;
position: relative;
margin-bottom: 20px;
}
.deletebtn {
border-radius: 0;
width: 155px;
position: absolute;
color: white;
text-align: center;
text-decoration: none;
padding: 5px 0;
bottom: 0;
left: 0;
}
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css" rel="stylesheet"/>
<div class="bilder_bearbeiten col-lg-12">
<div class="img-element-del">
<img src="http://ghk.h-cdn.co/assets/cm/15/11/54ff82285cf02-lving-room-green-gold-modern-de.jpg"/>
<a class="btn btn-danger deletebtn" href="/user/logged_in/edit_room/22/delete6"> Entfernen </a>
</div>
<div class="img-element-del">
<img src="http://ghk.h-cdn.co/assets/cm/15/11/54ff82285cf02-lving-room-green-gold-modern-de.jpg"/>
<a class="btn btn-danger deletebtn" href="/user/logged_in/edit_room/22/delete7"> Entfernen </a>
</div>
<div class="img-element-del">
<img src="http://ghk.h-cdn.co/assets/cm/15/11/54ff82285cf02-lving-room-green-gold-modern-de.jpg"/>
<a class="btn btn-danger deletebtn" href="/user/logged_in/edit_room/22/delete8"> Entfernen </a>
</div>
<div class="img-element-del">
<img src="http://ghk.h-cdn.co/assets/cm/15/11/54ff82285cf02-lving-room-green-gold-modern-de.jpg"/>
<a class="btn btn-danger deletebtn" href="/user/logged_in/edit_room/22/delete9"> Entfernen </a>
</div>
<div class="img-element-del">
<img src="http://ghk.h-cdn.co/assets/cm/15/11/54ff82285cf02-lving-room-green-gold-modern-de.jpg"/>
<a class="btn btn-danger deletebtn" href="/user/logged_in/edit_room/22/delete10"> Entfernen </a>
</div>
</div>
Try adding "Left:0;" and "bottom:0;" in your deletebtn css
Here I have craeted a new one. You do not have to use position absolute or something similar.
jsfiddle
I have just put each "image" and "a" in a div
<div class="bilder-row">
<img src="..."/>
<a class="btn btn-danger deletebtn" href="/user/logged_in/edit_room/22/delete6"> Entfernen </a>
</div>
and style:
.bilder-row{width:160px;float:left;}
this will solve the problem.
When styling a page with markup, generally avoid absolute positioning within your layout. Absolutely positioned items make for very brittle layouts which make responsive design very very challenging. Only use it as a last resort. I'd recommend you fully utilize Bootstrap. It's a very powerful tool but is opinionated about your markup. I've refactored your example into something more responsive while taking full advantage of the Bootstrap grid: http://getbootstrap.com/css/#grid
Here's the full Codepen example: http://codepen.io/toddsby/pen/pRLQem
Viewed on Firefox 51 (macOS)
HTML
<div class="row gutter-5">
<div class="img-element-del col-xs-3">
<img src="http://ghk.h-cdn.co/assets/cm/15/11/54ff82285cf02-lving-room-green-gold-modern-de.jpg" />
<div class="deletebtn-container">
<a class="btn btn-danger deletebtn" href="/user/logged_in/edit_room/22/delete6"> Entfernen </a>
</div>
</div>
</div>
CSS
/** custom Bootstrap grid gutter **/
.row.gutter-5 {
margin-left: -10px;
margin-right: -10px;
}
.gutter-5 > [class*="col-"], .gutter-5 > [class*=" col-"] {
padding-right: 5px;
padding-left: 5px;
}
I've moved the items into a col-3 (12/4) grid. Then styled the image and button to take up 100% of their containers. This allows for a flexible and responsive layout. You can then use Bootstrap breakpoints to target different devices. ie <div class="img-element-del col-xs-1 col-md-2 col-lg-3">
Note: This layout would be very simple with Flexbox. As of 2016, Flexbox is supported by all major browsers! You can learn more about Flexbox here: https://medium.freecodecamp.com/understanding-flexbox-everything-you-need-to-know-b4013d4dc9af
Try add position: relative; to .img-element-del
and to .deletebtn add this properties:
z-index: 1;
left: 0;
bottom: 10px;
I have a website where I want a header and a sidebar.
My intended functionality is that the sidebar extends to the bottom of the page, which it does. However, it has content that extends beyond the viewport, I'm guessing because the .menu is sized to 100% of the entire body container, yet is pushed down because of the header.
How do I make it such that the menu only extends all the way down the viewport?
<body>
<div class="container-fluid">
<header class='row'>
<div class="col-md-1">
<a href="#" class="menu-icon-link">
<i class="glyphicon glyphicon-list"></i>
</a>
</div>
<div class="input-group col-md-4 col-md-offset-4">
<input type="text" class="form-control" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-default" type="button"><i class="glyphicon glyphicon-search"></i></button>
</span>
</div>
</header>
<div class="row menu-container">
<div class="menu col-md-2">
Lorem ipsum...
</div>
</div>
</div>
</body>
My CSS:
html, body{
height: 100%;
margin: 0;
padding: 0;
}
body {
position: relative;
padding: 3.5em 0 0 0;
box-sizing: border-box;
}
.menu-container {
display: block;
}
.menu {
position: fixed;
top: 3.5em;
padding: 1em;
background: #A9E2AD;
height: 100%;
overflow-y: scroll;
}
.glyphicon-list {
font-size: 1.5em;
color: #FFF;
}
header {
background: #50af4c;
color: #fff;
position: fixed;
top: 0;
width: 100%;
padding: 0.5em 1em;
display: block;
}
You don't need to use an explicit height, you can use positioning for what you want.
.menu {
position: fixed;
top: 3.5em;
bottom: 0; //add this
padding: 1em;
background: #A9E2AD;
//height: 100%;
overflow-y: scroll;
}