Css problems with positioning - html

I have included 2 photos and my css code below. I am trying to bring my #bottomBar up so its directly under and that its the same width as the black space - you can see in the images below.
Depending on if i use position relative or position absolute i get the desired affect of either being directly under the black space or being the same width. But never both at the same time.
I am using a bootstrap templet in my html, would that cause the issues that i am getting?
css position relative
css position absolute
body{
margin: 0;
padding: 0;
}
.container{
padding: 0;
width: 100vw;
height: 100vh;
background-color: black;
}
#header{
display: flex;
padding: 5px;
width: 100%;
height: 10vh;
background: linear-gradient(to right,white, #a5c6ff, #0066ff);
}
h1{
position: relative;
margin: auto;
font-size: 6vw;
}
#img{
width: 15vw;
}
.navbar{
padding: 5px;
background: linear-gradient(to right,white, #a5c6ff, #0066ff);
}
.navbar-toggler{
display: flex;
padding: 0;
margin: 0;
width: 10vw;
height: 4vh;
}
.navbar-toggler-icon{
height: 3vh;
width: 9vw;
margin: auto;
}
#bottomBar{
position: absolute;
top: 100%;
width: 100%;
}

Related

Positioning of Div in Browser with Absolute scheme

I have 2 Divs both of which are subject to absolute position condition. First Div has top: 200px and second one has top: 400px. However surprisingly, when I see them in Computers with different screen size, their relative positions look quite different. For example, when I see them in Laptop they appear to be closer to each other, whereas when I see then in wide-screen Desktop, they appear to be far.
I wonder, since I have position: absolute for both Divs, shouldn't their relative position be same regardless the screen size I chose?
What I need to do to make them appear in the same position relative to each other regardless the screen size?
CSS details for both Divs
.one {
margin: 0 auto;
padding: 32px 0 0 0;
background-color: rgba(248, 248, 255, 0.15);
height: 140px;
position: absolute;
top: 134px;
width: 100%;
text-align: center;
}
.two {
position: absolute;
margin: auto;
top: 237px;
bottom: 0;
left: 0;
right: 0;
text-align: center;
align-items: center;
}
Thanks for your advice.
The problem is that you're using bottom: 0 for the second div, instead of a height. This means that the bottom of your second div will always be at the bottom of the page, so if you resize it, this div will become taller proportionally to the height of your screen size.
To fix this, I removed the top, left and right positioning and instead applied a height (like in your first div) and a width of 100%.
.one {
position: absolute;
margin: 0 auto;
padding: 32px 0 0 0;
background-color: pink;
height: 140px;
top: 134px;
width: 100%;
text-align: center;
}
.two {
height: 100px;
width: 100%;
position: absolute;
margin: auto;
background-color: steelblue;
top: 237px;
text-align: center;
align-items: center;
}
<div class="one"></div>
<div class="two"></div>
This can be one solution.
*{box-sizing:border-box;}
.one {
position: absolute;
margin: 0 auto;
padding: 32px 0 0 0;
background-color: pink;
height: 140px;
top: 134px;
width: 100%;
text-align: center;
}
.two {
height: 140px;
width: 100%;
position: absolute;
margin: auto;
background-color: steelblue;
top: 274px;
text-align: center;
align-items: center;
}
<div class="one"></div>
<div class="two"></div>
The other solution is to just group them into 1 div, make make that div absolute.
The advantage of this is that u dont have to maintain positioning of 2 divs. Only the parent is enough
* {
box-sizing: border-box;
}
.parent {
position: absolute;
top: 134px;
width:100%;
left:0;
right:0;
}
.one {
margin: 0 auto;
padding: 32px 0 0 0;
background-color: pink;
height: 140px;
width: 100%;
text-align: center;
}
.two {
height: 140px;
width: 100%;
margin: auto;
background-color: steelblue;
text-align: center;
align-items: center;
}
<div class="parent">
<div class="one"></div>
<div class="two"></div>
</div>
In other to make look same regardless of screen size, you have to set the properties say left=0 , right=0 and bottom=0for bottom div and then you could control the height using different top values. Doing this you have make both div behave like a block container with absolute position and their placement will not shift each other like relative.
.one {
margin: 0 auto;
padding: 32px 0 0 0;
background-color: red;
height: 140px;
position: absolute;
top: 134px;
left: 0;
right: 0;
bottom:0;
width: 100%;
text-align: center;
border: 1px solid blue;
}
.two {
position: absolute;
margin: auto;
top: 237px;
bottom: 0;
left: 0;
right: 0;
text-align: center;
align-items: center;
background-color: green;
border: 1px solid blue;
}
<div class="one">
1
</div>
<div class="two">
2
</div>

Keeping the footer on the bottom of the page?

I know this is a common issue but I just can't work this out. No matter how many combinations of settings I try, the footer won't stay on the bottom of the page. It will just sit under whatever else is above it.
body {
margin: 0;
background-color: #ACFAB7;
}
# container {
margin: 0 auto;
padding: 40px;
}
#header {
z-index: 0;
height: 78px;
background-color: #2ecc71;
}
#footer {
z-index: 2;
height: 40px;
width: 100%;
padding: 0px;
position: relative;
background-color: #2ecc71;
/*display required to center text*/
display: table;
text-align: center;
margin-left: auto;
margin-right: auto;
}
#image {
z-index: 1;
margin: 20px auto;
padding: 50px;
}
/*Centers text within the header*/
span {
display: table-cell;
vertical-align: middle;
}
You have a lot of problems. This solution is for:
Fixing your footer at the end of the page.
Centering the contents (both vertically and horizontally).
Fixes
Get rid of display: table.
Get rid of width: 100%.
Change relative to fixed.
#footer {
z-index: 2;
line-height: 40px;
padding: 0px;
position: fixed;
background-color: #2ecc71;
text-align: center;
left: 0; right: 0;
bottom: 0;
}
<div id="footer">Copyrights.</div>
position: fixed; and bottom: 0; should do the trick. Add width and height as neccessary.
.footer {
position: fixed;
bottom: 0;
width: 100%;
height: 30px;
background-color: aquamarine;
}
<div style="background-color: lightgrey;height: 800px">
Page content
</div>
<div class="footer">
this is the footer
</div>
You can use position: fixed; bottom: 0;
#footer {
z-index: 2;
height: 40px;
width: 100%;
padding: 0px;
background-color: #2ecc71;
text-align: center;
margin-left: auto;
margin-right: auto;
position:fixed;
bottom:0;
left: 0;
}
<div>
<footer id="footer">Footer</footer>
</div>

How to place a footer at the bottom of a page in CSS?

I tried to create a page footer for each page. The objectif is to center the footer and to place it at the bottom of the page. You can check my JSFiddle, or see the code directly as following.
HTML
<div id="page1" class="page">
<div class="footer">
<p>1</p>
</div>
</div>
CSS
div.page {
height: 300px;
width: 180px;
border: 1px solid #000;
margin: auto;
margin-bottom: 5px;
text-align: center;
}
div.footer {
background-color: #DDD;
width: 100%;
bottom: 0; /* doesn't work */
}
p {
width: 15px;
color: white;
background-color: red;
text-align: center;
margin: auto;
bottom: 0;
}
I saw to similar question about How to position div at the bottom of a page ?. However, when i applied its proposition, bottom + position setting, footers in each page are all merged together, placed at the bottom of the navigator's windows. Here's the related JSFiddle
Can somebody help ? Thanks a lot.
You are missing position: relative; applied to the class="page".
This way the element which has absolute position applied knows that needs to be bottom:0 relative to the parent element .page.
div.page {
height: 300px;
width: 180px;
border: 1px solid #000;
margin: auto;
margin-bottom: 5px;
text-align: center;
position:relative;
}
div.footer {
background-color: #DDD;
width: 100%;
bottom: 0; /* it works now */
position: absolute;
}
p {
width: 15px;
color: white;
background-color: red;
text-align: center;
margin: auto;
bottom: 0;
}
DEMO http://jsfiddle.net/9xzb9m48/3/
Try this:
div.page {
height: 300px;
width: 180px;
border: 1px solid #000;
margin: auto;
margin-bottom: 5px;
text-align: center;
position: relative;
}
div.footer {
background-color: #DDD;
width: 100%;
position: absolute;
bottom: 0;
}
p {
width: 15px;
color: white;
background-color: red;
text-align: center;
margin: auto;
bottom: 0;
}

Whitespace between content and footer in Ebay listing template.

I'm designing an ebay template. However, a problem that I keep running into is that there seems to be a whitespace which I can't get rid of between the mainContainer div and the footer. I have highlighted the two divs with green and red to make the problem clear.
I want to know how I can get rid of the whitespace, and have the two divs underneath each other.
http://jsfiddle.net/4vembvLg/
Help is appreciated.
The whole code is on jsfiddle
* {
margin: 0;
}
html, body {
height: 100%;
padding: 0;
margin: 0;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto;
}
.footer {
height: 600px;
margin: 0;
padding: 0;
background-color: red;
}
#top-bar {
background: url(http://demo.presthemes.com/centrikids/themes/pt_centrikids/img/bg_topbottom.png) repeat-x;
height: 15px;
}
Remove the top rule in the mainContainer class and pageContainer id
.mainContainer {
background-color: green;
height: 900px;
margin: 0;
overflow: hidden;
padding: 0;
position: relative;
text-align: left;
/* top: -400px; */
width: 100%;
}
#pageContainer {
font-family: Arial,Helvetica,sans-serif;
font-size: 12px;
font-style: normal;
margin: 0 auto;
padding: 0;
position: relative;
/* top: -267px; */
width: 1393px;
}
I believe I found your issue, top: -400px;
.mainContainer {
background-color: green;
height: 900px;
width: 100%;
/* background: #f8f8f8; */
padding: 0;
overflow: hidden;
margin: 0;
text-align: left;
position: relative;
top: -400px; <----------------This Guy here
}

(html/css) How do I remove the margin appearing from my header, and have it only apply to my Logo?

I am trying to create a header for my website, with a logo contained. I wish for the logo to have a 5 pixel margin from the top of the header div that it is contained inside, however when I add "margin-top: 5px" to the div containing the logo, the header div is push 5 pixels down instead.
<div id="background">
<div id="HeaderGrey">
<div id="HeaderLogo">
<img src="CHBadgeLogo.png" />
</div>
</div>
<div id="HeaderShaderTop"></div>
<div id="HeaderShaderBottom"></div>
</div>
CSS
body {
margin: 0;
padding: 0;
}
#background {
left: 0px;
top: 0px;
position: relative;
margin-left: auto;
margin-right: auto;
width: 100%;
height: 600px;
overflow: hidden;
z-index:0;
background-color: #303030;
}
#HeaderGrey {
background-color: #676767;
height: 94px;
width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin-top: 0px;
}
#HeaderShaderTop {
background-color: #0e453d;
height: 2px;
width: 100%;
}
#HeaderShaderBottom {
background-color: #009d89;
height: 2px;
width: 100%;
}
#HeaderLogo{
margin-top: 5px;
margin-left: 28px;
height: 85px;
width: 86px;
}
I'm assuming this would have a pretty easy fix, I'm just new to html/css, sorry.
The positioning works only when you put the parent (containing) element as non-static, like relative. Then you can position the element with relative or absolute (taking it out of the flow).
Like so:
body {
margin: 0;
padding: 0;
position:relative;
}
#background {
left: 0px;
top: 0px;
margin-left: auto;
margin-right: auto;
width: 100%;
height: 600px;
overflow: hidden;
z-index:0;
background-color: #303030;
position:relative;
}
#HeaderGrey {
background-color: #676767;
height: 94px;
width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin-top: 0px;
position: relative;
}
#HeaderShaderTop {
background-color: #0e453d;
height: 2px;
width: 100%;
}
#HeaderShaderBottom {
background-color: #009d89;
height: 2px;
width: 100%;
}
#HeaderLogo{
margin-top: 5px;
margin-left: 28px;
height: 85px;
width: 86px;
position: absolute;
}
Very nice Question,
I see that you know how to use padding which is good. If just simply add a padding-top: 5px; to the image div it should just move the image down 5px from the top of the navbar!