I am learning about css atm, and I am trying to use a external css to style all my website. I found that if I do:
<ul id="menu" style="width:420px; margin:0 auto">
I get the result I want, but if I do it on a external file like:
this is the css file:
*{
margin:0px;
padding:0px;}
header, section, footer, aside, nav, article, hgroup {
display:block;}
body {
width:100%;
display:-webkit-box;
background-color: #808286;
-webkit-box-pack: center;}
#container {
max-width: 1000px;
margin: 20px 0px;
display:-webkit-box;
background-color: #FFFFFF;
display:-webkit-box;
-webkit-box-orient: vertical;
-webkit-box-flex: 1; }
#top_header {
background-color: #fdd023;
padding: 20px;
border: 2px solid #49207e;}
#new_div {
display:-webkit-box;
-webkit-box-orient: horizontal; }
#navigation_bar {
border: 1px solid #5970B2;
padding: 0;}
#main_section {
border: 1px solid blue;
-webkit-box-flex: 1;
margin: 20px;
padding: 20px;}
#side_left {
border: 1px solid red;
width: 220px;
margin: 20px 0px;
padding: 30px;
background: #66CCCC;}
#main_footer {
text-align: center;
padding: 20px;
border-top: 2px solid green;}
#menu {
width:420px;
margin:0 auto;}
#menu li {
list-style: none;
display: inline;
}
#menu li a {
display: inline;
padding: 0 8px 0px;
text-align: center;
text-decoration: none;
}
#menu div {
position: absolute;
visibility: hidden;
margin: 0;
padding: 0;
background: #EAEBD8;
border: 1px solid #5970B2}
#menu div a {
position: relative;
display: block;
margin: 0;
padding: 5px 10px;
width: auto;
white-space: nowrap;
text-align: left;}
this is the Html code:
<div id="container">
<nav id="navigation_bar">
<ul id="menu">
<li>
<a href=""">
A
</a>
<div id="firstMenu">
1
2
</div>
</li>
<li>
<a href="">
B
</a>
<div id="secondMenu">
1
2
3
4
</div>
</li>
<li>
<a href="">
C
</a>
</li>
<li>
<a href="">
D
</a>
</li>
<li>
<a href="">
E
</a>
</li>
</ul>
<div style="clear:both"></div>
</nav>
I get a different layout. The first centers my menu bar, and the second one give me a little of a padding. I am using Chrome, but I think I may be missing a key concept here.
The differences you are seeing are due to some other code on the page.
If a CSS rule applies (after the cascade is applied), then it doesn't matter where it came from as far as rendering is concerned.
Related
My navigation bar cannot click any item except the last item. I have checked and follow the tutorial from youtube but unfortunately I checked code is same but not working at all please anyone got solution please share to me.
Here's My html
<html>
<title>UIA | Homepage</title>
<link href="Homepage.css" rel="stylesheet" type="text/css">
<header>
<div class="row">
<div class="logo">
<img src = "Logo.png">
</div>
<ul class="main-nav">
<li class = "active"> Home </li>
<li> Promotion </li>
<li> Booking </li>
<li> SignIn </li>
<li> About </li>
</ul>
</div>
<div class="title">
<h1>Ready for another adventure?</h1>
</div>
</header>
And here's my CSS.
*{
margin: 0;
padding: 0;
}
header{
background-image:
linear-gradient(rgba(0,0,0,0.8),rgba(0,0,0,0.8)), url(Homepage.jpg);
height:100vh;
background-position:center;
background-size: cover;
}
.main-nav{
float: right;
list-style: None;
margin-top: 30px;
}
.main-nav li{
display: inline-block;
}
.main-nav li a{
color: white;
text-decoration: none;
padding: 5px 20px;
font-family: "Roboto", Sans-serif;
font-size: 15px;
}
.main-nav li.active a{
border: 1px solid white;
}
.main-nav li a:hover {
border: 1px solid white;
}
.logo img{
width: 150px;
height: auto;
margin-top:10px;
float: left;
}
.row{
max-width: 1200px;
margin: auto;
}
.title{
position:absolute;
width: 1200px;
margin-left: 0;
margin-top: 0;
}
h1{
color: white;
font-size: 60px;
text-align: center;
margin-top: 255px;
}
So did I miss out something please advice me Thank you.
.title is overlapping the menu.
You can give the menu a higher z-index to ensure it is on top.
Information about z-index
updated code below
* {
margin: 0;
padding: 0;
}
header {
background-image: linear-gradient(rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.8)), url(Homepage.jpg);
height: 100vh;
background-position: center;
background-size: cover;
}
.main-nav {
float: right;
list-style: None;
margin-top: 30px;
/* added */
position: relative;
z-index: 100;
}
.main-nav li {
display: inline-block;
}
.main-nav li a {
color: white;
text-decoration: none;
padding: 5px 20px;
font-family: "Roboto", Sans-serif;
font-size: 15px;
}
.main-nav li.active a {
border: 1px solid white;
}
.main-nav li a:hover {
border: 1px solid white;
}
.logo img {
width: 150px;
height: auto;
margin-top: 10px;
float: left;
}
.row {
max-width: 1200px;
margin: auto;
}
.title {
position: absolute;
width: 1200px;
margin-left: 0;
margin-top: 0;
}
h1 {
color: white;
font-size: 60px;
text-align: center;
margin-top: 255px;
}
<header>
<div class="row">
<div class="logo">
<img src="Logo.png">
</div>
<ul class="main-nav">
<li class="active"> Home </li>
<li> Promotion </li>
<li> Booking </li>
<li> SignIn </li>
<li> About </li>
</ul>
</div>
<div class="title">
<h1>Ready for another adventure?</h1>
</div>
</header>
It is because you do not use clearfix on your floated element parent(similar issues will occur on all floated stuff if you don't use clearfix).
Add this to your css file:
.clearfix:after {
content: "";
display: table;
clear: both;
}
And add clearfix to parent of floated element, in this case to:
<div class="row clearfix">
I recommend reading these two(will come in handy in the future):
https://css-tricks.com/all-about-floats/
https://css-tricks.com/snippets/css/clear-fix/
Just in case, here is a link to jsfiddle with solution to your issue: https://jsfiddle.net/mwgjycv4/1/
I have menu that open inline block links
this menu work fine in all browser except IE11
in chrome appear like this
in IE11 appear link this
this snippet
.rlist--inline {
list-style: none;
padding: 0;
margin: 0;
}
.rlist--inline li{
display:inline-block;
padding:10px;
border:1px solid black;
}
.dropdown__menu li{
padding:5px;
}
.dropdown__menu a {
white-space: nowrap;
padding: 12px 20px 8px;
}
* {
box-sizing: border-box;
}
.dropdown:hover>.dropdown__menu {
display: flex;
background: #ed1c24;
left:-100%;
}
.dropdown {
display:inline-block;
position: relative;
background:red;
}
.dropdown__menu {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
display: none;
float: left;
min-width: 160px;
font-size: 14px;
text-align: left;
box-shadow: 0 6px 12px rgba(0,0,0,.175);
}
<ul class="rlist--inline">
<li class="menu-item"><a><span>Topics</span></a></li>
<li class="dropdown menu-parent" >
<a title="Journal" class="dropdown__toggle">
<span>Journal</span>
</a>
<ul class="rlist dropdown__menu">
<li>
<a title="Current Issue"">
<span>Current Issue</span>
</a>
</li>
<li>
<a>
<span>Archive</span>
</a>
</li>
<li>
<a >
<span>Article Series</span>
</a>
</li>
</ul>
</li>
</ul>
how I can fix it in IE11?
I tried to make clearfix & make right:-100% , but still there is problem.
any help ............................................................
First, there is issue in your HTML with double quote here
<a title="Current Issue"">
Second, it looks like when you display flex in a row in IE it does not compute new width and instead keeps the same width from when flex box was a column. I am not exactly sure what you want to accomplish but if you are trying to make submenues red you can apply red color and shadow directly to your list items like so:
.rlist--inline {
list-style: none;
padding: 0;
margin: 0;
}
.rlist--inline li {
display: inline-block;
padding: 10px;
border: 1px solid black;
}
.dropdown__menu li {
padding: 5px;
}
.dropdown__menu a {
white-space: nowrap;
padding: 12px 20px 8px;
}
* {
box-sizing: border-box;
}
.dropdown:hover>.dropdown__menu {
display: flex;
/* background: #ed1c24; */
left: -100%;
}
.dropdown {
display: inline-block;
position: relative;
background: red;
}
.dropdown__menu {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
display: none;
float: left;
min-width: 160px;
font-size: 14px;
text-align: left;
}
ul.rlist > li {
background: #ed1c24;
box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
}
<ul class="rlist--inline">
<li class="menu-item"><a><span>Topics</span></a></li>
<li class="dropdown menu-parent">
<a title="Journal" class="dropdown__toggle">
<span>Journal</span>
</a>
<ul class="rlist dropdown__menu">
<li>
<a title="Current Issue">
<span>Current Issue</span>
</a>
</li>
<li>
<a>
<span>Archive</span>
</a>
</li>
<li>
<a>
<span>Article Series</span>
</a>
</li>
</ul>
</li>
</ul>
I'm trying to do something so astonishingly simple, and yet after pounding my head on the wall I'm unable to get the div that contains my navigation menu to center within the container. I would appreciate it if you'd have a look and let me know why it isn't working. I have a 1px border around the elements so you can see how the 'nav' div is staying left justified.
Here's a link to jsfiddle:
http://jsfiddle.net/glennw9/7vr7tovh/3/
html, body {
background-color:#F2EED6;
width:900px;
height:900px;
border: 1px solid #630800;
margin: 0px 0px 0px 0px;
}
#container {
/*border: 1px solid #630800;*/
width: 860px;
margin: 0 auto;
border: 1px solid #630800;
}
h1 {
font-size: 2.5em;
font-family: Georgia;
letter-spacing: 0.1em;
color: #630800;
text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.6);
text-align: center;
}
div.nav {
margin-left: auto;
margin-right: auto;
display: inline-block;
border: 1px solid #630800;
text-align: center;
}
ul.nav {
width: 840
margin: 0 auto;
display: block;
}
ul.nav, li.nav {
list-style-type: none;
}
li.nav, a.nav {
background: #354178;
color: white;
font-family: Arial, Helvetica, sans-serif;
padding: 6px 10px;
text-decoration: none;
}
li.nav, a.nav:hover {
background: #4A5AA7;
display:inline;
}
li {
display:inline;
padding: 10px;
}
a.active {
background: white;
color: black;
border: 1px solid #CCCCCC;
}
<body>
<div id="container">
<h1>Edit Order Record</h1>
<div class="nav">
<ul class="nav">
<li><a class="nav" href="inv-main.php">Main Page</a>
</li>
<li><a class="nav" href="prod-view-paged.php">View Products</a>
</li>
<li><a class="nav active" href="order-view-paged.php">View Orders</a>
</li>
<li><a class="nav" href="cat-view.php">View Categories</a>
</li>
<li><a class="nav" href="#Bot">Go to Bottom</a>
</li>
</ul>
</div>
<br>
<br>
<br>
</body>
Simply add text-align: center; to the #container element.
Here's a fiddle.
You can center align it by simply two ways.
This "div.nav" class has inline-block. To make it center aligned with its parent, you have to use "text-align:center" to its parent.
Remove inline-block for "div.nav" class and add margin:0 auto in this class. It will be center aligned.
you have a lot of options mentioned above. This too counts as one of them: position: absolute;
left:50%;
margin-left: (half of the width of the div u wish to center)
Remember, set your parent element/div to relative.
What about this (updated fiddle)?
div.nav {
margin: 0 auto;
border: 1px solid #630800;
text-align: center;
}
If you want to consider using flex-box, you can do something like this too (see the fiddle, and here's the browser compatibility table):
HTML:
<nav>
<h1>Hello world</h1>
<ul>
<li>Thing</li>
<li>Another thing</li>
<li>Yet another</li>
</ul>
</nav>
CSS:
nav {
border: 1px solid gray;
display: flex;
flex-flow: column wrap;
align-items: center;
width: 100%;
}
li {
display: inline-block;
border: 1px solid black;
}
And lastly, here's a list of ways to center stuff:
Set this on the child element: { margin-left: 50%; transform: translateX(-50%) }
If the child element is block do this: { margin: 0 auto }
Or, on the parent element, do: { text-align: center }
remove the margin:0px 0px 0px 0px; and change that to margin:auto; in html,body{}
and add text-align:center in #container.
html, body {
background-color:#F2EED6;
width:900px;
height:900px;
border: 1px solid #630800;
/* margin: 0px 0px 0px 0px;*/
margin: auto;
}
#container {
/*border: 1px solid #630800;*/
margin: 0 auto;
border: 1px solid #630800;
text-align:center;
}
just edit the css part. and it will generate the output like this:
I have 5 divs in two wrapper divs and when I am assigning the float left attribute to the 5 dips they are gaining a 'top-margin' of 5, as in they have a space between the top of the wrapper div and them. Here is My HTML and CSS
HTML:
<div class="headerMenuWrapper">
<div class="menuOuterWrapper">
<div class="menuInnerWrapper" id="menuWrapper">
<div class="menuItem">Home</div>
<div class="menuItem">About Us</div>
<div class="menuItem">Products</div>
<div class="menuItem">FAQ</div>
<div class="menuItem">Contact Us</div>
</div>
</div>
</div>
CSS:
.menuOuterWrapper{
margin: auto;
margin-top: 0;
width: 95%;
height: 100%;
}
.menuInnerWrapper {
margin: auto;
margin-top: 0;
width: 90%;
height: 100%;
background-color: #327CF1;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
box-shadow: 1px 1px 5px #000000;
}
.menuItem {
height: 100%;
text-align: center;
border-right: 1px solid #051625;
float: left;
}
.headerMenuWrapper {
margin: auto;
width: 95%;
height: 50%;
}
Is this what you are looking for?
You have a lot going on in your markup that shouldn't be.
I simplified everything for you by using:
nav
ul
li
Instead of floats and margins, I used:
display: table
display: table-cell
text-align: center
HTML
<nav id="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Products</li>
<li>FAQ</li>
<li>Contact Us</li>
</ul>
</nav>
CSS
* {
margin: 0;
padding: 0;
border: none;
}
#menu {
margin: 0 auto;
text-align: center;
}
#menu > ul {
display: table;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
box-shadow: 1px 1px 5px #000000;
background: #327CF1;
width: 100%;
}
#menu ul > li {
display: table-cell;
text-align: center;
border-right: 1px solid white;
color: white;
}
#menu > ul > li:last-child {
border: none;
}
use Resetting Browser-Style Defaults for Elements
shorthand for you
{
margin: 0px;
padding: 0px;
}
margin: auto tells to browser automatically calculate margin
example of reset styles here http://meyerweb.com/eric/thoughts/2007/04/12/reset-styles/
http://jsfiddle.net/hmaQR/
Here is my html:
<div id="page">
<div id="logo">
<h1>My Website</h1>
</div>
<div id="navigation-wrapper">
<ul id="top-navigation">
<li class="home">Home</li>
<li class="about">About</li>
<li class="Blog">Blog</li>
<li class="Contact">Contact</li>
</ul>
</div>
<div id="body"></div>
</div>
and the CSS
#page {
margin: 0 auto;
border: 2px solid black;
width: 960px;
height: 700px;
}
h1 {
font-family: Helvetica;
text-decoration:;
color: #0099CC
}
#logo {
position: relative;
margin: 0 auto;
text-align: center;
font-size: 20px;
border: 1px dashed blue;
}
#navigation-wrapper {
margin: 0 auto;
border: 1px dashed blue;
text-align: center;
}
#top-navigation {
border: 1px solid black;
margin: 0 auto;
list-style: none;
}
#top-navigation li {
width: 80px;
height: 20px;
background-color: orange;
padding: 5px;
color: blue;
font-family: Helvetica;
display: inline-block;
}
You'll notice that the orange navbar/list is not quite centered to the logo above it. What the heck am I missing?
I cannot seem to get the #top-navigation to center to the middle of the page. I'm super new to css, so any help would be appreciated.
I suggest you in each css file of a page that you make, always put the following first to disable all margin and padding of the default css:
* { margin:0;padding:0}
Try that, and then you can tweak the margin and padding of your h1
Hope this helps
I forked your fiddle: http://jsfiddle.net/hmaQR/1/
ul { padding-left: 0; }
I highly recommend getting a good dev toolbar. Chrome has a great one out of the box.