How can I make the sidebar stick? - html

Currently, I've made it so that the sidebar appears where the 'apply' page starts. I want the sidebar to then remain in that position as the user continues to scroll down. Another thing that confuses me is that when I set the position to 'absolute' for the bar, it just disappears completely. Why does this happen?
CSS:
#navbar {
background-color: black;
overflow: auto;
height: 100%;
width: 25%;
z-index: 1000;
float: right;
}
#navbar-links {
list-style-type: none;
display: block;
}
#apply {
background-color: red;
}
#about {
background-color: orange;
}
#sponsor {
background-color: green;
}
HTML:
<div id="pages">
<!-- apply page -->
<div id="apply" class="sections" tabindex='2'>
<!-- navigation bar -->
<div id="navbar">
<ul id="navbar-links">
<li>Apply</li>
<li>About</li>
<li>Sponsor</li>
</ul>
</div>
<div class="container">
</div>
</div>
<!-- about page -->
<div id="about" class="sections" tabindex='3'>
<div class="container">
</div>
</div>
<!-- sponsor page -->
<div id="sponsor" class="sections" tabindex='4'>
<div class="container">
</div>
</div>
</div>

You need to use position: fixed fix the position to the view.
You can then use: top right left and bottom to put the element where you want it to be. So right: 0; and top: 0; put the element 0px from the right and top.
The same is true for position absolute, if you didn't use any of those that may be why it disappeared.
See here for more details on css position property: http://www.w3schools.com/cssref/pr_class_position.asp
#navbar {
position: fixed;
right: 0;
top: 0;
background-color: black;
color: white;
overflow: auto;
height: 100%;
width: 25%;
z-index: 1000;
}
#navbar-links {
list-style-type: none;
display: block;
}
#apply {
background-color: red;
}
#about {
background-color: orange;
}
#sponsor {
background-color: green;
}
<div id="pages">
<!-- apply page -->
<div id="apply" class="sections" tabindex='2'>
<!-- navigation bar -->
<div id="navbar">
<ul id="navbar-links">
<li>Apply</li>
<li>About</li>
<li>Sponsor</li>
</ul>
</div>
<div class="container">
</div>
</div>
<!-- about page -->
<div id="about" class="sections" tabindex='3'>
<div class="container">
</div>
</div>
<!-- sponsor page -->
<div id="sponsor" class="sections" tabindex='4'>
<div class="container">
</div>
</div>
</div>

Related

Something is wrong with scroll bar and content

Something is wrong with my code.
I don't understand why the scrollbar is visible?
Why do I need to add <br /> to content for the text will be show?
#main {
transition: margin-left .5s;
padding: 16px;
}
#header {
transition: margin-left .5s;
position: fixed;
right: 0;
left: 0;
top: 0;
background: #ededed;
font-weight: 700;
z-index: 10;
height: 70px;
}
#content {
margin-top: 70px;
}
#footer {
background: #ffab62;
width: 100%;
height: 20px;
position: fixed;
bottom: 0;
left: 0;
}
<div id="mySidenav" class="sidenav">
×
×
<div id="menu">
<ul id="myUL">
</ul>
</div>
<p>סה"כ: 50 ש"ח</p>
</div>
<div id="wrapper">
<div id="site">
<div id="header">
<ul>
<div id="referNav">
<li>
<div id="referLink1">הזמנה חדשה
</div>
</li>
<li>
<div id="referLink2">2
</div>
</li>
</div>
</ul>
</div>
</div>
<!-- #header -->
<div id="content">
<br />
<input type="text" id="myInput" placeholder="Title...">
<span onclick="newElement()" class="addBtn">Add</span>
</div>
</div>
<!-- #wrapper -->
Add overflow: hidden; to the <body> and the scrollbar should be hidden. I don't know the answer to your second question, but I think I've gave you the answer for the first question.

CSS Navbar Breaking (width 100%, wraps around onto next line)

I'm working on an aspx master page, and my nav bar is wrapping around even though the width adds up to 100%. What is throwing this off, I've had it work on other projects?
Snippet:
/*General Styling*/
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
#wrapper {
min-height: 100%;
position: relative;
}
.clear:before,
.clear:after {
content: " ";
display: table;
}
/*Header Styling*/
/*Banner Styling*/
#banner {
text-align: center;
border-bottom: 1px solid purple;
}
#banner h1 {
color: blue;
}
#banner h5 {
color: red;
}
/*Nav Styling*/
#nav {
height: 100px;
border-bottom: 1px solid black;
}
.nav-item {
margin: 0;
padding: 0;
display: block;
list-style-type: none;
height: 100%;
}
.nav-child {
overflow: hidden;
font-size: 15px;
border-right: 1px solid green;
float: left;
height: 100%;
text-align: center;
width: 16%;
}
.nav-child:first-child {
width: 20%;
}
/*Content Styling*/
#content {
padding-bottom: 35px;
}
/*Footer Styling*/
#footer {
width: 100%;
border-top: 1px solid orange;
height: 35px;
position: absolute;
bottom: 0;
left: 0;
}
<!-- Start Wrapper -->
<div id="wrapper">
<!-- Start Header -->
<div id="header">
<div id="banner">
<h1>BETTER</h1>
<h5>Battling Elemental Titans Through Exercise Training</h5>
</div>
<!-- Start Navigation Bar -->
<div id="nav" class="clear">
<ul class="nav-item">
<li class="nav-child">
<asp:label ID="exercisePointLabel" runat="server">EP: 500</asp:label>
<br />
Add Exercise Points
</li>
<li class="nav-child">
Home
</li>
<li class="nav-child">
Battle
</li>
<li class="nav-child">
Hall of Legends
</li>
<li class="nav-child">
Settings
</li>
<li class="nav-child">
Logout
</li>
</ul>
</div>
<!-- End Navigation Bar -->
</div>
<!-- End Header -->
<!-- Start Content -->
<div id="content">
<!-- Start Titan Sidebar -->
<div id="titans">
<div class="titan-block">titan block</div>
<div class="titan-block">+<br /><span class="createTitan">(create new titan)</span>
</div>
<div class="titan-block">+<br /><span class="createTitan">(create new titan)</span>
</div>
<div class="titan-block">+<br /><span class="createTitan">(create new titan)</span>
</div>
</div>
<!-- End Titan Sidebar -->
<!-- Start Content Placeholder -->
<form id="form1" runat="server">
<div id="body">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
<!-- End Content Placeholder -->
</div>
<!-- End Content -->
<!-- Start Footer -->
<div id="footer">
<div class="footer-text">© 2016</div>
</div>
<!-- End Footer -->
</div>
<!-- End Wrapper -->
If someone could please help that would be amazing. This is driving me crazy. I'm trying to build a website where the banner is, obviously, a banner, with heading and subheading. Followed by a navbar where the first child is an info box slightly wider than the other children, with 5 true navigation elements.
This will then be followed by content, which consists of a left aligned "titan" section, which occupies 100% height down to the footer, with a right aligned "content placeholder" section, also 100% height down to the footer.
It's the border-right you have.
You should add box-sizing: border-box; to fix this.
.nav-child {
overflow:hidden;
font-size:15px;
border-right:1px solid green;
float:left;
height:100%;
text-align:center;
width:16%;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
Here is another solution for this.
Replace this style in your css file:
.nav-child:first-child {
/* width: 20%; Remove this style */
}
.nav-item {
display: table;
height: 100%;
list-style-type: none;
margin: 0;
padding: 0;
}
.nav-child {
border-right: 1px solid #008000;
display: table-cell;
font-size: 15px;
height: 100%;
overflow: hidden;
text-align: center;
vertical-align: middle;
width: 1%;
}
Demo: https://jsfiddle.net/4bfg0p18/2/

How can I make the header's border/other content not overlap the img on the left?

HTML:
<div id="container">
<!-- Header -->
<div id="logo">
<img src="img">
</div>
<div id="header">
<h1>Header</h1>
</div>
<!-- Nav -->
<div id="nav">
<ul>
<li>nav</li>
<li>nav</li>
<li>nav</li>
</ul>
</div>
<!-- Main Content -->
<div id="content">
<div id="mainContent">
Content
</div>
<div id="imgOne">
<img src="img">
</div>
<div id="imgTwo">
<img src="img">
</div>
<div id="imgThree">
<img src="img">
</div>
</div>
</div>
<div id="footer">
Footer
</div>
</body>
</html>
CSS:
* {
margin: 0;
padding: 0;
}
#container {
width: 100%;
}
#logo {
width: 150px;
height: 200px;
border: 3px solid black;
float: left;
}
#header {
text-align: center;
border: 3px solid black;
}
#nav {
clear: left;
}
#content {
}
How it currently looks.
This is what it looks like right now. I would like the header to not be overlapping and still stay centered in the page, how can I do that?
Sorry if the post is sloppy, first post here & new to coding.
This can be done in so many ways dependent of how everything else on the page should behave.
Below sample just show a way to fix the header issue.
The to the "header" added "margin" and "padding" make sure the header text is center to page and as well not overlap the image.
* {
margin: 0;
padding: 0;
}
#container {
width: 100%;
}
#logo {
width: 150px;
height: 200px;
border: 3px solid black;
float: left;
}
#header {
text-align: center;
border: 3px solid black;
margin-left: 156px;
padding-right: 156px;
}
#nav {
clear: left;
}
#content {
}
<div id="container">
<!-- Header -->
<div id="logo">
<img src="img">
</div>
<div id="header">
<h1>Header</h1>
</div>
<!-- Nav -->
<div id="nav">
<ul>
<li>nav</li>
<li>nav</li>
<li>nav</li>
</ul>
</div>
<!-- Main Content -->
<div id="content">
<div id="mainContent">
Content
</div>
<div id="imgOne">
<img src="img">
</div>
<div id="imgTwo">
<img src="img">
</div>
<div id="imgThree">
<img src="img">
</div>
</div>
</div>
<div id="footer">
Footer
</div>

Bootstrap container shifts to the left when row has image content

I'm trying to develop a pretty simple site using twitter bootstrap. When adding content I noticed that all of the content with the container class was being shifted a bit to the left with the addition of a child div of the row class with image content. The padding/margin/width of the container div doesn't seem to be changing so I'm really not sure what's affecting this change.
The HTML and CSS is below and the issue can be seen if you comment out the divs with classes .row1 and .row2. Doing so returns the content of the container class to its regular location.
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="http://code.jquery.com/color/jquery.color-2.1.2.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
</head>
<body>
<!-- Header -->
<div id="header">
<div class="container">
<div id="leftHeader">
<h1>Title</h1>
<h1 class="subtitle"><small>Subtitle</small></h1>
</div>
<div id="rightHeader">
<h3>Declaration</h3>
</div>
</div>
</div>
<!-- Navbar -->
<nav class="navbar navbar-default">
<div class="container">
<!-- Navbar Header -->
<div class="navbar-header">
<a class="navbar-brand" href="index.htm">Company Name</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>Services</li>
<li>Pricing</li>
<li>About Us</li>
<li>Contact Us</li>
</ul>
</div>
</div>
</nav>
<!-- Content -->
<div class="container">
<div class="row row1">
<div class="col-md-12">
<div id="countercont">
<div id="counter"><div>0</div></div><div id="introRest">Counter text</div>
<div id="edge">Other side</div>
</div>
</div>
</div>
<div class="row row2">
<div class="col-md-4 img1">
<img src="computer.jpg" />
</div>
<div class="col-md-4 img2">
<img src="lightbulb.jpg" />
</div>
<div class="col-md-4 img3">
<img src="dome.jpg" />
</div>
</div>
<div class="row row3">
<div class="col-md-6">
<h1>Title</h1>
<p>Text</p>
</div>
<div class="col-md-6">
<h1>Title 2</h1>
<p>Other Text</p>
</div>
</div>
</div>
</body>
</html>
CSS
.subtitle {
margin-top: -15px;
}
#leftHeader {
float: left;
}
#rightHeader {
float: right;
}
#rightHeader h3 {
font-size: 28px;
padding-top: 40px;
}
#counter {
border-style: solid;
border-width: 1px;
width: 150px;
display: block;
margin-left: auto;
margin-right: auto;
}
#counter div {
font-size: 50px;
width: 82px;
margin: 0 auto;
}
#introRest, #edge{
font-size: 30px;
display: none;
}
#edge {
float: right;
font-style: italic;
}
#countercont {
height: 80px;
}
.img1, .img2, .img3 {
text-align: center;
}
.img1 img, .img2 img, .img3 img {
border: 2px solid black;
height: 240px;
width: 240px;
}
.row2 {
padding-top: 10px;
padding-bottom: 30px;
}
.row3 ul {
padding-left: 20px;
margin-top: 20px;
margin-bottom: 20px;
}
.row3 li {
font-size: 13px;
}
Did you try adding a max-width to your images?
.img1 img, .img2 img, .img3 img {
border: 2px solid black;
height: 240px;
width: 240px;
max-width:100%; /* Added these */
max-height:100%; /* Added these */
}
Example on Bootply

Why are headers/pictures being placed beneath instead of beside?

this is for sure a noobish html question, because i am new at this stuff.
Anyways lets get to it:
1st, check the fiddle:
http://jsfiddle.net/d6767uur/
<!DOCTYPE html>
<html>
<head>
<link type="text/css" href="frontpage.css" rel="stylesheet">
</head>
<body>
<div class="navBar">
<div class="greyline"> </div>
<div class="menu"> smoothies </div>
<div class="greyline"> </div>
<div class="menu"> milkshakes </div>
<div class="greyline"> </div>
<div class="menu"> juicy facts </div>
<div class="greyline"> </div>
<div class="menu"> about us </div>
<div class="greyline"> </div>
<div class="stuffwithsmall"> © All rights reserved.. </div>
</div>
<div class="frontWrapper">
<h1> HELLO </h1>
<div style="margin-left: 750px; margin-top: -435px;"> <img src="frontfruit.jpg"> </div>
</div>
</body>
</html>
CSS:
#font-face { font-family: SourceSansPro-Regular; src: url('SourceSansPro-Regular.otf'); }
body {
margin: 0px;
padding: 0px;
}
.navBar {
width: 205px;
height: 667px;
background-color: #55AE3A; //hover = 398a20
}
.greyline {
width: 205px;
height: 1px;
background-color: darkgrey;
}
.menu {
font-family: 'SourceSansPro-Regular';
color: white;
font-size: 25px;
opacity: 0.64;
height: 40px;
text-decoration: none;
}
.menu:hover {
background-color: #398a20;
}
.stuffwithsmall {
color: #75715e;
font-family: helvetica;
margin-top: 320px;
}
Question: why is that header going down below the main menu, and how do i change it, so that it goes to the right of the menu?
Your navbar div goes down that far because .stuffwithsmall class is inside it and has a huge margin-top. You can fix that by moving it lower, after the closing tag of navbar div.
In css, change:
.navbar {
height: auto;
width: 100%;
}