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>
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.
I've been working on a site that I've been using ems and % in as I want to make it responsive. It's my first time attempting this.
I had the same site working using px.
I'm having this issue where content in the header and footer is not re-sizing properly. The content moves down past their containers or overlaps other content.
I.e. say in my footer i have the parent content set to 100% width and then the children divs set to various percentages of it.
The children then move down out of their containers and even the footer itself when I re-size.
Here's My JsFiddle
In my code here I've just put the footer code as it will just look messy if I put it all
<footer class="site-footer">
<div class="leftfoot">
<div class="footercontent">
<div class="logocopyright">
Tali.Zorah 2015 ©
</div>
</div>
</div>
<div class="rightfoot">
<div class="legal">
<ul>
<li>CONTACT US</li>
<li>ABOUT US</li>
<li>LEGAL NOTICE</li>
<li>PRIVACY POLICY</li>
</ul>
</div>
<div class="social">
<ul class="socicons">
<li>
<a class="facebook" href="https://www.facebook.com"> <img src="http://placehold.it/350x150"></a>
</li>
<li>
<a class="twitter" href="https://www.twitter.com"><img src="http://placehold.it/350x150"></a>
</li>
<li>
<a class="instagram" href="https://www.instagram.com"><img src="http://placehold.it/350x150"></a>
</li>
</ul>
</div>
</div>
</footer>
And the footer CSS:
.footercontent{
position:absolute;
min-width:100%;
max-width:100%;
}
.logofooter{
float:left;
margin-left:2%;
min-width: 10%;
max-width: 10%;
min-height:100%;
}
.mysitefooter-logo {
min-height: 100%;
min-width:10%;
max-width:100%;
margin-top: -1%;
margin-right:1%;
}
.logocopyright{
float:left;
margin-top:5%;
margin-left:2%;
min-width:100%;
padding-top:1%;
}
.leftfooter{
min-width:10%;
max-width:15%;
float:left;
}
.rightfooter{
min-width:85%;
max-width:90%;
float:right;
}
.logocopyright a {
font-family: 'Arial Black', 'Arial Bold', Gadget, sans-serif;
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size:.6em;
}
.logocopyright a:hover{
color: #FFF;
-webkit-border-radius: 200px;
-moz-border-radius: 200px;
border-radius: 200px;
background: #1874CD;
}
.legal{
background-color:#009;
min-width:70%;
max-width:80%;
float:left;
}
.legal a:hover {
color: #FFF;
-webkit-border-radius: 200px;
-moz-border-radius: 200px;
border-radius: 200px;
background: #1874CD;
}
.legal ul li {
display:inline-block;
font-family: 'Arial Black', 'Arial Bold', Gadget, sans-serif;
font-size:.8em;
margin-left:8%;
min-width:10%;
max-width:100%;
}
.legal ul > :first-child {
margin-left:5%;
}
.legal a {
font-size:1em;
color:#FFF;
}
.social{
min-width:15%;
max-width:20%;
float:right;
margin-top: -4%;
color:#000000;
}
.social li {
display:inline-block;
}
.socicons{
min-width:80%;
max-width:100%;
}
.socicons li{
display:inline;
}
.facebook{
min-width:8%;
max-width:10%;
}
.facebook img
{
min-width:8%;
max-width:20%;
}
.twitter{
min-width:8%;
max-width:10%;
}
.twitter img
{
min-width:8%;
max-width:20%;
}
.instagram{
min-width:8%;
max-width:10%;
}
.instagram img
{
min-width:8%;
max-width:20%;
}
If you want a responsive site absolute positioning is not a good idea. Just use a width of 100% and try using viewport(vw) width instead of ems.
maybe I fixed a little. I updated:
'id' into footer tag.
little jscript.
here's my js code:
var footer = document.getElementById("guestAttempt");
footer.setAttribute("float","left");
footer.setAttribute("margin-left","3em");
footer.setAttribute("margin-bottom","0em");
https://jsfiddle.net/unt5zbL8/6/embedded/result/
I'm doing a project on recreating the Google homepage with html and css. I am for the most part finished with the project, but I've noticed a few quirks that are irritating me. I've spent a great deal of time on each of these quirks, but can't get things to way I want them to look. These are the following quirks:
The icon in the top right-hand corner isn't inline with the rest of the text.
For some reason I can't center the buttons properly.
Not sure how to handle the white space surrounding the grey footer.
JSFiddle of The Code
If you have any input on any of the above issues, I would forever be thankful!
<body>
<div id="wrapper">
<div id="header">
<ul class="navbar">
<li class="navli"> +You
</li>
<li class="navli">Gmail
</li>
<li class="navli">Images
</li>
<li class="navli" id="icon">
<img src="http://bit.ly/1NHEwTW" height="auto" width="30" />
</li>
<li class="navli">theonlybrianlie#gmail.com
</li>
</ul>
</div>
<div id="body">
<div class="logo">
<img src="https://www.google.com/images/srpr/logo11w.png" />
</div>
<div class="searchbar">
<input type="text" id="search1" />
</div>
<div id="buttons">
<input class="button" id="googlesearch" value="Google Search" type="submit">
<input class="button" id="secondbutton" value="I'm Feeling Lucky" type="submit">
</div>
</div>
<div id="footer">
<div id="leftfoot">
<ul>
<li class="lf"> Advertising
</li>
<li class="lf"> Business
</li>
<li class="lf"> About
</li>
</ul>
</div>
<div id="rightfoot">
<ul>
<li class="rf"> Privacy
</li>
<li class="rf"> Terms
</li>
<li class="rf"> Settings
</li>
</ul>
</div>
</div>
</div>
.button {
font-family:Arial;
font-size:11px;
font-weight:bold;
display:inline;
height:30px;
border:1px solid #dcdcdc;
background:#f2f2f2;
padding-left: 10px;
}
body, html {
height:100%
}
#wrapper {
min-height:100%;
position: relative;
padding:0;
margin:0;
}
.logo img {
display:block;
width: 269px;
height:95px;
margin:auto;
margin-top: 80px;
padding-top: 112px;
}
#header {
width:100%;
height:100px;
/*background-color:green*/
;
}
.navbar {
/*background-color: red;*/
float: right;
}
.navli {
display: inline-block;
font-family: Arial;
}
.navli a {
text-decoration:none;
color: #404040;
font-size: 13px;
padding-left: 15px;
}
.navli a:hover {
text-decoration:underline;
}
#icon {
margin-top:10px;
padding-left:15px;
bottom:0;
position:relative;
}
.searchbar {
width:400px;
height:28px;
margin: auto;
display:block;
/*background-color:red;*/
padding-top:10px;
}
#search1 {
width:400px;
height:28px;
margin: auto;
}
#buttons {
display:block;
/*background-color:blue;*/
height: 22px;
width:250px;
margin: auto;
margin-top: 10px;
}
#footer {
position: absolute;
bottom:0;
height:60px;
width:100%;
background-color:#f2f2f2;
clear:both;
display:block;
border-top: 1px solid #e4e4e4;
}
#leftfoot {
width:300px;
left:0;
/*background-color:blue;*/
display: inline-block;
}
.lf {
display: inline-block;
}
.lf a {
text-decoration:none;
color: #404040;
font-size: 13px;
font-family: Arial;
padding-left: 15px;
}
.lf a:hover {
text-decoration: underline;
}
#rightfoot {
width:250px;
float:right;
/*background-color:blue;*/
padding:0;
margin:0;
}
.rf {
display: inline-block;
margin:auto;
}
.rf a {
text-decoration:none;
color: #404040;
font-size: 13px;
padding-left: 15px;
font-family: Arial;
}
.rf a:hover {
text-decoration: underline;
}
For your top right icon not inline with the rest of the menu, i would alter the CSS like this
.navli {
display: inline-block;
font-family: Arial;
float: left;
height: 30px;
line-height: 30px;
}
#icon {
/* margin-top: 10px; */
padding-left: 15px;
/* bottom: 0; */
/* position: relative; */
}
For your buttons not centering:
Add text-align:center; to #buttons
And for the white space on footer:
There's a margin on your body, so change your body,html to this:
body, html {
height: 100%;
margin: 0;
}
UPDATE
Here's the JSFiddle - Full Screen Preview - JSFiddle View
I'll try to answer these as concisely as possible:
1- the heading is inline, and your icon is taller than the rest of the inline elements. play with the margin and padding for your text elements there.
2- place your buttons in a div or section element of their own, and use text-align: center to center them on the page
3- add a class="container-fluid" to your footer element.
I'm trying to create a fixed header that sticks to the top on scroll. I have one wrapper (#topbarwrapper) that should fit 100% across the entire browser. I also have another div wrapper (.topbarcontentWRAPPER ) inside the(#topbarwrapper) which includes logo and navigation (#mainNav). One floats to the left and the other floats to the right. They both float as they should but it seems as if when the browser is resized, the divs move. I want the two divs floating inside to be centered with the entire page. The layout is responsive so the body width is 90%. I spent several days trying to figure this out including research. Any help would be appreciated.
Ideal goal is to have the header with 100% width fixed and centered.
Layout View:
http://s30.postimg.org/so036qarl/Screen_shot_2014_03_10_at_1_53_42_AM.jpg
HTML:
<body>
<div id="topbarWRAPPER">
<div class="topbarcontentWRAPPER">
<nav id="mainNav" role="navigation">
<h2 class="hidden">Main Site Navigation</h2>
<?php if ($this->countModules('nav')): ?>
<jdoc:include type="modules" name="nav" />
<?php endif; ?>
</nav>
</div>
</div>
<div id="mobilelogo"></div>
<div id="imageshow">
</div>
<div class="wrap">
<div class="miscellaneousRow">
</div>
<div class="search">
</div>
</div>
<section><h2 class="hidden">Recent News</h2>
<article id="recentNews">
<jdoc:include type="component" />
</article>
</section>
<aside>
<div class="sideBOX"> <section>
<h1 class="sideHeader">MAILING LIST</h1>
<div class="signup">
</section> </div>
<div class="sideBOX"> <section>
</section></div>
<div class="tabviewTABS"> <section>
</section>
</div> </aside>
<footer id="mainbottomFooter">
<div class="footerFLOATLEFT">
<h1 class="hidden">Footer</h1>
<div class="floatone">
</div>
</div>
</footer>
<div class="secondbottomFooter"> <div class="secondbottomfooterRight">
<nav id="sidenav">
<ul>
<li>
l
</li>
<li>
f
</li>
<li>
g
</li>
<li>
x
</li>
<li>
!
</li>
</ul>
</nav>
</div>
<div class="secondbottomfooterLeft"> content</a></div>
</div>
</html>
body {
width:90%;
margin:0 auto;
min-width:1024px;
max-width:1580px;
}
.latest-post clearfix{
display:hidden;}
.imageshow {
position:relative;
width: 100%;
}
.blog-readmore{
font-size: 24px;
display: inline;
width: 180px;
text-transform:uppercase;
margin-top:20px;
}
.blog-readmore a:link{
font-family: arial;
color: #690000;
}
.blog-readmore a:visited{
color: #690000;
}
.blog-readmore a:hover{
color: #eee;
}
#topbarWRAPPER{
position:fixed;
left: 0px;
right: 0px;
background-color:#000;
z-index:1000;
text-align:center;
}
.topbarcontentWRAPPER {
display:block;
height:50px;
background-color: #1E1E1E;
width: 90%;
margin: 0 auto;
}
#topbarLOGO
{
background-image:url("http://strip2.png");
background-repeat:no-repeat;
display:block;
float:left;
height:50px;
width:250px;
text-indent:-9999px;
}
aside{
background-color: #d6d6d6;
width: 29.1%;
padding-left:1%;
height: 100%;
float: right;
overflow: none;
color: #fff;
font-size:10px;
padding-bottom:1000em;
margin-bottom:-1000em
}
/* Blog content */
#recentNews {
width: 65.1%;
float: left;
padding-right:2%;
padding-left:2%;
padding-bottom:2%;
background-color:#fff;
padding-bottom:1000em;
margin-bottom:-1000em;
}
.wrap{ overflow:hidden;
background-color:#fff;
}
/* ~~ Bottom footer ~~ */
#mainbottomFooter{
background-color:#000;
position:relative;
height: 300px;
clear: both;
padding:15px 0;
min-width:100%;
}
.footerFLOATLEFT li{
list-style-type: none;
padding-bottom: 1em;
padding-top: 1em;
}
.footerFLOATLEFT a:link{
font-size:12px;
color: #555555;
text-transform:uppercase;}
.footerFLOATLEFT a:visited {
font-size:12px;
color: #555555;
text-transform:uppercase;}
.footerFLOATLEFT a:hover {
font-size:12px;
color: #690000;
text-transform:uppercase;}
/* ~~ P~~ */
p{
font-size: 17px;
color: #000;
line-height:140%;
font-family: 'HelveticaNeue';
padding-left: 1%;
padding-right:1%;
font-weight:bold;
}
h3 {
margin-bottom: 0px;
font-size: 2em;
color: #690000;
font-family: 'Lato', sans-serif;
font-weight:300;
text-transform:uppercase;
padding-bottom:1em;
padding-top:1em;
}
.floatone {
float:left;
padding-right: 4em;
padding-top: 4em;
height: 100%;}
.floattwo {
float:left;
height: 100%;
padding: 4em;}
.floatthree {
float:left;
height: 100%;
padding: 4em;}
.floatfour {
float:left;
height: 100%;
padding: 4em;}
.signup {
width:100%;}
.footerFLOATLEFT {
width:100%;
float:left;
}
.secondbottomFooter {
width: 100%;
height:40px;
background-color:#690000;
border-top:1px solid #222;
border-bottom:1px solid #222;
color: #fff;
font-size: 12px;
padding-top:2em;
padding-bottom:2em;
text-align:right;
}
h2 {font-face:arial;
font-size:12px;
color: #fff;
padding-top: 1em;
padding-bottom: 1em;}
#sidenav {
}
#sidenav li {
display:inline;
}
#sidenav a:link{
font-family: 'socialicoregular', Arial, sans-serif;
font-size:5em;
color: #eee;
text-decoration:none;
}
#sidenav a:visited{
color: #fff;
text-decoration:none;
}
#sidenav a:hover{
color: #690000;
text-decoration:none;
}
.miscellaneousRow {
background-color: #000;
width: 100%;
height:100px;
position:relative;
}
.twitterFeed {float:left;
padding-top: 10px;
padding-bottom: 10px;
width: 65.1%;
}
.search {
float: right;
padding:2%;
width: 26%;}
#mainNav {
float:right;
}
.sideDivider {
background-color:#222;
height:auto;
margin-bottom:10%;
padding-top:10%;
padding-bottom:5%;
padding-left:5%;
padding-right:5%;
}
.tabviewTABS {
background-color:#222;
height:auto;
margin-bottom:20%;
padding-top:10%;
padding-bottom:5%;
padding-left:5%;
padding-right:5%;
}
.sideBOX {
background-color:#222;
height:auto;
margin-bottom:10%;
padding-top:10%;
padding-bottom:5%;
padding-left:5%;
padding-right:5%;
text-align:center;
}
.soundcloud {
background-color:#222;
position:relative;
height:auto;
clear: both;
padding:15px 0;
min-width:100%;
}
.soundcloudtitle {
font-family: 'Droid Serif', serif;
color: #fff;
font-size: 2em;
text-align:right;
text-transform: uppercase;
margin-bottom: 1em;
border-bottom: 5px solid #690000;
}
.secondbottomfooterRight p{
padding-right:3em;
padding-bottom:1em;
}
.hidden
{
position: absolute !important;
clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
clip: rect(1px, 1px, 1px, 1px);
}
You're setting the left and right positions of your topbarWRAPPER to 0px instead of 5%.
See this fiddle.
EDIT:
I see what you mean. I've updated the fiddle. It should be what you need.
EDIT #2:
Alrighty. Forgive me, I didn't notice this earlier. You've assigned the body a width in percent but a min and max width in pixels. If you remove the min and max widths you'll see the behavior you're looking for, but what I think you should do is assign the 70% width to .wrap and give it a margin:0 auto;