I'm new to HTML and CSS.
I'm trying to do a website, and I'm starting by the navbar, but this navbar is not "scalable" for every screen side, when it is on full screen fine but when I minimize it it does not load the part on the right side wich is "About". All of the menus are pointing to the same page and for now that's the objective.
Here's the Code:
body {}
.navbardiv {}
.navbar_ul {
list-style-type: none;
margin: 0;
padding: 0;
/*overflow:hidden;*/
background-color: #333;
border: 5px solid gray;
margin: -8px;
width: auto;
min-width: 600px;
height: 70px;
}
li {
float: left;
padding: 10px 150px;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px 16px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
<!--NAVBAR-->
<div class="navbardiv">
<ul class="navbar_ul">
<li class="navbar_li_Contact">Contact</li>
<li class="navbar_li_WebHosting">Webhosting</li>
<li class="navbar_li_About">About</li>
</ul>
</div>
You are setting the padding for li to 150px which is very high, you need to reduce.
But if you want the links to take the whole width and to be evenlly spaced, then you can use flex box and justify-content: space-between;
see code snippet:
body {}
.navbardiv {}
.navbar_ul {
list-style-type: none;
margin: 0;
padding: 0;
/*overflow:hidden;*/
background-color: #333;
border: 5px solid gray;
margin: -8px;
width: auto;
min-width: 600px;
height: 70px;
display: flex;
justify-content: space-between;
}
li {
float: left;
padding: 10px 20px;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px 16px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
<!--NAVBAR-->
<div class="navbardiv">
<ul class="navbar_ul">
<li class="navbar_li_Contact">Contact</li>
<li class="navbar_li_WebHosting">Webhosting</li>
<li class="navbar_li_About">About</li>
</ul>
</div>
Your navbar is not responsive because of min-width: 600px; part. What this one will do is that when screen resolution is below 600px in width it will keep your navbar at 600 px. Thus it will align it to leftmost part of the screen which will leave you a cropped right edge.min-width:100%; wont work either since it will start to crop when inner elements of the navbar will not fit.
It is easy to fix this. Just change it to width:100%;.
Related
I have a "current" class which highlights the current page. And it works as far as highlighting the current page. With the padding I've added the highlighted area covers the a-element and go towards the top of the page which is what I want it to do. But each highlighted area is the width of the a-element and since each a-element has a different number of characters within, the widths are inconsistent.
To correct this I gave the a-element a display: block. This correction did give a consistent width, but now the highlighted area goes down towards the page as opposed to towards the top of the page as I wanted it.
How can I get a consistent width of highlighted area to go up towards the top of the page?
nav {
margin: 100px auto;
}
.top-nav {
width: 785px;
color: dimgrey;
text-align: center;
margin: 0 auto;
}
.top-nav li {
width: 150px;
float: left;
margin: 0 3px;
}
.top-nav a {
color: dimgrey;
width: 150px;
}
.current {
padding: 150px 0px 5px 0px;
background-color: #fab938;
color: white;
}
span.fa-bath {
font-size: 50px;
margin-top: -45px;
margin-bottom: 10px;
border-radius: 100%;
padding: 20px;
background-color: #fab938;
}
<nav>
<ul class="top-nav">
<li>Quem Somos</li>
<li>O Que Fazemos?</li>
<li><span class="fa fa-bath"></span></li>
<li>Donations</li>
<li>Contact</li>
</ul>
</nav>
I would change the way you build you nav.
Instead of using a float use a inline-block on the LI.
Next to that you can use vertical-align: middle; to align the items from the middle or use top/bottom.
also your nav container is not fitting the size of the 5 Li you are using.
https://jsfiddle.net/wyrscn48/1/
nav {
margin: 100px auto; }
.top-nav {
width: 935px;
color: dimgrey;
text-align: center;
margin: 0 auto;
}
.top-nav li {
width: 150px;
margin: 0 3px;
display: inline-block;
vertical-align: top;
}
.top-nav a {
color: dimgrey;
width: 150px; }
.current {
background-color: #fab938;
color: white; }
span.fa-bath {
font-size: 50px;
margin-bottom: 10px;
border-radius: 100%;
padding: 20px;
background-color: #fab938;
}
Okay so I'm in the process of learning flexbox but I cannot understand why my navigation title is above the links.
HTML:
<style>
#import url(https://fonts.googleapis.com/css?family=Oswald:400,700);
.box {
display: flex;
}
.item {
width: 100px;
height: 100px;
background-color: red;
margin: auto;
color: #fff;
}
nav {
font-family: "Oswald", sans-serif;
display: flex;
min-width: 100%;
background-color: #181818;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
max-width: 960px
}
nav a {
display: block;
padding: 1rem;
text-decoration: none;
color: #fff;
font-weight: 400;
transition: all 0.3s ease-in-out;
}
nav a:hover {
color: #343434;
}
.title {
margin: 0 35px 0 10px;
color: #1BC;
}
</style>
<nav>
<div class="container">
<a class="title">Architect</a>
<ul>
<li>Getting Started</li>
<li>Examples</li>
<li>Blog</li>
<li>Forum</li>
</ul>
</div>
</nav>
Container CSS:
.container{
width: 100%;
margin: 0 auto:
max-width: 1200px;
}
Code Pen Link: http://codepen.io/ZoidCraft/pen/XKMewy
I would like the title "Architect" to be align to the left of the links.
You set <a class="title">Architect</a> to display: block; in your css. Block level elements will take up their own line. display: flex; elements will also take up their own line.
To fix your problem you could first remove that display: block; from your nav a style. Then change your nav ul from display: flex; to display: inline-flex;. Now you just need to add some padding back to your nav since everything is display inline now, so add padding: 1em 0; to your nav
Here is an updated CodePen of what I am talking about.
Not sure why there is a space to the right of each li, as you can see here when you mouse over it. Obviously don't want it there and can't figure out how to get rid of it. Any help would be greatly appreciated!
Here is the code:
HTML:
<header>
<div class="nav-container">
<nav class="nav-items" role="navigation">
<ul>
<li>list1</li>
<li>list2</li>
<li>list3</li>
</ul>
</nav>
</div>
</header>
CSS:
header {
position: fixed;
top:0;
background-color:#2C5463;
height:2.3em;
width: 100%;
border-bottom-color: black;
border-bottom-style: solid;
}
header .nav-container {
margin: 0 30px;
height: 100%;
display: block;
padding: 0;
}
.nav-items {
float: left;
margin: 0;
height: 100%;
}
.nav-items ul {
display: inline-block;
margin: 0;
height: 100%;
}
.nav-items ul li {
display: inherit;
border-left: 1px solid #c8c8c8;
height: 100%;
margin: 0;
}
.nav-items ul li a {
display: inherit;
text-decoration: none;
color: #ffffff;
margin: 0 auto;
padding-top: 8px;
white-space: nowrap;
height: 100%; /* Width and height of top-level nav items */
width: 90px;
text-align:center;
vertical-align: middle;
}
.nav-items ul li:hover {
background: #617F8A
}
http://jsfiddle.net/eF83x/
Inline elements are sensitive to white space. Remove the white space and the problem goes away.
Ex:
<ul>
<li>list1</li><li>list2</li><li>list3</li>
</ul>
jsFiddle example
You can remove the spaces between the list items literally, occupy the space with HTML comments (<!-- -->), or float them left.
Just needs to changes on css class here for your solution,
.nav-items ul
{
display: **inline-table**;
margin: 0;
height: 100%;
}
Demostration
What you could also do is make the lis float left and display them as block. This will fix it without messing with the html code.
.nav-items ul li {
float: left;
display: block;
border-left: 1px solid #c8c8c8;
height: 100%;
margin: 0;
}
jsFiddle example
So I'm trying to keep an unordered list centered once the website hits a certain media query. I can't get it to stay in the center of it's container if the page is moved around. Here is the corresponding code.
HTML
<div id="centerNav">
<ul id="home-nav">
<li>DUI/DWI Defense</li>
<li>Criminal Defense</li>
<li>Estate Planning</li>
<li style="border: none;"> Agricultural Law</li>
</ul>
</div>
CSS
#media only screen and (max-width: 839px)
{
#centerNav {
margin: 0 auto;
max-width: 840px;
padding: 0;
height:60px;
}
#home-nav li {
float: left;
position: relative;
display: block;
text-align: center;
background: none;
font-size: 20px;
width: 158px;
border-right: 1px solid #fff;
margin-top: 8px;
line-height: 1em;
padding-left: 10px;
}
#home-nav {
list-style:none;
position:relative;
height: 60px;
vertical-align: middle;
z-index: 5;
border-top: 4px double #fff;
border-bottom: 4px double #fff;
border: none;
margin: 0;
background: #7a0426;
}
}
Remove float from li and make it display: inline-block
I think this will solve your issue.
css
#centerNav {
margin: 0 auto;
max-width: 840px;
padding: 0;
height:60px;
text-align:center;
}
#home-nav li {
position: relative;
display: inline-block;
text-align: center;
background: none;
font-size: 20px;
border-right: 1px solid #fff;
line-height: 60px;
padding:0 10px;
}
jsFiddle Code
In your media query you need to make sure float is none because you have float set from previous css
#home-nav li {
float: none;
display: inline-block;
}
The unordered list that contains the li, add text-align: center
#home-nav {
text-align: center;
}
Also your html structure is currently invalid because you have a div as the immediate child of a ul. You can wrap the ul with the div if you need to but it definitely should not be the way it is now
That should solve the issue
Heres my html for my tabbed navigation bar. Im having trouble centering the text within the li tags and putting padding on the top is not somthing I want to do because I want to put padding around all the text to make the whole tab clickable. If theres any advice for that as well please feel free to give me advice. So how can I make my link text centered and if possible how can I make the whole tab clickable?
<div id="tab_container">
<nav id="tabs">
<ul id="nav">
<li class="active">About</li>
<li class="inactive">Services</li>
<li class="inactive">Our Staff</li>
<li class="inactive">book</li>
<li class="inactive">Gift Cards</li>
<li class="inactive">Reviews</li>
</ul>
</nav>
</div>
This is my CSS. Please tell where I went wrong?!
#tab_container
{
background-color: #222;
display: -webkit-box;
-webkit-box-flex: 1;
display: block;
position: relative;
max-width: 970px;
width: 100%;
text-align: center;
}
#tabs
{
float: left;
margin-top: 0px;
width: 100%;
max-width: 970px;
background-color: #222;
padding-top: 20px;
text-align: center;
}
#nav
{
width: 100%;
max-width: 970px;
text-align: center;
}
ul
{
float: left;
max-width: 970px;
display: -webkit-box;
-webkit-box-flex: 1;
width: 100%;
padding-left: 0px;
margin-bottom: 0px;
margin-top: 0px;
margin-right: 0px;
text-align: center;
}
ul li
{
display: inline-block;
text-align: center;
width: 158px;
height: 70px;
background-color: black;
font-size: 18px;
text-transform: uppercase;
text-align: center;
margin:0 auto;
padding: 0;
}
ul li a
{
color: #54544b;
text-decoration: none;
text-align: center;
margin: 0px auto;
}
a:hover
{
color: #CF7BA1;
}
.active a
{
text-decoration: underline;
color: #CF7BA1;
}
Option 1:
Really simple. Just add line-height: 70px; to your a tag.
So the css would be:
ul li a
{
color: #54544b;
text-decoration: none;
text-align: center;
margin: 0px auto;
line-height: 70px;
}
Where the 70px is the height of the list element.
Option 2:
Alternatively, you could set your A to display: block; and add padding to that. This would make it clickable, but personally, I prefer to use line height.
ul li a
{
display: block;
padding-top: 15px;
padding-bottom: 15px;
}