I just started learning HTML and CSS and I have been stuck on the layout of a website in css for a while now. In the first picture you can see how i am trying to make it look and in the second picture you see how it looks right now...
I tried searching online but I don't seem to grasp the way layout and positioning works in CSS. Does anyone know what I am doing wrong??
Picture here!
2nd picture here!
html
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Catamaran:100|Pontano+Sans|Ruda:900" rel="stylesheet">
<link href="style.css" type="text/css" rel="stylesheet">
<title>ALISAN'S OCCASIONS</title>
</head>
<body>
<div class="header">
</div>
<div class="home_page">
<div class="home_left">
<ul id="social_media">
<li><img src="Facebook1.jpg"></li>
<li><img src="Instagram1.jpg"></li>
<li><img src="twitter1.jpg"></li>
</ul>
</div>
<div class="home_center">
</div>
<div class="home_right">
</div>
</div>
</body>
</html>
and this the CSS stylesheet
* {
box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
background-color: #8799b7;
overflow-y: scroll;
max-height: 735px;
}
.header {
display: block;
background-image: url("header4.jpg");
height: 500px;
}
.home_page {
display: block;
margin:0;
padding: 0;
}
.home_left {
display: inline-block;
height: 235px;
width: 506px;
margin: 0;
padding: 0;
}
.home_center {
display: inline-block;
height: 235px;
width: 506px;
margin: 0;
padding: 0;
}
.home_right {
display: inline-block;
height: 235px;
width: 506px;
margin: 0;
padding: 0;
You can simplify your code by using flexbox, as long as you don't need to support older browser.
The HTML would be:
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Catamaran:100|Pontano+Sans|Ruda:900" rel="stylesheet">
<link href="style.css" type="text/css" rel="stylesheet">
<title>ALISAN'S OCCASIONS</title>
</head>
<body>
<div class="header">
header
</div>
<div class="home_page">
<div class="home_left">
left
</div>
<div class="home_center">
center
</div>
<div class="home_right">
right
</div>
</div>
</body>
</html>
The CSS:
* {
box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
background-color: #8799b7;
overflow-y: scroll;
max-height: 735px;
}
.header {
display: block;
background-image: url("header4.jpg");
height: 500px;
}
.home_page {
display: flex;
margin:0;
padding: 0;
}
.home_page > div {
border: 1px solid grey;
}
.home_left {
height: 235px;
width: 506px;
margin: 0;
padding: 0;
}
.home_center {
height: 235px;
width: 506px;
margin: 0;
padding: 0;
}
.home_right {
height: 235px;
width: 506px;
margin: 0;
padding: 0;
}
And you can see it in action at:
https://codepen.io/anon/pen/EvqXmg
Related
I am working on a website and I finally made a responsive menu that takes up the whole screen when you click on the label. The problem is, I cannot hide it(I want to use pure css) I created a new label in the menu that tries to close the menu but it doesn't work and I am assuming that it's because a child is trying to select a parent. I am new to CSS and would really appreciate any help on how to make a close button that closes the menu(width: 0%). Thank you!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="css/main.css" rel="stylesheet" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>La Regina</title>
</head>
<body>
<div id="pagewrap">
<!--HEADER-->
<header class="pagesection" id="pageheader">
<div class="pagewidth">
<figure id="logo">
<img src="img/logo-full.png" alt="Logotype La Regina">
</figure>
<label for="toggle">☰</label>
<input type="checkbox" id="toggle">
<div id="myNav" class="overlay">
<nav>
<label for="toggle2">☰</label>
<input type="checkbox" id="toggle2">
Home
Menu
About us
Contact
</nav>
</div>
</div>
</header>
<!--END OF HEADER-->
</div>
</body>
</html>
html,
body,
figure {
padding: 0;
margin: 0;
list-style: none;
}
#pageheader {
background: #333;
position: fixed;
top: 0;
left: 0;
right: 0;
}
.pagesection {
padding-left: 11px;
padding-right: 11px;
}
#logo img{
width: 200px;;
}
.overlay {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
right: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
#myNav > nav {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
#toggle{
z-index: 3;
}
#toggle2:checked < #myNav{
width: 0%;
}
#toggle:checked + #myNav{
width: 100%;
}
Unfortunately in CSS you cant go up the parent level.
But you can do this in Pure CSS.
#pageheader {
background: #333;
position: fixed;
top: 0;
left: 0;
right: 0;
}
.pagesection {
padding-left: 11px;
padding-right: 11px;
}
#logo img{
width: 200px;;
}
.overlay {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
right: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
#myNav > nav {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
#toggle{
z-index: 3;
}
#toggle:checked + #myNav{
width: 100%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="css/main.css" rel="stylesheet" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>La Regina</title>
</head>
<body>
<div id="pagewrap">
<!--HEADER-->
<header class="pagesection" id="pageheader">
<div class="pagewidth">
<figure id="logo">
<img src="img/logo-full.png" alt="Logotype La Regina">
</figure>
<label for="toggle">☰</label>
<input type="checkbox" id="toggle">
<div id="myNav" class="overlay">
<nav>
<label for="toggle">☰</label>
Home
Menu
About us
Contact
</nav>
</div>
</div>
</header>
<!--END OF HEADER-->
</div>
</body>
</html>
As you can see I've removed one of the input fields (one inside the nav) and then changed the id of the for attribute inside the nav to point to the checkbox outside the nav making use of the selector
#toggle:checked + #myNav
What you want to affect is the overlay class but i do not believe you are able to do this with CSS.
You could do this with JQuery.
However, you can modify your current code so that the original toggle is still visible in the overlay and therefore when you untick that toggle, the overlay is removed.
So, in the html remove these two lines:
<label for="toggle2">☰</label>
<input type="checkbox" id="toggle2">
In your CSS change the 'top' to relative:
.overlay {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: relative;
right: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
Give that a try otherwise, I would recommend you look into JQuery and the hide function
I would also encourage checking out Bootstrap at some point once you are comfortable with CSS since it is a great framework for mobile-first design.
I am helping a student with a project and we are going through a tutorial. The tutorial is here:
https://ihatetomatoes.net/demos/parallax-scroll-effect/
Here is our index.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>joeys school project</title>
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/normalize.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
<script src="js/jquery.waypoints.min.js"></script>
</head>
<body>
<main>
<section id="slide-1" class="homeSlide">
<div class="bcg" data-center="background-position: 50% 0px;" data-top-bottom="background-position: 50% -100px;" data-anchor-target="#slide-1">
<div class="hsContainer">
<div class="hsContent" data-center="opacity: 1" data-106-top="opacity: 0" data-anchor-target="#slide-1 h2">
<h2>Mac Vs. Windows</h2>
<p>Which is better? Which should you choose?</p>
</div>
</div>
</div>
</section>
</main>
</body>
</html>
Here is our main.css:
body {
margin: 0;
}
.mac_header {
z-index: 100;
position: absolute;
color: white;
font-size: 24px;
font-weight: bold;
left: 150px;
top: 350px;
}
/* CSS */
.hsContainer {
display: table;
table-layout: fixed;
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
opacity: 0;
}
.hsContent {
max-width: 450px;
margin: -150px auto 0 auto;
display: table-cell;
vertical-align: middle;
color: #ebebeb;
padding: 0 8%;
text-align: center;
}
.hsContent h2,
.copy h2 {
color: #ffffff;
font-size: 45px;
line-height: 48px;
margin-bottom: 12px;
}
.hsContent p {
width: 400px;
margin: 0 auto;
color: #b2b2b2;
}
.hsContent a {
color: #b2b2b2;
text-decoration: underline;
}
.bcg {
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
height: 100%;
width: 100%;
}
/* Slide 1 */
#slide-1 .bcg {
background-image:url('../img/computers-1227142.jpg');
height: 733px;}
The issue is we can see the block for the text when we inspect the page in Chrome, but it is not displaying the text over the image. All we see is the outline of the div where it is located. We have researched how to get this working and also followed the tutorial correctly. Also we have compared our code to the tutorial and can't see where the disconnect is. Any ideas? At this point a solution that works instead of what is in the tutorial will be fine as well.
I was looking for some help in regards to media queries. This is the first time I am using this on a site, but it doesn't seem to work. This is also the first time I am changing my html4 code to html5, not sure if that's where the problem lies.
My HTML Code:
<!doctype html> <!-- html5 doctype -->
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- line added to for responsive layout -->
<title>Dummy Site</title>
<link href="style5.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="maincontainer">
<div id="wrapper">
<header></header>
<div id="spacer1"></div>
<div id="banner"></div>
<div id="range"></div>
<div id="spacer2"></div>
<div id="cols"></div>
<div id="spacer3"></div>
<footer></footer>
</div>
</div>
</body>
</html>
My CSS:
body {
margin:0 auto;
background:#f5f3ef;
}
a {
font-family: 'Arial';
font-size: 12px;
color: #66308f;
text-decoration:none;
font-weight:bold;
}
#container {
margin: 0 auto;
height: 1264px;
width: 100%;
}
#wrapper {
margin: 0 auto;
height: 1264px;
width: 893px;
background-color:#0CF;
}
header {
margin:0 auto;
height: 171px;
width: 883px;
}
#spacer1 {
height:59px;
}
#banner {
margin:0 auto;
width: 883px;
height: 439px;
background:url(z_imgs/banner.jpg) no-repeat;
}
#range {
margin: 0 auto;
height: 246px;
width: 883px;
}
#spacer2 {
height:24px;
}
#cols {
margin: 0 auto;
height:188px;
width:883px;
}
#spacer3 {
height:39px;
}
footer {
margin: 0 auto;
height:98px;
width:883px;
}
<!-- MEDIA QUERIES -->
#media (max-width: 850px) {
#wrapper {
background-color: red;
}
}
When I resize the browser to below 850px the color still stays the same and doesn't change to red.
It does not work since you are using HTML comments inside CSS code which leads to syntax error and browser not recognizing the code. Remove the comment or modify it from <!-- --> to /* */ and it works.
body {
margin: 0 auto;
background: #f5f3ef;
}
a {
font-family: 'Arial';
font-size: 12px;
color: #66308f;
text-decoration: none;
font-weight: bold;
}
#container {
margin: 0 auto;
height: 1264px;
width: 100%;
}
#wrapper {
margin: 0 auto;
height: 1264px;
width: 893px;
background-color: #0CF;
}
header {
margin: 0 auto;
height: 171px;
width: 883px;
}
#spacer1 {
height: 59px;
}
#banner {
margin: 0 auto;
width: 883px;
height: 439px;
background: url(z_imgs/banner.jpg) no-repeat;
}
#range {
margin: 0 auto;
height: 246px;
width: 883px;
}
#spacer2 {
height: 24px;
}
#cols {
margin: 0 auto;
height: 188px;
width: 883px;
}
#spacer3 {
height: 39px;
}
footer {
margin: 0 auto;
height: 98px;
width: 883px;
}
/* Media Queries */
#media (max-width: 850px) {
#wrapper {
background-color: red;
}
}
<!doctype html>
<!-- html5 doctype -->
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- line added to for responsive layout -->
<title>Dummy Site</title>
<link href="style5.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="maincontainer">
<div id="wrapper">
<header></header>
<div id="spacer1"></div>
<div id="banner"></div>
<div id="range"></div>
<div id="spacer2"></div>
<div id="cols"></div>
<div id="spacer3"></div>
<footer></footer>
</div>
</div>
</body>
</html>
I have the following HTML5 code:
<!doctype html>
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style>
body {
max-width: 960px;
margin: 0 auto;
font-size: 120%;
}
header, nav {
margin: 0;
padding: 0;
border: 1px solid black;
}
header {
border-color: red;
}
img.mainpicture {
width: 100%;
height: auto;
}
</style>
</head>
<body>
<header>
<img class="mainpicture" src="http://s29.postimg.org/ajjbb0n07/apic.jpg" alt="A picture"/></header><nav>Navigation area.</nav>
</body>
</html>
Can someone please explain why there is about 5 pixels of empty space between the <header> and the <nav> content, and how can I remove it?
By adding
header {
padding-bottom: 1px;
}
to the CSS file, the height of the white space is extended by one pixel, so it doesn't seem to have anything to do with the padding of <header>.
EDIT: I would like to do it without using <nav style="position: relative; top:-7px;">.
Set display block on the image for fixing fitting issues.
body {
max-width: 960px;
margin: 0 auto;
font-size: 120%;
}
header,
nav {
margin: 0;
padding: 0;
border: 1px solid black;
}
img.mainpicture {
width: 100%;
display: block;
}
<header>
<img class="mainpicture" src="//lorempicsum.com/futurama/960/200/2" alt="A picture" />
</header>
<nav>
Navigation area.
</nav>
Just add
img.mainpicture{
.....................
.....................
vertical-align: top;
}
That will fix the issue:)
It could be because of the inner elements having a margin, that is protruding outside! And also since you have an <img />, give a display: block; to it. Try overflow: hidden; for both header, nav:
header, nav {
overflow: hidden;
}
header img {
display: block;
}
Set the property margin-bottom equal to zero.
margin-bottom: 0;
would you be able to help me to position my navigation - "wrapperNav" completely left in the browser so there would be no gap between the blue navigation and the browser edge?
thanks a lot.
code: http://codepen.io/anon/pen/hKsCe
<header>
<div id="logo"><img src="images/logo.jpg" alt="logo"/></div>
<h1 id="adminHeader">Administrace webu</h1>
<div id="wrapperNav">
<nav>
<ul>
<li>Vložit obrázek</li>
<li>Editovat odkazy</li>
<li>Nahrát soubor</li>
<li>Editovat text</li>
</ul>
</nav>
</div>
</header>
#logo,
#adminHeader {
float: left;
display: inline;
width: 45%;
}
nav li {
list-style: none;
height: 100px;
color: #7E8AA2;
background: #263248;
min-width: 100px;
}
nav li:hover {
background: #000;
}
#wrapperNav {
margin-top: 70px;
margin-left: 0;
margin-bottom: 0;
margin-right: 0;
padding: 0;
position: fixed;
float: left;
display:block;
}
Fixed, you just needed to add in padding-left: 0px; to nav ul
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Administrace odkazů</title>
<link href="adminstyle2.css" rel="stylesheet" type="text/css">
<style type="text/css">
#logo, #adminHeader {
float: left;
display: inline;
width: 45%;
}
nav li {
list-style: none;
height: 100px;
color: #7E8AA2;
background: #263248;
min-width: 100px;
}
nav li:hover {
background: #000;
}
#wrapperNav {
margin-top: 70px;
margin-left: 0;
margin-bottom: 0;
margin-right: 0;
padding: 0;
position: fixed;
float: left;
display:block;
}
nav ul {
padding-left:0px;
}
</style>
</head>
<body>
<header>
</header>
<div id="logo"><img src="images/logo.jpg" alt="logo"/></div>
<h1 id="adminHeader">Administrace webu</h1>
<div id="wrapperNav">
<nav>
<ul>
<li>Vložit obrázek</li>
<li>Editovat odkazy</li>
<li>Nahrát soubor "credentials"</li>
<li>Editovat text</li>
</ul>
</nav>
</div>
</body>
</html>
#wrapperNav ul {
margin: 0;
padding: 0;
}
As need to be updated, I did on your example, try it once.
As a best practice you have to use css re-set for better styling. Because HTML tags has its own padding and margins, so using a re-set css, you can re--set them and control by yourself. Use following link for more. http://meyerweb.com/eric/tools/css/reset/
You are missing a reset. For example, put in your css:
* {
padding: 0;
margin: 0;
}
I have changed your code check it.
[http://codepen.io/anon/pen/Dvcgr][1]