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>
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/
Is there a way to get this navigation bar to always been in the middle of the page? I'm sure using percentages will be the best way. I added in which line I think needs changing. I'm just trying to get used to CSS. Any help would be appreciated.
<!DOCTYPE html>
<html>
<head>
<style>
.menu {
position:absolute;
background:#CCC;
width:100%;
top:100px;
left:0;
height:23px;
padding: 0;
text-align:center;
font-size:20px;
font-weight:light;
}
.ty-menu__items {
position: absolute;
left:20%; /* This is the line that needs changing, I think*/
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width:100%;
}
.ty-menu__item {
float: left;
}
a:link, a:visited {
display: block;
width: 200px;
font-weight: light;
color: #FFF;
background: #CCC;
text-align: center;
padding: 0;
text-decoration: none;
text-transform: uppercase;
}
a:hover, a:active {
background: #000;
border-bottom: 4px solid #fff;
}
</style>
</head>
<body>
<div class="menu">
<ul class="ty-menu__items">
<li class="ty-menu__item">Home</li>
<li class="ty-menu__item">News</li>
<li class="ty-menu__item">Contact</li>
<li class="ty-menu__item">About</li>
</ul>
</div>
</body>
</html>
Remove the left property from your ul, then remove the float property from your li's, and instead make the li's display: inline-block; so you can simply text-align: center; them. Code below:
.ty-menu__items {
position: absolute;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width:100%;
text-align: center;
}
.ty-menu__item {
display: inline-block;
}
I am looking to have the logo aligned in the center and social media buttons aligned on the right in the header. How do I achieve? I've been able to get it aligned with my nav bar but that's not what I'm looking for. Any help would be appreciated.
HTML
<body>
<div id="wrapper">
<header>
<div class="logo">
<img src="http://i.imgur.com/cosDXx1.png"/>
</div>
<div class ="social">
<img src="http://i.imgur.com/1GhbSOj.png"/>
<img src="http://i.imgur.com/oawoJtC.png"/>
<img src="http://i.imgur.com/2dAtAX3.png"/>
</div>
</header>
<nav>
<ul class="egmenu">
<li>Home</li>
<li>About
<ul>
<li>History</li>
<li>Brothers</li>
</ul>
</li>
<li>Philanthropy
<ul>
<li>Kovacs Color Run</li>
<li>Greek God</li>
<li>Boys & Girls Club</li>
</ul>
</li>
<li>Membership</li>
<li>Contact</li>
</ul>
</nav>
CSS
body {
margin:0px;
padding:0px;
}
header {
height:105px;
background-color:black;
text-align:center;
}
header img{
display:inline-block;
margin: 0 auto;
}
header .social a {
float:right;
}
ul.egmenu {
background: #333;
height: 30px;
width: 100%;
text-align:center;
}
ul.egmenu > li {
position: relative;
display:inline-block;
list-style:none;
}
ul.egmenu ul {
background: #444;
display: none;
position: absolute;
left: 0; top: 100%;
}
ul.egmenu a {
cursor: pointer;
display: block;
color: white;
line-height: 30px;
padding: 0 20px;
text-decoration:none;
}
ul.egmenu li {
list-style: none;
}
ul.egmenu li:hover {
background: #555;
}
ul.egmenu li:hover ul {
display: block;
padding:0;
}
#media all and (max-width: 600px) {
ul.egmenu { height: auto; padding:0;}
ul.egmenu > li { float: none; width: 100%; }
ul.egmenu a { line-height: 40px; }
ul.egmenu ul { position: relative; }
}
#media all and (min-width: 601px) {
ul.egmenu li:hover { background: #555; }
ul.egmenu li:hover ul { display: block; }
}
#media all and (max-width: 600px) {
ul.egmenu { height: auto; }
ul.egmenu > li { float: none; width: 100%; }
ul.egmenu a { line-height: 40px; }
ul.egmenu ul { position: relative; }
ul.egmenu li.tap { background: #555; }
ul.egmenu li.tap ul { display: block; }
}
Heres a fiddle: http://jsfiddle.net/mcxa341s/
Remove the logo div and use CSS to add a background for the header.
Change to this:
header {
height:105px;
background: url('http://i.imgur.com/cosDXx1.png') no-repeat center;
background-color:black;
text-align:center;
}
And use margin-top for the social div to adjust the positioning.
JSFiddle Demo
UPDATE
Change:
header .social a {
float:right;
}
To this:
header .social {
position: absolute;
right: 0;
top: 40px;
}
JSFiddle Demo
Make the logo a background for the header and get rid of the logo div. Then your social media icons will align without a problem.
Use position:absolute for social media.
.social {
position: absolute;
right: 20px;
top: 50px;
}
CSS:
body {
margin:0px;
padding:0px;
}
header {
height:105px;
background-color:black;
text-align:center;
}
header .logo{ margin: 0 auto;}
header .social{margin-top:-24px;}
header img{
display:inline-block;
}
header .social a {
float:right;
}
ul.egmenu {
background: #333;
height: 30px;
width: 100%;
text-align:center;
}
ul.egmenu > li {
position: relative;
display:inline-block;
list-style:none;
}
ul.egmenu ul {
background: #444;
display: none;
position: absolute;
left: 0; top: 100%;
}
ul.egmenu a {
cursor: pointer;
display: block;
color: white;
line-height: 30px;
padding: 0 20px;
text-decoration:none;
}
ul.egmenu li {
list-style: none;
}
ul.egmenu li:hover {
background: #555;
}
ul.egmenu li:hover ul {
display: block;
padding:0;
}
#media all and (max-width: 600px) {
ul.egmenu { height: auto; padding:0;}
ul.egmenu > li { float: none; width: 100%; }
ul.egmenu a { line-height: 40px; }
ul.egmenu ul { position: relative; }
}
#media all and (min-width: 601px) {
ul.egmenu li:hover { background: #555; }
ul.egmenu li:hover ul { display: block; }
}
#media all and (max-width: 600px) {
ul.egmenu { height: auto; }
ul.egmenu > li { float: none; width: 100%; }
ul.egmenu a { line-height: 40px; }
ul.egmenu ul { position: relative; }
ul.egmenu li.tap { background: #555; }
ul.egmenu li.tap ul { display: block; }
}
JSFiddle Demo
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 ...
}
I'm trying to center the navigation, but I haven't succeeded yet. The idea is that the navigation moves along as the user scrolls the page. It has to be responsive as well, because navigation should always be displayed. So I've come up with this:
<nav id="nav" class="container">
<ul>
<li><a href="#avaleht" class="avaleht" title="Avaleht" >avaleht</a></li>
<li><a href="#massaazh" class="massaazh" title="Massaaž" >massaaž</a></li>
<li><a href="#kontakt" class="kontakt" title="Kontakt" >kontakt</a></li>
</ul>
</nav>
And the CSS:
#nav
{
position: fixed;
}
#nav ul
{
list-style: none;
padding-left: 0;
text-align: center;
}
#nav li
{
display: inline-block;
}
#nav a
{
color: rgb(255,255,255);
font-family: 'Open Sans', sans-serif;
font-weight: 500;
text-transform: uppercase;
font-size: 1.3em;
display: block;
margin-right: 80px;
height: 100px;
width: 100px;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
line-height: 100px;
}
#nav a.avaleht
{
background: rgb(168,191,18);
}
#nav a.massaazh
{
background: rgb(255,159,0);
}
#nav a.kontakt
{
background: rgb(0,170,181);
}
#nav a:hover
{
text-decoration: none;
background: rgb(66,64,62);
}
And this is how I'd like it to work:
Thank you very much.
Just add left:0; right:0; to the fixed #nav element:
#nav {
position: fixed;
left:0; right:0;
}
Then remove the margin-right for the last li element's child anchor element:
#nav li:last-child a {
margin-right:0;
}
Example Here
#nav {
position: fixed;
left:0;
right:0;
}
and replace margin-right:80 with margin:5px 40px
#nav a{
margin: 5px 40px;
}