New Elements added to the bottom of the page - html

I'm coding a webpage using CSS and PHP. Whenever I add a new element it's pushed down to the bottom of the page. I thought it was a one time thing only affecting a paragraph so I added negative margins for it (not great practice, I know), but every element I add is getting pushed to the end of the page and I have to scroll to find it.
The paragraph below was the part getting pushed down, the login heading remained at the top, but when I tried adding more text after, it got pushed down as well.
#import url('https://fonts.googleapis.com/css2?family=Urbanist:wght#500&display=swap');
* {
width: 100%;
height: 100%;
}
h1 {
color: white;
font-family: 'Urbanist', sans-serif;
font-size: 30px;
line-height: 0px;
margin-bottom: 0px;
}
p {
color: white;
font-family: 'Urbanist', sans-serif;
font-size: 20px;
line-height: 0px;
margin-top: -740; //I added negative margins because this element was being pushed downwards and that solved it, but I don't want to have to do it with every new element.
}
body {
padding: 0;
margin: 0;
}
header {
height: 60px;
background-color: #1e3799;
}
ul {
float: right;
right: 30%;
}
ul li {
display: inline;
list-syle: none;
}
ul li a {
text-decoration: none;
color: white;
font-family: 'Urbanist', sans-serif;
font-size: 18px;
padding: 0px 0px 0px 20px;
}
footer {
position: absolute;
bottom: 0%;
width: 100%;
height: 60px;
background-color: #1e3799;
text-align: center;
margin: 0 auto;
}
footer p {
color: white;
font-family: 'Urbanist', sans-serif;
}
body {
background-color: #4a69bd;
}
<h1>Log In</h1>
<p> No Account?<a href="register.php">Register here!</p>

Don't use width and height 100% for *.
This * means use it every element on
p {
color: white;
font-family: 'Urbanist', sans-serif;
font-size: 20px;
line-height: 0px;
margin-top: -740; /* You forgot to add 'px' here */
}
Change this to these to full page with preserving background color.
* {
padding: 0;
margin: 0;
}
body {
width: 100%;
height: 100%;
}
You also forgot to close <p> No Account?Register here!</p> tag.
I don't suggest you use this if you don't know what you are doing line-height: 0px;
Here is complete fixed code. I aligned some items because the way of coding I thought you want to center footer items.
* {
padding: 0;
margin: 0;
}
h1 {
color: white;
font-family: 'Urbanist', sans-serif;
font-size: 30px;
/* line-height: 0px; */
margin-bottom: 0px;
}
p {
color: white;
font-family: 'Urbanist', sans-serif;
font-size: 20px;
/* line-height: 0px; */
/* margin-top: -740; */
/* You forgot to add 'px' here */
}
body {
background-color: #4a69bd;
width: 100%;
height: 100%;
}
footer {
position: absolute;
bottom: 0%;
width: 100%;
height: 60px;
background-color: #1e3799;
}
footer, p {
display: flex;
justify-content: center;
align-items: center;
color: white;
font-family: 'Urbanist', sans-serif;
}
a {
margin-left: 10px;
color: white;
}
<h1>Log In</h1>
<footer>
<p> No Account?Register here!</p>
</footer>

It may be because you have given all (*) a height of 100% in your css

Related

How to align an element to the right while staying vertically centered?

I want the 'William Marchesi' and 'Contact' Text centered vertically with the 'Contact' Button on the right of the header. When I try a float: right, the contact text moves so that it is higher than the 'William Marchesi' text.
html {
height: 100%;
background-repeat: no-repeat;
background-color: green;
}
body {
font-size: 87.5%;
/* Base font size on 14px */
font-family: sans-serif;
line-height: 1.5;
text-align: justify;
margin: 0 auto;
padding: 0;
}
a {
text-decoration: none;
color: inherit;
}
.header div {
margin: 0 auto;
width: 70%;
clear: both;
padding: 0;
}
.header {
background-color: #FCFCFC;
width: 100%;
padding: 0;
margin: 0 auto;
/*height: 5em;*/
}
.heading,
.contactButton {
display: inline-block;
padding: 0;
margin: 0;
vertical-align: middle;
line-height: 3em;
height: 3em;
font-family: 'Nunito', sans-serif;
}
.heading {
font-size: 3em;
padding: 0;
margin: 0;
}
.contactButton {
font-size: 2em;
text-align: right;
padding: 0;
margin: 0;
float: right;
}
<body class="body">
<div class="header">
<div>
<h1 class="heading">William Marchesi</h1>
<a class="contactButton" href="#contact">Contact</a>
</div>
</div>
</body>
Here's one of many possible solutions, using position:absolute on the contact button.
html {
height: 100%;
background-repeat: no-repeat;
background-color: green;
}
body {
font-size: 87.5%; /* Base font size on 14px */
font-family: sans-serif;
line-height: 1.5;
text-align: justify;
margin: 0 auto;
padding: 0;
}
a {
text-decoration: none;
color: inherit;
}
.header div {
margin: 0 auto;
padding: 0;
text-align:center;
}
.header {
background-color: #FCFCFC;
padding: 0;
}
.heading, .contactButton {
padding: 0;
margin: 0;
vertical-align: middle;
line-height: 3em;
font-family: 'Nunito', sans-serif;
}
.heading {
font-size: 3em;
padding: 0;
margin: 0;
}
.contactButton {
font-size: 2em;
text-align: right;
padding: 0;
margin: 0;
position:absolute;
top:0.8em;
right:1em;
}
<div class="header">
<div>
<h1 class="heading">William Marchesi</h1>
<a class="contactButton" href="#contact">Contact</a>
</div>
</div>
You can use margin-left instead of float
html {
height: 100%;
background-repeat: no-repeat;
background-color: green;
}
body {
font-size: 87.5%; /* Base font size on 14px */
font-family: sans-serif;
line-height: 1.5;
text-align: justify;
margin: 0 auto;
padding: 0;
}
a {
text-decoration: none;
color: inherit;
}
.header div {
margin: 0 auto;
width: 70%;
clear: both;
padding: 0;
}
.header {
background-color: #FCFCFC;
width:100%;
padding: 0;
margin: 0 auto;
/*height: 5em;*/
}
.heading, .contactButton {
display: inline-block;
padding: 0;
margin: 0;
vertical-align: middle;
line-height: 3em;
height: 3em;
font-family: 'Nunito', sans-serif;
}
.heading {
font-size: 3em;
padding: 0;
margin: 0;
}
.contactButton {
font-size: 2em;
text-align: right;
padding: 0;
margin-left: 59%;
}
Here's a flexbox solution that makes centering simple and easy:
body {
background-color: green;
font-size: 87.5%;
margin: 0;
padding: 0;
}
.header {
display: flex;
justify-content: space-around; /* horizontal alignment of children */
align-items: center; /* vertical alignment of children */
height: 6rem;
background-color: #FCFCFC;
}
.heading {
font-size: 3em;
font-family: 'Nunito', sans-serif;
}
.contactButton {
font-size: 2em;
font-family: 'Nunito', sans-serif;
}
a {
text-decoration: none;
color: inherit;
}
<body class="body">
<div class="header">
<h1 class="heading">William Marchesi</h1>
<a class="contactButton" href="#contact">Contact</a>
</div>
</body>
jsFiddle
More about flex centering here:
How to Center Elements Vertically and Horizontally in Flexbox
Center and right align flexbox elements
Browser support: Flexbox is supported by all major browsers, except IE < 10. Some recent browser versions, such as Safari 8 and IE10, require vendor prefixes. For a quick way to add prefixes use Autoprefixer. More details in this answer.
You can do this using flexbox (display: flex) quite easily.
Try my jsFiddle.

I accidentally put an extra close curly bracket

I am stuck with an extra close curry bracket in CSS that I accidentally put prior writing other lines. If I leave it there, it acually does no harm to the result. However, when I remove it, the position of other elements are repositioned.
(( In lines of code, the extra close curly bracket is where the arrow pointing ))
Please click on the links below to see both results.
Question: Is there any way to remove it without repositioning other elements?
Without the Close Curly Bracket
With the Close Curly Bracket
body{
font: 15px/1.5 Helvetica, Arial, sans-serif;
padding: 0;
margin: 0;
p(color#282f38);
background-color: #F5F2ED;
font:696863;
}
/*Global*/
.container{
width:80%;
margin:auto;
overflow:hidden;
}
ul{
margin:0;
padding:0;
}
/* Header */
#fixed{
position: fixed;
}
header{
position: fixed;
width: 100%;
background:#282f38;
color:#F5F2ED;
padding-top: 10px;
min-height:50px;
border-bottom:#F5F2ED 3px solid;
}
header a{
color:#F5F2ED;
text-decoration:none;
text-transform:uppercase;
font-size: 18px;
}
header li{
float:left;
display: inline;
padding: 0 20px 0 20px;
}
header #resume{
float: left;
}
header #resume h1{
margin: 0;
padding: 0;
}
header nav{
position: relative;
left: 30%;
float: right;
margin-top: 10px;
}
header .highlight, header .current a{
color:#696863 ;
font-weight: bold;
}
header a:hover{
color:#696863;
font-weight: bold;
}
/* Showcase */
#showcase {
min-height: 350px;
background: url('../Resources/Photographer.png') no-repeat 0 -120px;
align-items: center;
color: #ffffff;
overflow: auto;
}
#showcase h1{
text-align: center;
margin-top: 100px;
font-size: 40px;
margin-bottom: 10px;
}
#showcase p{
text-align:justify;
margin:0;
padding:0;
font-size: 14;
text-indent: inherit;
}
/* Social Medias*/
#socialmedias{
position:fixed;
padding-top: : 5px;
right: 20px;
top: 130px;
display: block;
vertical-align: baseline;
font: inherit;
list-style-type: none;
}
} <<-----------------------------------------------------------------------
/* Message Me Box */
#box{
width: 30%;
overflow: hidden;
padding: 1px;
}
/* Box Border */
.fieldset{
display: inline-block;
border: 3px solid;
float: right;
}
/* Message Me Title */
#legend{
font-size: 20px;
font-weight: bold;
color:#282f38;
}
/* Name Input */
#form-name{
display: block;
width: 200px;
margin-bottom: 10px;
}
/* Email Input */
#form-email{
display: block;
width: 200px;
margin-bottom: 10px;
}
/* Message Input */
#form-message{
display: block;
margin-bottom: 10px;
}
/* Contact */
.button_contact{
position: relative;
height: 30px;
width: 100%;
background:#696863;
color: #F5F2ED;
font-size: 14px;
text-transform: uppercase;
border: 0;
}
The extra curly bracket is being treated as part of the selector for the next rule. i.e. the rule is
} #box {
width: 30%;
overflow: hidden;
padding: 1px;
}
So } #box matches nothing. When you remove the }, the selector is #box and matches the element with id "box".
If you don't want the effect you get when removing the extra }, remove the entire rule.
Not just one error,
Check the comments I added in your code.
Best way to avoid these errors are using an IDE.
There are so many open source tools available. For example NetBeans.
They can help you to identify your errors.
Check this screenshot, they are easy to use also.
/* Social Medias*/
#socialmedias{
position:fixed;
padding-top: : 5px; // Error 1,
right: 20px;
top: 130px;
display: block;
vertical-align: baseline;
font: inherit;
list-style-type: none;
}
} // Error 2
body{
font: 15px/1.5 Helvetica, Arial, sans-serif;
padding: 0;
margin: 0;
p(color#282f38); // Error 3
background-color: #F5F2ED;
font:696863;
}
You have many errors in your css. I've validated your css on W3C CSS Validator
I've changed your CSS. See below:
body {
font: 15px/1.5 Helvetica, Arial, sans-serif;
padding: 0;
margin: 0;
background-color: #F5F2ED;
}
p {
color: #282f38;
}
/*Global*/
.container {
width: 80%;
margin: auto;
overflow: hidden;
}
ul {
margin: 0;
padding: 0;
}
/* Header */
#fixed {
position: fixed;
}
header {
position: fixed;
width: 100%;
background: #282f38;
color: #F5F2ED;
padding-top: 10px;
min-height: 50px;
border-bottom: #F5F2ED 3px solid;
}
header a {
color: #F5F2ED;
text-decoration: none;
text-transform: uppercase;
font-size: 18px;
}
header li {
float: left;
display: inline;
padding: 0 20px 0 20px;
}
header #resume {
float: left;
}
header #resume h1 {
margin: 0;
padding: 0;
}
header nav {
position: relative;
left: 30%;
float: right;
margin-top: 10px;
}
header .highlight, header .current a {
color: #696863;
font-weight: bold;
}
header a:hover {
color: #696863;
font-weight: bold;
}
/* Showcase */
#showcase {
min-height: 350px;
background: url('../Resources/Photographer.png') no-repeat 0 -120px;
align-items: center;
color: #ffffff;
overflow: auto;
}
#showcase h1 {
text-align: center;
margin-top: 100px;
font-size: 40px;
margin-bottom: 10px;
}
#showcase p {
text-align: justify;
margin: 0;
padding: 0;
font-size: 14px;
text-indent: inherit;
}
/* Social Medias*/
#socialmedias {
position: fixed;
padding-top: 5px;
right: 20px;
top: 130px;
display: block;
vertical-align: baseline;
font: inherit;
list-style-type: none;
}
/* Message Me Box */
#box {
width: 30%;
overflow: hidden;
padding: 1px;
}
/* Box Border */
.fieldset {
display: inline-block;
border: 3px solid;
float: right;
}
/* Message Me Title */
#legend {
font-size: 20px;
font-weight: bold;
color: #282f38;
}
/* Name Input */
#form-name {
display: block;
width: 200px;
margin-bottom: 10px;
}
/* Email Input */
#form-email {
display: block;
width: 200px;
margin-bottom: 10px;
}
/* Message Input */
#form-message {
display: block;
margin-bottom: 10px;
}
/* Contact */
.button_contact {
position: relative;
height: 30px;
width: 100%;
background: #696863;
color: #F5F2ED;
font-size: 14px;
text-transform: uppercase;
border: 0;
}
/* Header */
----------------->#fixed{<------------------
position: fixed;
}
Try to change the id where the arrow is pointed, use class for that, because there are so many conflicts, if we use IDs directly. For more information please find the link below:
https://github.com/CSSLint/csslint/wiki/disallow-ids-in-selectors
i think there is something to do with "#fixed" id name in the html and css.
try to change the name to something else. The property and your name might be colliding with each other. So change it...

How do I remove the white margins around my div tags?

So I have been creating a very basic website with a header, nav, main container, and a footer. and I'm using the the viewport tag in my website.
My problem occurs when I set the width of the divs to 100%.
Here is my code:
#header {
background-color: black;
color: white;
text-align: center;
padding: 5px;
}
#nav {
line-height: 60px;
background-color: #FFFFFF;
min-height: 60px;
width: 100%;
left: 0px;
text-decoration: none;
}
#nav a {
font-family: sans-serif;
font-size: 25px;
text-decoration: none;
float: left;
margin-left: 10px;
}
#section {
min-width: 50%;
min-height: 479px;
float: left;
}
#section p {
font-family: sans-serif;
font-size: 20px;
}
#footer {
background-color: black;
color: white;
clear: both;
text-align: right;
line-height: 40px;
height: 40px;
}
#footer p {
margin-right: 30px;
}
Is there something I need to change to get rid of the white edges around the div, I have tried things to get rid of it but none of them seem to work, any help would be greatly appreciated.
bodyhas a default margin across browsers so you need to reset that margin.
so add this
body {
margin: 0
}
are you talking about the white edges around the website then use
html, body {
margin: 0;
padding: 0;
overflow-x: hidden;
}

CSS no background image, any ideas?

I'm trying to get my background image to show at the top center of the page. The image works fine if I do:
<style>
body {
background: #FFF url('img/top_logo_blank_small.png') no-repeat fixed;
}
</style>
I can't seem to work out where I've gone wrong. There must be something I've managed to mess up, I just can't see it. Here is the CSS:
body {
font-family: 'Quattrocento Sans', helvetica, sans-serif;
background: #EEE url('img/top_logo_blank_small.png') no-repeat fixed;
color: #fff;
margin: 0;
padding: 0;
}
a {
color: black;
text-decoration: none;
}
/* Typography */
.header h1 {
position: absolute;
width:100%;
top: 50%;
margin-top: -20px;
text-align: center;
letter-spacing: 4px;
}
.header h1 em {
font-size: 1.200em;
font-style: normal;
}
h1 {
font-size: 2.2em;
color: #fff;
}
.content h2 {
font-size: 1.75em;
color: #fff;
letter-spacing: 4px;
text-align: center;
}
.content h2 em {
font-size: 1.2em;
font-style: normal;
}
.content h3 {
text-align: center;
font-size: 1.0em;
font-weight: normal;
color: #ede0ed;
letter-spacing: 1px;
margin-bottom: 25px;
}
.content h4 {
margin-top: 0;
text-align: center;
font-size: 0.8em;
font-weight: normal;
color: #ede0ed;
letter-spacing: 1px;
}
#banner p {
text-align: center;
}
/* Navigation */
#nav {
margin: 4px 4px 40px;
}
#nav ul {
padding: 0;
margin: auto;
list-style: none;
}
#nav ul li {
width: 50%;
color: #BBB;
float: left;
font-family: 'Cabin Sketch';
font-size: 1.75em;
text-align: center;
background: url(img/scribble_dark.png);
}
#nav ul li a {
display: block;
/*padding: 5px 20px;*/
}
#nav ul li a:hover {
background: #e0d0e0;
}
/* Content */
.container{
max-width: 720px;
margin: 50px auto 0;
background: #FFF url('img/top_logo_blank_small.png') no-repeat fixed 0 0;
}
.header {
position: relative;
background-color: #b88fb8;
border-top: 5px solid #ede0ed;
height: 75px;
}
.content {
background-color: #000;
padding: 15px;
margin-bottom: 10px;
}
div#about {
padding:25px;
min-height: 255px;
}
img#portrait {
float: left;
margin-right: 25px;
width: 256px;
height: 256px;
}
div#footer {
width: 100%;
max-width: 720px;
margin: auto;
color: black;
text-align: right;
padding: 0 10px;
font-size: 0.850em;
}
#media screen and (max-width: 650px) {
.container {
width: 90%;
max-width: none;
}
div#footer {
width: 90%;
}
}
Try to change your path for example:
background: #EEE url('../img/top_logo_blank_small.png') no-repeat fixed top;
Because you are in a subfolder, you have to go up of a level I think
Most likely your css file is in a different folder and therefore needs another path to the image file.
The common way is to put css in a separate css/* folder, so the path should be:
url('../img/top_logo_blank_small.png')
This CSS seems to work fine, are you certain that the image exists?
http://jsfiddle.net/ghsNR/
I've just tried it here and it works fine with an image from http://placehold.it/
body {
font-family: 'Quattrocento Sans', helvetica, sans-serif;
background: #EEE url('http://placehold.it/500x500') no-repeat fixed top;
color: white;
margin: 0px;
padding: 0px;
}
The most likely cause after observing this is that your CSS isn't actually locating your image correctly. I suggest using tools like the Chrome dev tools, or Firebug to inspect the absolute path that the browser is trying to use to load the image and moving forward from there.
Is the css in the same folder as the page? If you have a different folders, you need to change the URL accordingly.
Maybe change the URL to
'../img/top_logo_blank_small.png'

sticky CSS footer broken

My footer is designed to stay at the bottom of the page even if the div above it only has a small amount of content. It worked until recently, and I seem to have broken it somehow.
Can you take a look?
Thanks in advance.
CSS:
body {
margin: 0;
padding: 0;
height: 100%;
font: 100% Helvetica, sans-serif, Arial, sans-serif;
color: #000;
background-color: #FFF;
background-image: url(images/BGmain.png);
background-repeat: repeat-x;
}
/*----------
Div styles
----------*/
#container {
min-height: 100%;
position: relative;
}
.header {
padding: 0 0 230px 0;
text-align: center;
background-image: url(images/BGlogo_55top.png);
background-repeat: no-repeat;
background-position: top;
}
.column1 {
padding-bottom: 50px;
width: 960px;
margin: 0 auto;
position: relative;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
text-align: center;
}
/*----------
Other
----------*/
.plainimg {
border-style: none
}
/*----------
Text styles
----------*/
p {
font-size: 80%;
color: #333;
line-height: 150%;
text-align: left;
padding: 1px 15px 1px 15px;
}
h1 {
font-size: 100%;
color: #000;
padding: 0;
}
h2 {
font-size: 100%;
font-weight: 500;
color: #000;
padding: 0;
text-align: center;
}
/*----------
Links
----------*/
a.navlink:link, a.navlink:visited {
text-decoration: none;
display: inline-block;
color: #F1F1F1;
width: 120px;
text-align: center;
padding: 0 0 3px 0;
font-size: 80%;
}
a.navlink:hover, a.navlink:active {
text-decoration: none;
display: inline-block;
color: #FFF;
background-color: #000;
width: 120px;
text-align: centre;
padding: 0 0 3px 0;
font-size: 80%;
}
a:link, a:visited {
text-decoration: none;
color: #AEAEAE;
}
a:hover, a:active {
text-decoration: underline;
color: #999
}
The div arrangement is as follows:
<div id=container>
<div class=header></div>
<div class=column1></div>
<div class=footer></div>
</div>
As Jason McCreary said, you need to add height to the html CSS.
Use:
html
{
height: 100%;
margin: 0;
padding: 0;
}
On your pages this triggers an extraneous scrollbar for some reason.
UPDATE:
The scrollbar appears to be triggered by the overflow of the .footer h6.
Adding: bottom: 2.5ex; and line-height: 1; to the footer style appears to clears that.
But a better way is to use a CSS reset.
With no reset, at the minimum, add:
.footer h6 {
margin: 0;
padding: 0;
}
.
A CSS reset will also minimize cross-browser variation that busts the layout from platform to platform.
Take a look at this: http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page
When it has broken for me in the past I typically have something in the content that is the culprit - padding, invalid markup, etc. If you post a link to your page, you may find a more specific answer.
Here is your problem:
#container {
min-height:100%;
position:relative;
}
Here is the fix:
#container {
min-height:100%;
}
Good stuff:
http://www.w3schools.com/Css/pr_class_position.asp
Solved. Easy Solution Just put your Footer Division outside of your Container Division.
<div id=container>
<div class=header></div>
<div class=column1></div>
</div>
<div class=footer></div>