I've read through countless posts about this looking for a solution but can't seem to find one that works for me. I've built a fairly basic portfolio site, and am trying to build it such that the first thing you see on load is the word 'Developer', and you then scroll down to the portfolio.
I've given my portfolio header a top padding to fill the screen, but can't get the word 'Developer' to center within that. I'm pretty new so have probably done something very wrong!
HTML:
<header id="hero">
<div id="hero_text">Developer.</div>
<img class="arrow" src="Images/lake_tahoe_img/arrow.svg" alt="Down arrow"></a>
<a href="index.html" id="logo">
<h1>Rob Wood</h1>
<h2>Front-end Developer</h2>
</a>
<nav>
<ul>
<li>Portfolio</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</header>
CSS:
#hero {
padding-top: 800px;
z-index: -2;
}
#hero_text {
position: fixed;
margin-left: auto;
margin-right: auto;
top: 35%;
color: white;
font-size: 9em;
font-family: 'Open Sans', sans-serif;
font-weight: bold;
}
.arrow {
width: 50px;
top: 70%;
position: center;
padding-left: 50%;
position: fixed;
}
Add to your #hero_text text-align:center. Remove position:fixed
The problem with position:fixed is the element is made like an absolutely positioned element and will cause it to collapse unto itself giving it no width and, therefore, nothing to center within.
An alternative would be to leave the fixed positioning but give that element a width. Along with auto margins, which you set, this will center the element plus center the text within the same element.
As mentioned in the comments, there is no such thing as position:center.
you want something like this??
to position developer in the center of the page i used display:flex; justify-content:center and align-items:center; like this, the words developer always stays in the center
body{
margin: 0px;
}
.box{
background-color: pink;
background-size: cover;
height: 100vh;
position: relative;
display:flex;
justify-content: center;
align-items: center;
}
h1{
font-size:25px;
}
.down{
height: 100px;
}
<div class="box">
<h1>
Developer
</h1>
</div>
<div class="down">
<p>
the rest of the page
</p>
</div>
I think you're looking for something like this :
.outer-container {
position: fixed;
display: table;
width: 100%;
height: 100%;
background: #ccc;
}
.inner-container {
display: table-cell;
vertical-align: middle;
text-align: center;
}
#hero {
display: inline-block;
background: #fff;
}
#hero_text {
font-size: 9em;
font-family: 'Open Sans', sans-serif;
font-weight: bold;
}
#hero ul {
list-style-type: none;
}
<div class="outer-container">
<div class="inner-container">
<header id="hero">
<div id="hero_text">Developer.</div>
<img class="arrow" src="Images/lake_tahoe_img/arrow.svg" alt="Down arrow">
<a href="index.html" id="logo">
<h1>Rob Wood</h1>
<h2>Front-end Developer</h2>
</a>
<nav>
<ul>
<li>Portfolio</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</header>
</div>
</div>
(see also this Fiddle)
In the following solution, one drawback is that you have to fix a height and a line-height to the outside div (the gray one).
.abs-center {
position: absolute;
top: 0; bottom: 0;
left: 0; right: 0;
margin: auto;
}
.v-center {
background: yellow;
display: inline-block;
vertical-align: middle;
line-height: normal;
}
#graybox {
height: 120px;
line-height: 120px;
background: #bbb;
text-align: center;
}
<div id="graybox" class="abs-center">
<div class="v-center">
<p>vertically<br />centered</p>
</div>
</div>
Related
I would like to make my tag is big as the parent div (#logo, and i'm having trouble making a 100% padding without making it bigger than the parent's tag.
HTML
<div id="header">
<div id="logo">
</div>
<div class="hide" id="navigation">
<ul>
<li>About</li>
<li>Examples</li>
<li>Form</li>
<li>Contact</li>
</ul>
</div>
</div>
CSS
div#logo {
background: url(https://i.imgur.com/sHTtXk4.png) no-repeat center center;
background-size: cover;
float: left;
line-height: 80px;
width: 10%;
height: 80px;
text-align: center;
}
div#logo a {
background: #fff;
width: 100%;
height: 100%;
padding: 100%;
https://jsfiddle.net/vwbo9exg/
Remove padding and add display for a tag
div#logo a {
background: #fff;
width: 100%;
height: 100%;
/* padding: 100%; */
display: inline-block; /*Add this*/
}
I will explain my problem.
For school I have to make a website, but it is not working how it should be.
I have a border made of divs around the screen, and the page in the middle. When I first open the page, everything is in place, but when I click on one of the nav items (#link) the page suddenly loses its margin top and left. So it goes outside of the borders. I pasted all the code in the snippet, as I believe it will be too much for a post.
To see the full page and problem, please copy the code in a file to open it in the browser itself. I used vw and vh because it want it to be the same on different screens. I will do the inside elements mostly with percentages
So my questions:
How do I prevent this from happening, and an example?
Is there a way to set #Home as the usual landing space? without adding #Home in the link (and without changing its position)?
And my last question regarding CSS animation, how do I add a transition so it looks like the page is scrolling to the #div.
body{
top: 0;
margin: 0;
padding: 0;
left: 0;
}
.wrapper{
width: 100vw;
height: 100vh;
overflow: hidden;
}
.container{
width: 300vw;
height: 200vh;
background-image: url("../img/background.png");
background-size: cover;
}
/* simple nav*/
ul{
display: inline;
z-index: 99;
position: fixed;
}
ul li{
list-style-type: none;
display: inline;
}
ul li a{
text-decoration: none;
}
/*pages*/
.page{
margin: 10vh 10vw;
width: 80vw;
height: 80vh;
transition: 2s;
}
#Interactive{
background: blue;
float: left;
}
#Graphical{
float: left;
}
#Company{
float: left;
}
#Conclusion{
float: left;
}
#Home{
float: left;
}
/*header borders*/
.borders{
position: fixed;
z-index: 30;
}
.border-top{
height: 10vh;
width: 100vw;
top:0;
background: #007CFF;
}
.border-left{
height: 100vh;
width: 10vw;
top: 0;
background: #007CFF;
position: absolute;
}
.border-right{
height: 100vh;
width: 10vw;
top: 0;
background: #007CFF;
float: right;
margin-top: -10vh;
}
.border-bottom{
height: 10vh;
width: 100vw;
bottom: 0;
background: #007CFF;
position: absolute;
}
<div class="header">
<ul>
<li>Home</li>
<li>Interactive</li>
<li>Graphical</li>
<li>Company</li>
<li>Conclusion</li>
</ul>
</div>
<div class="borders">
<div class="border-top">
</div>
<div class="border-left">
</div>
<div class="border-right">
</div>
<div class="border-bottom">
</div>
</div>
<div class="wrapper">
<div class="container">
<div id="Interactive" class="page">
</div>
<div id="Graphical"class="page">
</div>
<div id="Company"class="page">
</div>
<div id="conclusion"class="page">
</div>
<div id="home"class="page">
</div>
</div>
</div>
Thanks for thinking with me, any help is appreciated.
I didn't really know how to call this post, so the search for it was difficult.
Please remove this div
#Interactive{
background: blue;
float: left;}
I think this only you are expecting.
I have made changes to your HTML code and CSS code on the basis of what i thought you wanted to achieve. Below is the code.
* {
padding: 0;
margin: 0;
}
body{
display: flex;
flex-direction: column;
}
.header {
padding: 10px 50px;
}
ul li{
list-style-type: none;
display: inline-block;
padding: 10px;
}
.wrapper {
flex-grow: 1;
padding: 50px 150px;
}
.page{
transition: 2s;
width: 100%;
height: 100%;
}
#Home{
background-color: pink;
}
#Interactive{
background: blue;
}
#Graphical{
background-color: green;
}
#Company{
background-color: yellow;
}
#Conclusion{
background-color: orange;
}
<div class="header">
<ul>
<li>Home</li>
<li>Interactive</li>
<li>Graphical</li>
<li>Company</li>
<li>Conclusion</li>
</ul>
</div>
<div class="wrapper">
<div id="Home" class="page">
</div>
<div id="Interactive" class="page">
</div>
<div id="Graphical" class="page">
</div>
<div id="Company" class="page">
</div>
<div id="Conclusion" class="page">
</div>
</div>
If you want to use transition for smooth scrolling. Refer to
this
article, you will have to use jQuery.
Also do not use fixed width or height until necessarily required.
Use document.getElementById('Home').focus() in document.ready() of js to bydefault show the Home Page.
Always focus on making responsive solutions with relative content rather than absolute content.
Let me know if you need more help :)
I'm trying to horizontally and vertically align my banner text like so:
I have been searching around for the best way possible and have found it very difficult. It could be something really easy that i've missed and wasted a few hours on but I guess that's learning!
This is my html
<header class="fullscreen" style="background-image: url('images/bg.png');">
<div class="logo-wrapper text-center">
<img id="logo" src="" alt="The South-West Skateboarding (SWSB) logo." />
</div>
<nav id="primary" class="text-center">
HOME |
ABOUT |
TEAM |
GALLERY |
FORUM |
LOGIN
</nav>
<div id="banner" >
<h1>SOUTH-WEST SKATEBOARDING</h1>
<p>EST. 2016</p>
</div>
</header>
And css (sorry it's in sass, shouldnt make much of a difference)
header {
padding: 50px 0 50px 0;
height: 100%;
.logo-wrapper {
margin: 0 auto;
width: 100%;
img#logo {
width: 140px;
height: 85px;
}
}
nav#primary {
margin-top: 25px;
a {
color: $nav-link-color;
font-weight: 100;
letter-spacing: 2.15px;
text-decoration: none;
text-transform: uppercase;
}
}
#banner {
h1 {
margin-bottom: 0;
}
p {
margin: 0;
}
}
Here is the demo
#banner {
width: 100%;
height: 400px;
background-color: yellow;
display: flex;
align-items: center;
justify-content: center
}
major edits, please re-open
Creating a page with Bootstrap 2.3.2 that will later become a template for Joomla 3.x.
In the header, I have 6 elements. I was able to position them as shown below.
problem
is positioning the nav-pills section quite at the bottom of the container that has image as background-image.
setting margin-top on the .minimenu container of the nav-pills does work, but relates it to the top. I'd like to relate it to the bottom.
vertical-align: bottom; has been tried with no solution.
HTML code:
<div class="container">
<p class="headtitle">This is the Headline on Top!</p>
<div class="header">
<img src="http://www.chris-nlp-hall.com/tmp/logo1.png" class="pull-left logo1" />
<img src="http://www.chris-nlp-hall.com/tmp/logo2.png" class="pull-right logo2" />
<div class="mininav">
<ul class="nav nav-pills">
<li>Link1</li>
<li>Link2</li>
<li>Link3</li>
</ul>
</div>
</div>
<div class="navbar">
<div class="navbar-inner">
<ul class="nav">
<li>Home</li>
<li>Learn</li>
<li>More</li>
</ul>
</div>
</div>
</div>
CSS:
p.headtitle {
text-align: center;
font-size: 1.4rem;
}
.header {
background-image: url(http://www.chris-nlp-hall.com/tmp/center.png);
background-position: center top;
background-repeat: no-repeat;
height: 160px;
}
.mininav {
text-align: center;
vertical-align: bottom; /* doesn't work */
}
.mininav .nav-pills {
display: inline-block;
}
.header .logo1 {
margin-left: 10px;
}
.header .logo2 {
margin-right: 10px;
}
see this updated fiddle: https://jsfiddle.net/michi001/srzwz8o4/
In bootstrap you can use pull-left and pull-right classes for the logos and navpills can be centered using text-center class in a parent div.
Best option for the background seem to be place it via CSS using background-image.
Then why don't you just position absolute to the bottom?
.mininav{
position: absolute;
bottom: 0px;
width: 100%;
}
you will also need to set .header as relative:
.header { position:relative; }
.header {
position: relative;
background-image: url(http://www.chris-nlp-hall.com/tmp/center.png);
background-position: center top;
background-repeat: no-repeat;
height: 160px;
}
.mininav {
text-align: center;
position: absolute;
bottom: 0;
right: 0;
left: 0;
}
Added relative postion in .header and modified .mininav class
I have fixed your issue JS Fiddle
.mininav {
right: 0;
left: 0;
bottom: 0;
min-height: 30px; /*or other value*/
max-height: 30px; /*or other value*/
position: absolute;
}
.mininav p {
line-height: 30px;
}
This must be the most frequently occurring issue in my life!
I have to position a fixed DIV (800px) inside a 100% DIV and as always it works fine in everything but IE. I have tried the old "text-align" trick but nothing this time, I just can't get it to work.
If you want to inspect the actual page its www.chunkydesign.com and any answer would be greatly appreciated.
Here is the HTML (CSS Below)
<body>
<div id="navContainer">
<div id="navTopSpacer"></div>
<div id="navMain">
<div id="navContent">
<div id="navLogo"></div>
<div id="navLinks">
<h1>SERVICES ABOUT PORTFOLIO CONTACT</h1>
</div>
</div>
</div>
<div id="navBotSpacer"></div>
</div>
</body>
The devil code itself:
body {
padding: 0px;
margin: 0px;
}
navContainer{
width: 100%;
height: 110px;
}
navTopSpacer {
width: 100%;
height: 12px;
background-image: url('../images/core/nav_topspacer.jpg');
}
navMain {
width: 100%;
height: 88px;
background-image: url('../images/core/nav_main.jpg');
}
navContent {
text-align: center;
width: 800px;
height: 88px;
margin-left: auto;
margin-right: auto;
}
navLogo {
float: left;
width: 164px;
height: 88px;
background-image: url('../images/core/logo.png');
background-position: 0px 20px;
background-repeat: no-repeat;
}
navLinks {
float: right;
width: 400px;
height: 88px;
}
navLinks h1 {
font-family: Arial, Verdana, sans-serif;
text-align: right;
font-size: 13px;
color: #FE9900;
font-weight: 600;
padding-top: 40px;
word-spacing: 15px;
letter-spacing: 1px;
margin: 0px;
}
navBotSpacer {
width: 100%;
height: 10px;
background-image: url('../images/core/nav_botspacer.jpg');
}
By leaving a comment above your doctype you're making IE go into quirks mode, which makes rendering a nightmare.
Remove the comment and have NO text, spaces or anything above your doctype declaration.
Try using this markup:
<div id='header'>
<div class='center'>
<div id='logo'><h1><a href='' title=''></a></h1></div>
<ul id='navigation'>
<li>SERVICES</li>
<li>ABOUT</li>
<li>PORTFOLIO</li>
<li>CONTACT</li>
</ul>
</div>
</div>
And styling like this:
#header{
background:#cae1e9;
border-top:12px solid #7ebdce;
border-bottom:10px solid #a8d2de;
height:88px;
}
.center{
width:800px;
margin:auto;
}
Then just maybe float logo to the left and float navigation to the right or do whatever you want. But this kind of makup is much easier to understand and maybe see where is the error.
Combine that with the answer Paul gave you and i think that's it.