CSS positioning - relative positioning issue - html

Ive created a website but I noticed the navigation bar was slightly off using IE browser. I have read that position:relative may be the key but when I apply it the navigation bar doesn't respond to position commands (top, left, etc.)at all in IE, and would appear in different locations with FF browser when reloaded a few times.
Please could I get advice on which method is standard for getting correctly positioned elements with different browsers, and also tell me where I'm going wrong with changing my navigation bar divs from absolute to relative>
Much appreciated
code hints: Page comprises of company logo (id=banner) floated left, a small list of towns and phonenumber (id=info) all floated right. Navigation bar is in list form and I used block:inline command to so the list reads from left to right.
/* ----All page selectors---- */
body{
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
font-size:16px;
}
.page {
position: relative;
margin-left:auto;
margin-right:auto;
background-color: rgba(255,255,255,0.4);
font-family: gabriola, Verdana, Geneva, sans-serif;
color: #383838;
font-weight: bolder;
}
.banner a{
color: black;
text-decoration: none;
letter-spacing:10px;
}
#bannerText{
text-align:center;
}
.banner{
font-family: sans-serif, Verdana, Geneva;
}
#phonenum{
font-family: sans-serif, Verdana, Geneva;
}
#info{
font-weight:bold;
color: #505050;
line-height:110%;
}
ul a{
color: #383838;
}
/* ----Desktop only---- */
#media screen and (min-width:481px) {
body{
background-image: url("images/water.jpg");
}
#info{
font-size: 200%;
float: right;
right:0px;
width: 230px;
margin: 15px 25px 0px 0px;
padding:15px 5px 5px 5px;
}
#info ul{
margin:0px;
padding-left:63px;
}
#phonelogo{
float:left;
width:30px;
}
#phonenum{
float:right;
width: 190px;
margin:0%;
font-size: 80%;
font-family: sans-serif, Verdana, Geneva;
}
.banner{
float:left;
padding-top:1px;
margin-left: 18px;
opacity: 0.7;
}
#banner{
margin-top: 20px;
}
.banner p{
margin:0px;
}
#bannerText{
letter-spacing: 5px;
margin-bottom:5px;
padding-left:5px;
}
.btn{display:none;}
#toolbar {
position: absolute;
margin:220px 0px 0px 16px;
opacity: 0.7;
}
.menu li a{
font-family: gabriola, Verdana, Geneva, sans-serif;
font-size: 140%;
font-weight: bold;
text-decoration: none;
color: black;
margin-right:30px;
}
.nav{
position: absolute;
list-style-type: none;
top:10px;
left:-33px;
}
.nav ul li{
display: inline;
}
.nav ul li a{
font-family: gabriola, Verdana, Geneva, sans-serif;
font-size: 140%;
font-weight: bold;
text-decoration: none;
color: black;
}
.nav ul li a:hover{
color: yellow;
}
<div id="homePage" class="page">
<div class="banner">
<p id="banner">
<a href="index.htm"><img src="images/Logo.png" alt="
Logo for site" /></a>
</p>
<p id="bannerText"><a href="Slogan link.htm">
Slogan under the Logo</a></p>
</div>
<div id="info">
<table>
<tr>
<td id="phonelogo"><img src="images/phoneimage.png" alt="
Mobile phone image" /></td>
<td id="phonenum">(08080) 080 080</td>
</tr>
</table>
<ul>
<li>Town A</li>
<li>Town B</li>
<li>Town C</li>
</ul>
</div>
<div id="toolbar">
<div>
<p id="toolBackground">
<img src="images/toolBackground.png" alt="
Coloured background for toolbar" />
</p>
</div>
<div class="dropdown">
<ul class="nav">
<li><img class="btn" src="images/menuIcon.png" alt="
Menu button for mobile site version" />
<ul class="menu">
<li>Page1</li>
<li>Page1</li>
<li>Page1</li>
<li>Page1</li>
<li>Page1</li>
<li>Page1</li>
<li>Page1</li>
</ul>
</li>
</ul>
</div>
</div>

Always use a css reset so the styling is the same between browsers.
Very minimal css reset I always use:
html,body,div,span,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,abbr,address,cite,code,del,dfn,em,img,ins,kbd,q,samp,small,strong,sub,sup,var,b,i,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,figcaption,figure,footer,header,hgroup,menu,nav,section,summary,time,mark,audio,video {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section {
display: block;
}
Then everything should look (mostly) the same between browsers.
Also keep in mind display: inline-block; adds spaces between elements based on the font-size.

Related

Navigation and title won't center

I'm so new to coding and for school we need to code a website. Right now I'm slowly rolling into it, but I can't get my navigation and title to center. On my 13 inch laptop it all looks fine, but on a bigger pc it isn't centered anymore.
This is the link to the website, it's a mess right now: http://st358373.cmd16c.cmi.hanze.nl/portfolio.html
Updated question:
How do I get my title and subtitle centered?
HTML code:
<div class="titel">Portfolio</div>
<div class="subtitel">Hier is een selectie van recentelijk werk.</div>
CSS:
.titel {
font-family: Raleway;
font-size: 52px;
color: #3b3d40;
text-align: center;
font-weight: 700;
margin-top: 20px;
}
.subtitel {
font-family: Adobe Caslon Pro;
font-size: 18px;
text-align: center;
margin-top: 40px;
margin-bottom: 50px;
}
One way would be:
ul.topnav li {
/* float: left; Remove this. */
display: inline-block;
}
ul.topnav {
text-align: center;
}
.titel {
font-family: Raleway;
font-size: 52px;
color: #3b3d40;
font-weight: 700;
text-align: center;
margin-top: 20px;
width: 100%;
}
ul.topnav {
list-style-type: none;
margin: 0;
overflow: hidden;
font-family: Raleway;
font-weight: 500;
/* float: center; */
text-align: center;
position: center center;
}
ul.topnav li {
/* float: left; */
display: inline-block;
}
ul.topnav li a {
display: inline-block;
color: #3b3d40;
text-align: center;
padding: 14px 16px;
text-decoration: none;
transition: 0.3s;
font-size: 10px;
letter-spacing: 2px;
}
ul.topnav li a:hover {
background-color: #555;
}
ul.topnav li.icon {
display: none;
}
<ul class="topnav" id="myTopnav">
<li>HOME
</li>
<li>PORTFOLIO
<div style="margin-top:-12px;border-bottom:1px solid #3b3d40;height:1px;"></div>
</li>
<li>BLOG
</li>
<li>PROJECTEN
</li>
<li>ONTWERPPROCES
</li>
<li>VERANTWOORDING
</li>
<li>OVER
</li>
<li>CONTACT
</li>
<li class="icon">
☰
</li>
</ul>
<div class="titel">Portfolio</div>
Use flex. The invisible item and the right div should have same width. You can add some content in invisible div and remove visibility:hidden;
.header{
height:60px;
background-color:green;
display:flex;
flex-direction:row;
align-items:center;
}
.header>div:first-child {
margin-right: auto;
visibility: hidden;
width:100px;
}
.header .navigation{
height:50px;
margin:0;
text-align:center;
color:white;
}
.header .right{
margin:0;
padding:0;
margin-left:auto;
width:100px;
}
.header .right img{
width:30px;
margin:0 5px;float:right;
}
<div class="header">
<div>invisible</div>
<div class="navigation">Navigation Bar</div>
<div class="right">
<img src="http://www.chinabuddhismencyclopedia.com/en/images/thumb/b/b8/Nature.jpg/240px-Nature.jpg"/>
<img src="http://images.financialexpress.com/2015/12/Lead-image.jpg"/>
</div>
</div>

Footer div alignment and text issue

I'm working on a footer that I'm trying to align items in as shown in the image(actually the logo image and text under it should be a little off the left side not stuck to it).
I'm pretty close but can't get it exactly how I want it. Whenever I try to make the footer smaller as it's a bit too big at the moment stuff leaks out of it. What am I doing wrong?
Also I can't seem to change the text under the footer logo image to be the same as the links. Not sure why that is?
My Fiddle
<div class="row-2">
<div class="logofooter">
<a class="logofooter" href="index.html"> <img src="http://lorempixel.com/output/abstract-q-c-100-100-1.jpg"></a>
<div class="logocopyright">
Copyright info
</div>
</div>
<div class="legal">
<ul class="legal">
<li>Legal Policy</li>
<li>Contact</li>
<li>Privacy</li>
<li>Disclaimer</li>
</ul>
</div>
<div class="social">
<ul class="smm">
<li><a class="facebook" href="https://www.facebook.com"> <img src="http://lorempixel.com/output/abstract-q-c-68-68-5.jpg"></a></li>
<li><a class="twitter" href="https://www.twitter.com"><img src="http://lorempixel.com/output/abstract-q-c-68-68-5.jpg"> </a></li>
<li><a class="instagram" href="https://www.instagram.com"><img src="http://lorempixel.com/output/abstract-q-c-68-68-5.jpg"> </a></li>
</ul>
</div>
</div>
</footer>
</body>
Does this work better for you?
http://codepen.io/anon/pen/vNXKMa?editors=110
It's using flexbox for the main 3 elements (logo, menu, social menu).
.row-2{
display:flex;
justify-content: space-between;
}
The children elements will be spaced evenly. You can also try space-around.
When you reduce the screen size, things have to stack up at some point.
You could also consider using bootstrap's grid for this kind of layout.
please try This one:
.site-footer, .page-wrap:after {
height: 250px;
}
.site-footer {
background: #919191;
}
.logofooter{
float:left;
padding-top:10px;
}
.logocopyright a {
font-size: 10px;
color: #fff;
text-decoration: none;
text-transform: uppercase;
}
.row-2 ul li a {
font-family: 'Arial Black', 'Arial Bold', Gadget, sans-serif;
text-decoration:none;
color:#fff ;
padding: 5px 15px;
font-size: 16px;
}
.row-2 p {
color:#fff;
font-family: 'Arial Black', 'Arial Bold', Gadget, sans-serif;
font-size: 16px;
}
.row-2 a {
font-size: 22px;
}
.row-2{
padding-top: 100px;
text-align:center;
margin-left:auto;
margin-right:auto;
}
.legal{
float:left;
margin-right:auto;
margin-left:-60px;
}
.legal a:hover {
color: #FFF;
-webkit-border-radius: 200px;
-moz-border-radius: 200px;
border-radius: 200px;
background: #1874CD;
}
.legal li {
display:inline-block;
text-align: center;
margin-left:20px;
}
.social{
float:right;
margin-top:-50px;
margin-left:auto;
}
.social li, h3{
font-size:10px;
display:inline-block;
text-align: center;
color:#fff;
}
.smm li{
margin-right:20px;
}
.facebook img
{
width:20px;
height:20px;
border-radius: 50%;
margin-left:90px;
}
.twitter img
{
width:20px;
height:20px;
border-radius: 50%;
margin-left:-30px;
}
.instagram img
{
margin-left:-40px;
width:20px;
height:20px;
border-radius: 50%;
}
See the Demo Page

Vertical align navigation link text

My aim is to have the text links to be central inline with the search text, however i want the border around each of the links to stay how they are. basically how to i centre the text without moving the border.
I have tried adding this to the links .home .reviews .store .contact, however this just moves the border.
padding-top:20px;
margin-top:20px;
Here is my HTML:
<div id="navigation">
<nav class="navbar">
<div class="navbarcontainer">
<ul class="nav navbar-nav">
<li class="home">Home</li>
<li class="reviews">Reviews</li>
<li class="store">Store</li>
<li class="contact">Contact</li>
</ul>
</div>
</nav>
Here is my CSS:
/* NAVIGATION */
li {
display:inline-block;
float:left;
border:1px black solid;
padding-left:12px;
padding-right:12px;
height:60px;
}
a:link, a:visited {
text-decoration: none;
color:#fff;
font-family: 'Open Sans', sans-serif;
font-size: 15px;
}
This is what it currently looks like : http://imgur.com/0GVums0
Thankyou for any help
You can use line-height property on links to vertically center:
a:link, a:visited {
text-decoration: none;
color:#fff;
font-family: 'Open Sans', sans-serif;
font-size: 15px;
line-height: 60px;
}
Or, you can also use vertical-align: middle, but keep in mind that this approach is not fully compatible with all browsers (IE8+).
li {
display:table;
float:left;
border:1px black solid;
padding-left:12px;
padding-right:12px;
height:60px;
}
a:link, a:visited {
text-decoration: none;
color:#fff;
font-family: 'Open Sans', sans-serif;
font-size: 15px;
display: table-cell;
vertical-align: middle;
}
One way to do it:
li {
display: block;
float: left;
border: 1px black solid;
}
a {
padding: 19px 12px;
display: block;
}
a:link, a:visited {
text-decoration: none;
color: #000;
font-family: 'Open Sans', sans-serif;
font-size: 15px;
}
Codepen example

Items pushing each other out the way

So I'm doing a horizontal website with individual sections which works fine but now that Ive added my menu i'm having trouble where its just ruining my whole content areas and background.
Ive tried using the z-index which has no effect whats so ever... and putting items before it just push it out the way too.
My CSS Nav Bar
#Navigation
{
margin: 0px;
padding: 20px 0px 0px 700px;
font-family: 'american_captainregular', Helvetica, Arial, sans-serif;
font-size: 55px;
float:left;
}
#Navigation ul, #Navigation li
{
margin: 0;
padding: 0;
display: inline;
list-style-type: none;
}
#Navigation a:link, #Navigation a:visited
{
float: left;
line-height: 14px;
margin: 0 10px 4px 10px;
text-decoration: none;
color: #999;
}
#Navigation a:hover { color: #000; }
My CSS For the image
#HomeText{
background-repeat: no-repeat;
background-image: url(Images/HomeText.png);
float:left;
height:158px;
width:450px;
margin-left:461px;
margin-top:126px;
}
The HTML
<div id="Content">
<div class="Tabs TabOne" id="HomeTab">
<ul class="MyNav" id="Navigation">
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
</ul>
<div id="HomeText"></div>
</div>
And just in case, the CSS for my Sections
.Tabs{
margin:0px;
bottom:0px;
float:left;
width:3500px;
}
.TabOne{
background: url(Images/BG1.jpg) no-repeat;
}
Ive never encountered this sort of issue with elements being pushed down the page as much as with this
http://jsfiddle.net/BoneStarr/AGfwn/

HTML Background repeat been cut off after scroll

Im trying to make a menu, its working well however, when i make the window smaller and scroll across, the background doesn't extend. Example:
The first image is in full screen and second image is after i have scrolled across the page. As you can see the background does not extend. Below is my CSS:
body{
padding: 0px;
margin: 0px;
font-family:Arial, Helvetica, sans-serif;
background-color: #717070;
}
.header{
background-image: url("img/bgsmall.png");
height: 100px;
background-repeat: repeat-x;
min-width: 1000px;
}
.logo{
margin-left:320px;
float:left;
}
#menu{
position: relative;
height: 100px;
text-align: center;
width:auto;
margin-left:600px;
min-width:1000px;
}
#menu ul{
list-style: none;
padding: 0;
margin: 0;
position:relative;
}
#menu li{
float: left;
display: inline;
padding-top:35px;
position:relative;
text-transform:uppercase;
}
#menu li a{
text-decoration: none;
padding-left: 32px;
padding-right: 32px;
font-size: 15px;
font-family: arial;
color: #ffffff;
text-align:center;
}
#menu li a:visited{
color: #ffffff;
}
#menu li a:hover{
color: #D86C00;
}
HTML CODE
<html>
<head>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="header">
<div id="menu">
<ul>
<li>page1</li>
<li>page2</li>
<li>page3</li>
<li>page4</li>
</ul>
</div></div>
</body>
</html>
Thanks in advance.
Add position:absolute; to your .header class.
It's your min-width:1000px; on the #menu that is causing this. Without knowing what layout it is that you want to achieve it's hard to say what you should do to replace this, but taking that out sorts out that particular issue
you can solve this problem by two way:
1-
body{
padding: 0px;
margin: 0px;
font-family:Arial, Helvetica, sans-serif;
background-image: url("img/bgsmall.png");
background-repeat: repeat-x;
background-color: #717070;
}
.header{
height: 100px;
}
2-
Remove "min-width: 1000px;" from header style