I have a web page with a sticky header, sticky sidebar and sticky footer but can't get the content to be padded on the right(padding just gets ignored) and my in-page links don't work correctly. I want to do this with CSS ONLY.
http://jsfiddle.net/C7v9f/
I know there are many other similar questions but their solutions either don't work; their too old; they've never been answered; they use jQuery, JavaScript etc. or they fall apart after adding things like line-height or padding.
html, body {
height: 100%;
color: #fff;
}
body, p {
margin: 0;
padding: 0;
}
#wrap {
min-height: 100%;
height: auto !important;
height: 100%;
overflow: auto;
background: #888;
}
#header {
height: 55px;
background: #222;
position: fixed;
width: 100%;
z-index: 4;
}
#SC-wrap {
float: left;
margin-bottom: 40px;
}
/* BEGIN HEADER NAV */
#nav {
padding-left: 32%;
}
#nav li{
position: relative;
display: inline;
color: white;
}
#nav a {
display: inline-block;
padding:10px;
}
#nav ul {
position: absolute;
/*top:100%; Uncommenting this makes the dropdowns work in IE7 but looks a little worse in all other browsers. Your call. */
left:-9999px;
margin:0;
padding:0;
text-align: left;
text-decoration: none;
}
#nav ul li {
display: block;
}
#nav li:hover ul {
left:0;
}
#nav li:hover a {
text-decoration: none;
background: darkgrey;
}
#nav li:hover ul a {
text-decoration: none;
background: #B8B8B8;
}
#nav li:hover ul a:hover{
text-decoration: none;
background: #CCCCCC;
}
#nav ul a{
white-space: nowrap;
display: block;
border-bottom:1px solid #ccc;
color: white;
text-decoration: none;
}
#nav a {
text-decoration:none;
color: blue;
}
#nav a:hover {
text-decoration:none;
background: #f1f1f1;
color: blue;
}
/* END HEADER NAV */
#sidebar {
background-color: green;
width: 150px;
height: 100%;
position: fixed;
line-height: 2em;
font-size: 1.2em;
z-index: 2;
text-align: center;
padding-top: 6%;
overflow-y: auto;
}
#sidebar a {
text-decoration: none;
}
#sidebar a:hover {
background-color: grey;
}
#content {
padding-right: 250px;
width: 100%;
padding-top: 100px;
font-size: 1.2em;
line-height: 1.6em;
z-index: 1;
text-align: left;
padding-left: 200px;
}
#footer {
position: fixed;
bottom: 0px;
height: 40px;
width: 100%;
background: #222;
z-index: 4;
}
The padding on the right is there, the content is just too wide. To make the padding not be included in the width of the element use box-sizing:border-box Demo
#content {
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
... Your other styles ...
}
Related
Hi so I'm trying to align my navigation menu where the links align on one line with each other. But instead of aligning they are stacking. I'm currently coding in dreamweaver. I don't know what's going on.
Here is my css
body, html {
margin: auto;
width: 100%;
height: 100%;
}
.header {
width: 100%;
height: 100%;
background: url("") no-repeat;
display: block;
}
.header > .nav-container {
width: 100%;
height: 50px;
padding-top: 0px;
display: block;
}
.header > .nav-container > .logo {
width: 100%;
max-width: 196px;
display: inline-block;
margin-left: 20px;
background: #000;
}
.header > .nav-container > .navigation {
display: inline-block;
width: 60%;
background: #000;
}
.nav-container > ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
.nav-container > li {
float: left;
display:inline-block;
}
.nav-container > li a {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav-container > li a:hover {
background-color: #111;
}
.nav-container > .active {
background-color: #4CAF50;
}
and the html
<div class="header">
<div class="nav-container">
<div class="logo">
<img src="C:\Users\Terrell\Documents\Designs\GetVersed\site\versedlogo.png">
</div>
<!-- Naviagation -->
<div class="navigation">
<ul>
<li><a class="active" href="#home">Home</a></li>
<li>News</li>
<li>Contact</li>
</ul>
</div>
<!-- End Navigation -->
</div>
Can anyone explain to me what I am doing wrong.
I think this is the simplest way that I can break down what i'm asking for this site is asking me to write more because it's so much code here so this is just exrta writing.
You need to set display property of each List item as Inline.
ul li{
display: inline;
}
Add the block below to your css
.navigation ul {
display: flex;
}
.navigation li {
padding: 5px;
}
.navigation ul {
display: flex;
}
.navigation li {
padding: 5px;
}
body,
html {
margin: auto;
width: 100%;
height: 100%;
}
.header {
width: 100%;
height: 100%;
background: url("") no-repeat;
display: block;
}
.header>.nav-container {
width: 100%;
height: 50px;
padding-top: 0px;
display: block;
}
.header>.nav-container>.logo {
width: 100%;
max-width: 196px;
display: inline-block;
margin-left: 20px;
background: #000;
}
.header>.nav-container>.navigation {
display: inline-block;
width: 60%;
background: #000;
}
.nav-container>ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
.nav-container>li {
float: left;
display: inline-block;
}
.nav-container>li a {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav-container>li a:hover {
background-color: #111;
}
.nav-container>.active {
background-color: #4CAF50;
}
<div class="header">
<div class="nav-container">
<div class="logo">
<img src="C:\Users\Terrell\Documents\Designs\GetVersed\site\versedlogo.png">
</div>
<!-- Naviagation -->
<div class="navigation">
<ul>
<li><a class="active" href="#home">Home</a></li>
<li>News</li>
<li>Contact</li>
</ul>
</div>
<!-- End Navigation -->
</div>
ul{
list-style: none;
position: absolute;
left: 0px;
}
li>a{
display:inline;
}
li{
display:inline-block;
}
implement these css properties , you should get it inline
working fiddle
You should follow proper way to apply css
body, html {
margin:auto;
width:100%;
height:100%;
}
.header{
width:100%;
height:100%;
background:url("") no-repeat;
display:block;
}
.header > .nav-container{
width:100%;
height:50px;
padding-top:0px;
display:block;
}
.header > .nav-container > .logo{
width:100%;
max-width:196px;
display:inline-block;
margin-left:20px;
background:#000;
}
.header > .nav-container > .navigation{
display:inline-block;
width:60%;
background:#000;
vertical-align: middle
}
.navigation > ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
.navigation ul > li {
float: left;
display:inline-block;
}
.navigation ul > li a {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.navigation ul > li a:hover {
background-color: #111;
}
.navigation .active {
background-color: #4CAF50;
}
Remove the greater sign in css in between the element
ex:
.nav-container > li {
float: left;
display:inline-block;
}
write like this
.nav-container li {
float: left;
display:inline-block;
}
The greater than sign (>) selector in CSS is used to select the element with a specific parent. It is called as element > element selector. It is also known as the child combinator selector which means that it selects only those elements which are direct children of a parent. It looks only one level down the markup structure and not further deep down. Elements which are not the direct child of the specified parent is not selected.
https://www.geeksforgeeks.org/what-is-greater-than-sign-selector-in-css/
I need the last tab (About) to float to the right and the others to the left. It all floats left.
<div class="nav">
<ul>
<li>HOME</li>
<li>COSC 231</li>
<li>MAGIC 8 BALL</li>
<li>ABOUT</li>
</ul>
</div>
a {
color:#b7b7b7;
text-decoration:none;
}
body {
background-color:#0d0d0d;
font-family:Tahoma;
color:#ffffff;
text-align:center;
margin:0;
}
#lines {
line-height:.3px;
}
hr {
width:30%;
}
#page {
text-align:left;
}
div {
margin:0 auto;
text-align:center;
}
img {
width:50%;
border:1px solid white;
}
.nav {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
}
.nav div {
width:100%;
position: fixed;
}
.nav ul {
list-style-type: none;
width:100%;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #dbdbdb;
}
.nav li {
float: left;
}
.nav li a {
color: white;
text-align: center;
display: block;
padding: 12px 16px;
text-decoration: none;
-o-transition:.25s;
-ms-transition:.25s;
-moz-transition:.25s;
-webkit-transition:.25s;
transition:.25s;
}
.nav li a:hover {
background-color: #efefef;
}
.aboutRight {
position: fixed;
float: right;
left: 100px;
}
First of all have style for class aboutRight .aboutRight and your link has ID <li>ABOUT</li>. Rewrite id into class as it's a bad practice to use IDs for styling.
Second, you don't need position:fixed; in this style, it won't take space in a parent container, you need this link to be in a same position as other links.
Third, you should apply that class not to the <a> tag, but to the <li> element, because you want to float right <li> inside of <ul>, not <a> inside of <li>
And lastly, since you have this rule .nav li { float: left; } and want to override it for a certain li, you should write more specific selector, not just a class, e.g. nav li.aboutRight
I created a snippet for you with working code.
a {
color:#b7b7b7;
text-decoration:none;
}
body {
background-color:#0d0d0d;
font-family:Tahoma;
color:#ffffff;
text-align:center;
margin:0;
}
#lines {
line-height:.3px;
}
hr {
width:30%;
}
#page {
text-align:left;
}
div {
margin:0 auto;
text-align:center;
}
img {
width:50%;
border:1px solid white;
}
.nav {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
}
.nav div {
width:100%;
position: fixed;
}
.nav ul {
list-style-type: none;
width:100%;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #dbdbdb;
}
.nav li {
float: left;
}
.nav li a {
color: white;
text-align: center;
display: block;
padding: 12px 16px;
text-decoration: none;
-o-transition:.25s;
-ms-transition:.25s;
-moz-transition:.25s;
-webkit-transition:.25s;
transition:.25s;
}
.nav li a:hover {
background-color: #efefef;
}
.nav li.aboutRight {
float: right;
left: 100px;
}
<div class="nav">
<ul>
<li>HOME</li>
<li>COSC 231</li>
<li>MAGIC 8 BALL</li>
<li class="aboutRight">ABOUT</li>
</ul>
</div>
I am trying to create a hamburger menu for when my screen goes below 1025px but for some reason there is a small gap between my nav and my menu div whenever I make the window use the media query. I am not sure why it is there. When I use developer tools I find no margins around either of them.
nav #menu{
position: relative;
z-index: 999;
float: right;
margin: 0 75px 0 0;
line-height: 50px;
}
nav #menu li{
font-family:"Abril Fatface";
display: inline-block;
padding-left: 50px;
}
nav #menu li a{
color: white;
position: relative;
text-decoration: none;
}
nav #menu li a:after{
content: '';
position: absolute;
top: 0;
right: 0;
width: 0%;
border-bottom: 2px solid #c1c1c1;
transition: .3s;
}
nav #menu li a:hover:after{
width: 100%;
}
nav #menu li a:hover{
color: #c1c1c1;
}
#media (max-width: 1024px){
.hamburger{
float: right;
cursor: pointer;
padding: 15px;
display: block;
border-left: .1px solid white;
}
.line{
border-bottom: 4px solid white;
width: 35px;
margin-bottom: 5px;
}
.line:last-child {
margin-bottom: 0;
}
nav #menu{
width: 100%;
overflow: hidden;
padding-right: 0px;
margin: 0;
line-height: 25px;
/* height: 0;*/
}
nav #menu li{
display: block;
width: 100%;
background-color: black;
}
nav #menu li a{
width: 100%;
}
.open{
height: auto;
}
Perhaps try specifying:
nav {
margin: 0 auto;
}
I seem to be having a problem with my CSS in making the entire menu item clickable, not just the text.
As you can see from the highlighted screenshot, the menu does not extend to 100% height of the div. As a result, only the text of the menu is clickable, not the whole box around it. How do I make the entire box clickable?
(Code Below)
#header
{
background-color: black;
}
#header .menu
{
display: inline;
text-decoration: none;
list-style-type: none;
margin: 0;
padding: 0;
width: 100%;
height: 100%
position: relative;
text-transform:uppercase;
}
#header .menu ul{
display: inline-block;
}
#header .menu li {
display: inline-block;
padding: 20px;
width: auto;
color: white;
height: 100%;
position: relative;
}
#header .menu a{
display: block;
width: 100%
height: 100%;
text-decoration: none;
color: white;
font-family: Helvetica;
}
#header .menu ul li a{
display: block;
}
#header .menu li a{
position: relative;
}
Thanks.
Use this piece of CSS
#header .menu
{
display: inline;
text-decoration: none;
list-style-type: none;
margin: 0;
padding: 0;
width: 100%;
height: 100%
position: relative;
text-align: center;
text-transform:uppercase;
}
#header .menu li { display: inline; float:left; }
#header .menu li a
{
text-decoration: none;
padding: .2em 1em;
color: #fff;
background-color: #000;
font-family: Helvetica;
}
#header ul li a:hover
{
color: Yellow;
background-color: #000;
}
Here is a Demo
I tried to add some social media icons to my header just now and they are about 10 times larger than they should be. I've gone through the css and used firebug and I can't find what is doing this.
I would like them to be their regular size and sit on the top right of the header. Thanks in advance!!
Here's what it looks like ( http://www.bolistylus.com ):
Here's the style.css:
a {
color: #254655;
}
ul, ol {
margin: 0 0 0 5.5em;
}
#page {
margin: 0 auto;
}
body{
background: #f3f3f3;
border-top: none;
border-top: 10px solid #666666;
}
#page {
margin: 0em auto;
width: 1000px;
}
.singular.page .hentry {
padding: 0.5em 0 0;
}
#branding{
background: #f3f3f3;
color: #000000;
border-top: none;
position: relative;
z-index: 2;
}
#site-title {
/*margin-right: 270px;*/
padding: 0.66em 0 0 0;
}
#site-title a {
color: #111111;
font-size: 60px;
font-weight: bold;
line-height: 36px;
text-decoration: none;
}
#branding h1, header#branding a{
text-align: left;
margin-right: 0;
}
#branding span{
text-align: center;
}
#branding img {
height: auto;
margin-bottom: -.66em;
width: 30%;
}
#branding .widget{
position: absolute;
top: 2em;
right: 7.6%;
}
#respond{ background: #E7DFD6; }
.welcome{
margin: 15px 60px;
background: #f3f3f3;
border: 1px solid #f6ff96;
padding: 15px;
text-align: center;
}
/* =Menu
-------------------------------------------------------------- */
/*.header_nav ul{
margin: 0;
padding: 0;
text-align: center;
width: 400px;
}
*/
#branding img .sm-img {
height: auto;
margin-bottom: -.66em;
width: 100%;
}
.header_nav {
background: #f3f3f3
}
.header_nav .head-nav {
border-bottom: 1px solid #cfcec9;
border-top: 1px solid #cfcec9;
margin-top: 30px;
padding-top: 5px;
padding-bottom: 5px;
text-align: right
}
.header_nav ul li{
display: inline;
}
.header_nav ul li a{
padding: 10.5px 21px;
color: #000000;
}
.header_nav ul li a:hover, .menu ul li .current{
color: #a8cb17;
text-decoration: none;
}
#access {
background: #f3f3f3; /* Show a solid color for older browsers */
}
#access ul {
font-size: 13px;
list-style: none;
margin: 0 0 0 -0.8125em;
padding-left: 0;
}
#access li {
float: center;
position: relative;
display: inline;
}
#access a {
}
#access ul ul {
}
#access ul ul ul {
}
#access ul ul a {
}
#access a:focus {
}
#access li:hover > a,
#access a:focus {
}
#access ul li:hover > ul {
}
#access .current_page_item > a,
#access .current_page_ancestor > a {
font-weight: bold;
}
You're specifying a percentage width multiple times in your CSS, here are the lines:
style.css (line 70)
#branding img {
height: auto;
margin-bottom: -0.66em;
width: 30%; //remove
}
style.css (line 530)
#branding img {
height: auto;
margin-bottom: -7px;
width: 100%; //remove
}
Remove those and they should display ok.
Try to change your css here:
#branding img {
height: auto;
margin-bottom: -0.66em;
width: 3%; /* 3 not 30 */
}
In style.css line 70
Line 70 of your style.css is setting a width attribute with a value of 30%. This is causing your images to stretch to 30% of their container.
#branding img {
height: auto;
margin-bottom: -.66em;
width: 30%;
}
Adjust the width to a lower percentage or remove the line entirely.