I want use 100% height for MAIN id but when I put it 100% height to main id, creativity class is placed on the main. when use pixel for main in different device its look different.
is there any solution to fix it ?
#main {
width: 100%;
height: 675px;
}
.main {
position: fixed;
width: 100%;
height: 100%;
background: url(/images/logo/logo.svg) center no-repeat #ffcc00;
}
.introduction {
position: relative;
display: inline-block;
z-index: 2;
width: 100%;
height: auto;
background: #fcd803;
text-align: center;
padding-bottom: 40px;
}
.introduction h1 {
text-align: center;
text-transform: uppercase;
font-size: 24px;
padding-top: 40px;
}
.introduction span img {
width: 200px;
padding-top: 30px;
}
.introduction div {
text-align: center;
margin-left: 30px;
margin-right: 30px;
margin-top: 30px;
font-size: 15px;
line-height: 21px;
}
.creativity {
position: relative;
z-index: 2;
width: 100%;
height: 320px;
background: #fcd803;
}
.creativity-img {
display: block;
background: url('/images/ariadesk.png');
background-repeat:no-repeat;
background-size:contain;
background-position:bottom;
width: 100%;
height: 320px;
position: absolute;
}
.creativity-img div {
position: relative;
text-align: center;
padding-top: 145px;
}
.creativity-img div h1 {
font-size: 20px;
font-weight: normal;
text-transform: capitalize;
color: white;
border: solid 2px #fff;
display: inline-block;
padding: 10px 50px;
}
<div id="main">
<div class="main">
<div class="logo"><h1>HUR</h1><br><span>studio</span></div>
<div class="nav">
<ul>
<li>introduction</li>
<li>work</li>
<li>service</li>
<li>client</li>
<li>team</li>
<li>contact</li>
</ul>
</div>
</div>
</div>
<div class="introduction" id="introduction">
<h1>introduction</h1>
<span>
<img src="/images/icon/intro.svg" alt="">
</span>
<div><p>
We are small team of super nerds and talented creatives. Create cutting-edge interfaces and visually stunnig media.<br>
Experts in providing innovative Web Design, Graphic Design, Digital Imaging, Advertising and Branding service</p>
</div>
</div>
<div class="creativity">
<div class="creativity-img"></div>
</div>
If you don't mind IE 8 and below, you can use vh (viewport-height) units:
#main {
width: 100%;
height: 100vh;
}
Fiddle
I think it is because of your position
your #main is in the same level with .creativity
if you want the .main always on the top, just change your .creativity with z-index: 1 AND your .main with z-index: 2
You never set the .main index, and it always on the bottom layer.
Is it that case you want to?
Related
I'm learning now CSS and i'm creating a portfolio page as part of it.
I've created this page: link to the codepen
The thing is, the footer is not sticks to the bottom of the page, can some one tell me how can i fix it? so it will be after the <div id="contact">
Iv'e noticed that when I do put it in the <div class="content"> it does work, I tried to figure out why and I didn't got it.
Thanks.
CSS & HTML are here:
html,
body,
main {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
font-family: "Alef";
}
header {
position: fixed;
top: 0;
width: 100%;
height: 70px;
background: #fff;
}
nav {
width: 960px;
height: 70px;
margin: 0 auto;
}
nav ul {
margin: 10px 0 0;
}
nav ul li {
display: inline-block;
margin: 0 40px 0 0;
}
a {
color: #4d4d4d;
line-height: 42px;
font-size: 18px;
padding: 10px;
text-decoration: none !important;
}
.active {
color: #004cc6;
font-weight: bold;
font-size: 20px;
background: #f9fafc;
}
.content {
margin-top: 70px;
width: 100%;
height: 100%;
}
.content > div {
width: 80%;
height: 50%;
margin-left: auto;
margin-right: auto;
color: white;
font-size: 25px;
}
#home {
background: #0f5fe0;
}
#portfolio {
background: #129906;
}
#about {
background-color: #a00411;
}
#contact {
background-color: black;
}
:target:before {
content: "";
display: block;
height: 70px; /* fixed header height*/
margin: -70px 0 0; /* negative fixed header height */
}
footer {
display: flex;
flex-flow: row wrap;
justify-content: space-around;
align-items: flex-start;
background-color: #dbdbdb;
text-align: center;
height: 70px;
width: 100%;
}
<header>
<nav>
<ul>
<li><a class="active" href="#home">My Page</a></li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</nav>
</header>
<main>
<div class="content">
<div id="home">
<p>#home</p>
</div>
<div id="about">
<p>#about</p>
</div>
<div id="portfolio">
<p>#portfolio</p>
</div>
<div id="contact">
<p>#contact</p>
</div>
</div>
</main>
<footer>
Fotter
</footer>
Remove height: 50%; from .content > div if you want to put footer just after contact.
Codepen
If you want to stick footer to the bottom of the browser window, then add this to your css:
footer {
position: fixed;
bottom: 0px;
}
Codepen
Change footer value like below
footer {
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 99;
background-color: #dbdbdb;
text-align: center;
height: 70px;
width: 100%;
}
you can use vh instead of percentage to set the min-height of main, then you need to remove the height
.main {
min-height: 100vh; // Change as per your requirement
}
My HTML:
.title-card {
display: block;
height: 56.25vw;
width: 100%;
}
.title-overlay .title {
color: white;
background-color: rgba(255, 0, 0, 1);
font-weight: 100;
font-size: 2em;
display: table-cell;
vertical-align: middle;
text-align: center;
padding: 1em;
}
.title-overlay {
position: absolute;
left: 15%;
display: table;
width: 70%;
height: 56.25vw;
}
.background {
position: absolute;
width: 100%;
height: 56.25vw;
}
.background-overlay {
font-size: 0;
}
<div class="title-card">
<div class="background-overlay">
<img src="https://i.ytimg.com/vi/3RMr6m1B-qM/maxresdefault.jpg" class="background">
</div>
<div class="title-overlay">
<div class="title">
Hello there, and welcome! This site is still unfinished but feel free to look around.
</div>
</div>
</div>
As you can see, all of my heights are set to 56.25vw. However, in the actual page, the title-card's and background's heights are 698.52px while the title-overlay's height is 698.18px. According to my calculator, 698.52px should be the correct height. So why is my title-overlay a bit shorter?
It is because display:table; calculates height differently from block elements.
I don't know exactly why it does but my guess is that it does not allow half pixels somewhere in the calculation.
For example: set the height of everything to 300px and all elements will have 300px height but if you set all heights to 300.75px the block elements will be 300.75px and the table element will be 300px.
To fix your problem I would recommend just stop using tables.
If you want to center everything the same way you can use a inline-block element with 56.25vw in line-height and then having a inline-block element inside it with line-height: normal;
Example below:
.title-card {
display: block;
height: 56.25vw;
width: 100%;
}
.title-overlay .title {
font-weight: 100;
font-size: 2em;
line-height: normal;
display: inline-block;
vertical-align: middle;
text-align: center;
padding: 1em;
}
.title-overlay .title-container {
color: white;
background-color: rgba(255, 0, 0, 1);
display:inline-block;
line-height:56.25vw;
}
.title-overlay {
position: absolute;
left: 15%;
display: block;
width: 70%;
height: 56.25vw;
}
.background {
position: absolute;
width: 100%;
height: 56.25vw;
}
.background-overlay {
font-size: 0;
}
<div class="title-card">
<div class="background-overlay">
<img src="https://i.ytimg.com/vi/3RMr6m1B-qM/maxresdefault.jpg" class="background">
</div>
<div class="title-overlay">
<div class="title-container">
<div class="title">
Hello there, and welcome! This site is still unfinished but feel free to look around.
</div>
</div>
</div>
</div>
.title-card {
display: block;
height: 56.25vw;
width: 100%;
}
.title-overlay .title {
color: white;
background-color: rgba(255, 0, 0, 1);
font-weight: 100;
font-size: 2em;
display: table-cell;
vertical-align: middle;
text-align: center;
padding: 1em;
}
.title-overlay {
position: relative;
left: 15%;
display: table;
width: 70%;
height: 60vw;
}
.please-work {
position: absolute;
overflow: hidden;
width: 100%;
height: 56.25vw;
}
.background {
position: absolute;
width: 100%;
height: 56.25vw;
}
.background-overlay {
font-size: 0;
}
<div class="title-card">
<div class="background-overlay">
<img src="https://i.ytimg.com/vi/3RMr6m1B-qM/maxresdefault.jpg" class="background">
</div>
<div class="please-work">
<div class="title-overlay">
<div class="title">
Hello there, and welcome! This site is still unfinished but feel free to look around.
</div>
</div>
</div>
</div>
Well, I've found myself a disgusting "fix." I'm not really satisfied with it but if it works, then it works, I guess.
I'm practicing my HTML by making a website, and I'm making a header with buttons.
I'm trying to make the button the full height of the header, but it's going out of the header for some reason, and not going to the top.
#header {
background-color: #1564B3;
color: #fff;
height: 70px;
position: fixed;
width: 100%;
top: 0%;
left: 0%;
}
#header-a {
width: 100px;
background-color: #555555;
display: inline-block;
text-align: center;
margin-top: 0px;
height: 100%;
}
#header-h {
display: inline-block;
margin-top: 20px;
}
<div id="header">
<h2 id="header-h">Header text</h2>
<div id="header-a">
Home
</div>
</div>
You can reset the vertical-align(defaut is baseline) value on inline-block elements whenever needed. here vertical-align:top; will do fine :
#header {
background-color: #1564B3;
color: #fff;
height: 70px;
position: fixed;
width: 100%;
top: 0%;
left: 0%;
}
#header-a {
width: 100px;
background-color: #555555;
display: inline-block;
text-align: center;
margin-top: 0px;
height: 100%;
vertical-align:top;
}
#header-h {
display: inline-block;
margin-top: 20px;
}
<div id="header">
<h2 id="header-h">Header text</h2>
<div id="header-a">
Home
</div>
</div>
For a to cover the div, you may also use height or eventually line-height:
#header {
background-color: #1564B3;
color: #fff;
height: 70px;
position: fixed;
width: 100%;
top: 0%;
left: 0%;
}
#header-a {
width: 100px;
background-color: #555555;
display: inline-block;
text-align: center;
margin-top: 0px;
height: 100%;
vertical-align:top;
}
#header-a a {
display:block;
line-height:70px;/* will size it up to 70px height for each line */
}
#header-h {
display: inline-block;
margin-top: 20px;
}
<div id="header">
<h2 id="header-h">Header text</h2>
<div id="header-a">
Home
</div>
</div>
I changed it to this code. What I did was to change the display to block (in both header-a and header-h) instead of inline-block. I then floated both elements left. Run the snippet to see it in action
#header {
background-color: #1564B3;
color: #fff;
height: 70px;
position: fixed;
width: 100%;
top: 0%;
left: 0%;
}
#header-a {
width: 100px;
background-color: #555555;
text-align: center;
margin-top: 0px;
height: 100%;
}
#header-h {
margin-top: 20px;
}
#header-h,
#header-a {
display: block;
float: left;
}
<div id="header">
<h2 id="header-h">Header text</h2>
<div id="header-a">
Home
</div>
</div>
Rather than setting the height of your menu bar to 70px, you could let the contents within the menu bar size its height. That way you can vertically centre the Home button. JSFiddle
HTML
<div id="header">
<h2 id="header-h">Header text</h2>
<div id="header-a">
Home
</div>
</div>
CSS
#header {
position: fixed;
background-color: #1564B3;
color: #fff;
width: 100%;
top: 0%;
left: 0%;
}
#header-a {
background-color: #555555;
display:inline-block;
padding:30px 50px 30px 50px;
width:10%;
text-align:center;
}
#header-h {
display:inline-block;
width:30%;
text-align:center;
}
Do you see how the padding of #header-a not only vertically centres the Home text but also how the #header sizes to fit it.
This is the situation:
I have a main div with 2 div parts(red and orange), both have width: 100% and height: 90%. (should be responsive!)
Inside the red div there is a nav bar (top-right-pink), and 3 buttons in the middle.
The aqua div has to be above both red and orange divs.
What is the right way to position everything?
using relative on the red and orange divs doesnt work because of the '%' in the heights.
<div class="main">
<div class="thedude"></div>
<div class="first">
<ul>
<li> Clients </li>
<li> About Us </li>
<li> Contact </li>
<li class="hasImage"> <img src="logo.png"> </li>
</ul>
<div class="timages">
<img src="icon1.png">
<img src="icon2.png">
<img src="icon3.png">
</div>
</div>
<div class="second">
</div>
</div>
*{
margin: 0;
padding: 0;
}
body{
font-size: 100%;
font-family: arial;
}
.first{
width: 100%;
height: 90%;
background-color: #2acecd;
}
.thedude{
width: 95em;
height: 100%;
max-width: 100%;
max-height: 100%;
position: absolute;
background-image: url('yellow_creature.png');
background-repeat: no-repeat;
background-size: 100%, 100%;
z-index: 500;
}
.second{
width: 100%;
height: 90%;
background-color: #f49900;
}
.third{
width: 100%;
height: 90%;
background-color: #fbc00a;
}
.timages{
margin:0 auto;
width: 81%;
padding-top: 23%;
text-align: center;
max-width: 62%;
}
.timages img{
text-align: center;
max-width: 100%;
}
ul{
z-index: 540;
position: absolute;
right: 0;
text-transform: uppercase;
}
li{
float: left;
padding: 2em 0.5em;
}
li a{
text-decoration: none;
color: white;
}
li img{
max-width: 10em;
}
.hasImage{
padding: 0.6em 0.5em;
}
http://jsfiddle.net/4z55sjn0/
Your HTML structure is the main problem.
HTML
<div class="main">
<div class="thedude">
<div class="first">
</div>
<div class="second">
<ul>
<li> Clients </li>
<li> About Us </li>
<li> Contact </li>
<li class="hasImage"> <img src="logo.png"/> </li>
</ul>
<div class="timages">
<img src="icon1.png"/>
<img src="icon2.png"/>
<img src="icon3.png"/>
</div>
</div>
<div class="third">
</div>
</div>
</div>
If you want the menu on the orange div you need to move it...inside the orange block!
CSS
.first {
width: 30%;
height: 90%;
background-color: #2acecd;
float:left;
position:absolute;
top:5%;
z-index: 999 !important;
}
.thedude {
width: 95em;
height: 100%;
max-width: 100%;
max-height: 100%;
position: absolute;
background-image: url('yellow_creature.png');
background-repeat: no-repeat;
background-size: 100%, 100%;
z-index: 500;
}
.second {
width: 100%;
height: 90%;
background-color: #f49900;
position:relative;
}
.third {
width: 100%;
height: 90%;
background-color: #fbc00a;
}
.timages {
position: absolute;
top: 50%;
width: 100%;
text-align: center;
}
.timages img {
text-align: center;
max-width: 100%;
}
ul {
z-index: 540;
position: absolute;
right: 0;
text-transform: uppercase;
list-style: none;
}
li {
float: left;
padding: 2em 0.5em;
}
li a {
text-decoration: none;
color: white;
}
li img {
max-width: 10em;
}
.hasImage {
padding: 0.6em 0.5em;
}
Check the updated fiddle. Is that close to what you're after?
UPDATE (following comments to this answer)
I've swapped the styles to overcome the misunderstanding.
Check updated fiddle.
I hope it helps.
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
body{
background-color: #f2f2f2;
}
#content{
background-color: white;
border: 1px solid gray;
width: 60%;
height: auto;
display: block;
position: relative;
left: 50%;
margin-left: -30%;
padding: 10px;
z-index: 100;
margin-top: 20px;
}
html, body {
height: auto;
}
#wrap {
min-height: 100%;
}
#main {
overflow:auto;
padding-bottom: 150px;
} /* must be same height as the footer */
#footer {
position: relative;
margin-top: -150px; /* negative value of footer height */
height: 150px;
clear:both;
}
.instructions{
margin-top: 50px;
font-family: serif;
font-size: medium;
width: 50%;
left: 50%;
margin-left: -25%;
position: relative;
margin-bottom: 60px;
}
.repbanner{
background-color: red;
width: 108%;
height: auto;
left: 50%;
margin-left: -54.5%;
margin-top: 40px;
position: relative;
z-index: 200;
border: 1px #a70000 solid;
text-align: center;
color: white;
font-size: smaller;
text-transform: uppercase;
padding-top: 3px;
padding-bottom: 3px;
}
.dembanner{
background-color: blue;
width: 108%;
height: auto;
left: 50%;
margin-left: -54.5%;
margin-top: 40px;
position: relative;
z-index: 200;
border: 1px navy solid;
text-align: center;
color: white;
font-size: smaller;
text-transform: uppercase;
padding-top: 3px;
padding-bottom: 3px;
}
.introbanner{
background-color: white;
width: 108%;
height: auto;
left: 50%;
margin-left: -54.5%;
margin-top: 40px;
position: relative;
z-index: 199;
border: 1px gray solid;
text-align: center;
color: black;
font-size: smaller;
text-transform: uppercase;
margin-bottom: 10px;
}
/*Opera Fix*/
body:before {
content:"";
height:100%;
float:left;
width:0;
margin-top:-32767px;/
}
#animals{
width: 100%;
margin-left: 5px;
margin-right: 5px;
margin-bottom: 5px;
text-align: center;
position: relative;
display: block;
height: auto;
}
.animalmugshot{
width: 150px;
height: 150px;
float: left;
position: relative;
}
img{
position: relative
}
</style>
<!--[if !IE 7]>
<style type="text/css">
#wrap {display:table;height:100%}
</style>
<![endif]-->
</head>
<body>
<div id="wrap">
<div id="main">
<div id="content">
<div class="repbanner">
INTRODUCTION
</div>
<div class="instructions">
Hello and thanks for using the Chrome extension Political Animals. Below are the instructions on how the piece works. Enjoy!
<br/>
<br/>
</div>
<div class="dembanner">
Instructions
</div>
<div class="instructions">
Here's how the project works!
1. Surf the Web. Try any website you would like.
2. You should be redirected to a news site. Do not be alarmed!
3. Enjoy!
</div>
<div class="introbanner">
Meet the Cast
</div>
<div id="animals">
<div class="animalmugshot">
<img src="animalshots/thumbnails/PoliticalAnimal.png" alt="Charlie the CEO"/><br/><p>Charlie the CEO</p>
</div>
<div class="animalmugshot">
<img src="animalshots/thumbnails/PoliticalFox.png" alt="Freddy the Financial Agent"/>
<br/>
<p> Freddy the Financial Agent</p>
</div>
<div class="animalmugshot">
<img src="animalshots/thumbnails/PoliticalGiraffe.png" alt="Geoffry the Graphic Designer"/>
<br/>
<p>Geoffry the
<br/>Graphic Designer</p>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
</div>
</body>
The div " animals" and "animalmugshots" should be in the "wrapper" and "content" but for some reason, the animals spill over the white "content" body part. I am confused as to why? Hopefully someone can help me out!
The element, #animals, was collapsing upon itself as the children element were being floated.
Floated and absolutely positioned elements are taken out of the flow of the document, therefore causing the parent element(s) to collapse with undefined dimensions.
Adding a defined height to the parent element, or overflow:hidden will solve this collapsing issue.
Working example - made the footer black for visibility purposes.
#animals {
width: 100%;
margin-left: 5px;
margin-right: 5px;
margin-bottom: 5px;
text-align: center;
position: relative;
display: block;
height: auto;
overflow: hidden; /* Added this.. */
}
Need to clear your floats in #animals or all divs
div:after //OR
#animals:after {
display: table;
content: '';
clear: both;
}