Absolute positioned div element affects document flow structure. Why? - dom

As I read and understand, an absolute positioned element is ignored by the parent and removed from the DOM flow, but in my example (please see the code snippet) it's not behaving like that. In my opinion, the absolute positioned child element should be ignored by the parent div and thus the outer container shouldn't be expanded to contain the child. Why is that? And how should I solve that (keeping the containers scrollHeight unexpanded by the child)? Thanks in advance.
#container {
width: 300px;
height: 300px;
background-color: grey;
display: flex;
flex-flow: row wrap;
justify-content: center;
overflow-y: scroll;
gap: 10px;
padding: 10px 0;
}
.icon {
width: 120px;
height: 120px;
background-color: green;
position: relative;
}
#absolutePositionedChild{
position: absolute;
width: 50px;
height: 300px;
background-color: red;
top: 35px;
left: 35px;
}
<div id="container">
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"><div id="absolutePositionedChild"></div></div>
</div>

The absolute positioned element is positioned relative to the nearest ancestor.
It means your absolute positioned element will position itself relative to the nearest parent element which has the property, position: relative
If it does not have a positioned ancestor, then it will use the document body.
#container {
width: 300px;
height: 300px;
background-color: grey;
display: flex;
flex-flow: row wrap;
justify-content: center;
overflow-y: scroll;
gap: 10px;
padding: 10px 0;
}
.icon {
width: 120px;
height: 120px;
background-color: green;
position: relative;
}
#absolutePositionedChild{
position: absolute;
width: 50px;
height: 120px;
background-color: red;
top: 0px;
left: 35px;
}
<div id="container">
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"><div id="absolutePositionedChild"></div></div>
</div>

Related

How to apply an overlay on an image using CSS?

I try to do this way but it does not work. How can I overlay on an image.
<div class="banner_img">
<img src="images/catimage.jpg" alt="It is a cat image" width="300px" height="200px"> <br/>
</div>
Edit the code to fit your needs.
CSS & HTML:
* {box-sizing: border-box;}
.container {
position: relative;
width: 50%;
max-width: 300px;
}
.img{
display: block;
width: 100%;
height: auto;
}
.youroverlaydiv{
position: absolute;
bottom: 0;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.5); /* Black see-through */
color: #f1f1f1;
width: 100%;
transition: .5s ease;
opacity:0;
color: white;
font-size: 20px;
padding: 20px;
text-align: center;
}
.container:hover .youroverlaydiv{
opacity: 1;
}
<div class="container">
<div class="banner_img">
<img src="https://images.unsplash.com/photo-1524749292158-7540c2494485?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80" alt="It is a cat image" width="300px" height="200px" class="img">
<div class="youroverlaydiv">This is your overlay.</div>
</div>
</div>

Mapbox Bug with Zoom Control

I’m using mapbox.directions v0.3.0. I have come across a bug with the Zoom Control when using Internet Explorer only. It works fine with Edge, Chrome, and Firefox. I have the following layout:
<div id="pnlMapControl">
<div id="pnlRoutePane">
<div id="divRouteInputs"></div>
<div id="divRouteErrors"></div>
<div id="divRouteDirections">
<div id="divAlternateRoutes"></div>
<div id="divRouteInstructions"></div>
</div>
</div>
<div id="pnlMap"></div>
<div id="pnlStatusBar">
<span id="lblStatus">Status</span>
<span id="lblLatLon" style="float:right">LatLon</span>
</div>
</div>
pnlMapControl is a top level container control. pnlMap is the container for the Mapbox map. pnlRoutePane is where I want to have my input controls and display the instructions. I would prefer to keep the controls separate from the map container. pnlRoutePane is positioned on the left (and its visibility is toggled on and off so it is only visible when working with a route), and pnlMap is on the right.
My issue is, in IE11, when I click the zoom control on the map, it causes the parent pnlMapControl container to move left the width of pnlRoutePane and displays the Mapbox map at left position 0. All other browsers work without this issue. Is there something that can be done so that it will also work with IE?
Thanks in advance. My CSS is below:
#pnlMapControl {
position: absolute;
left: 0px;
right: 0px;
top: 60px;
bottom: 0px;
background-color: red;
}
#pnlRoutePane {
position: absolute;
left: 0px;
width: 300px;
top: 33px;
bottom: 20px;
background-color: lightseagreen;
display: none;
}
#pnlMap {
left: 0px;
top: 0px;
width: 100%;
height: 100%;
background-color: lightyellow;
}
#pnlStatusBar {
position: absolute;
left: 0px;
right: 0px;
bottom: 0px;
height: 20px;
background-color: lightblue;
}
#lblStatus {
margin-left: 5px;
vertical-align: middle;
}
#lblLatLon {
margin-right: 5px;
vertical-align: middle;
}
#divRouteInputs {
position: absolute;
top: 10px;
left: 10px;
width: 280px;
height: 80px;
background-color:yellow;
}
#divRouteErrors {
position: absolute;
top: 120px;
left: 10px;
padding: 10px;
border-radius: 0 0 3px 3px;
background: rgba(0,0,0,0.25);
}
#divRouteDirections {
position: absolute;
top: 120px;
left: 10px;
bottom: 0px;
overflow: auto;
background: rgba(0,0,0,0.8);
}

Keep footer on every page

I'm trying to keep my footer at the bottom of every page (not sticky). At the moment it is hovering in the middle of the screen.
Here is my site.
And here is the code I have at the moment -
HTML -
<footer id="footer">
<a class="right">All Rights Reserved © 1-800 Dinosaur 2014 </a>
</div>
</footer> <!-- footer --->
CSS -
#footer {
-moz-box-sizing: border-box;
background: transparent;
bottom: 0;
color: #444444;
font-family: 'Helvetica Neue',Helvetica,sans-serif;
font-size: 15px;
font-weight: 600;
height: 100px;
left: 0;
overflow: hidden;
padding: 44px;
position: absolute;
right: 0;
text-align: center;
width: 100%;
}
#footer a {
-moz-box-sizing: border-box;
background: transparent;
bottom: 0;
color: #FFFFFF;
height: 100px;
left: 0;
padding: 44px;
position: absolute;
right: 0;
text-align: center;
width: 100%;
}
#footer a:hover {
color: #000000;
}
#footer a:active {
background: transparent;
}
#footer .last-page {
text-align: center;
What am I doing wrong?
In my experience, absolute positioning has only worked if it was only in a parent specified to have relative positioning. Try putting your footer in a div with style="position: relative;" and see if that works. It actually looks like you've included a closing div tag without an open one in your snippet.

iPhone is adding a top margin to image

When checking my responsive site on my laptop it's scaling nicely using percentages, but when I check it on my iPhone it adds a huge top margin to my vertical row of images. Any ideas why? The site is here http://edharrisondesign.com/pocketpictograms/
Thanks in advance!
The HTML:
<!-- Pocket
================================================== -->
<figure>
<div class="main-pocket"><img src="images/assets/pocket.png"></div>
<div class="padding"></div>
</figure>
<!-- Icons
================================================== -->
<div class="inside-pocket">
<div class="icon-container">
<img class="pictogram" src="images/pocket-pics/pencil.png">
<img class="pictogram" src="images/pocket-pics/iphone.png">
<img class="pictogram" src="images/pocket-pics/earphones.png">
<img class="pictogram" src="images/pocket-pics/camera.png">
<img class="pictogram" src="images/pocket-pics/film.png">
<img class="pictogram" src="images/pocket-pics/scalpol.png">
<img class="pictogram" src="images/pocket-pics/paintbrush.png">
<img class="pictogram" src="images/pocket-pics/fineliner1.png">
<img class="pictogram" src="images/pocket-pics/fineliner2.png">
<img class="pictogram" src="images/pocket-pics/notepad.png">
<img class="pictogram" src="images/pocket-pics/mouse.png">
<img class="pictogram" src="images/pocket-pics/glasses.png">
<img class="pictogram" src="images/pocket-pics/lighter.png">
<img class="pictogram" src="images/pocket-pics/pipe.png">
<img class="pictogram" src="images/pocket-pics/flask.png">
<img class="pictogram" src="images/pocket-pics/matches.png">
<img class="pictogram" src="images/pocket-pics/watch.png">
<img class="pictogram" src="images/pocket-pics/pocket-watch.png">
<img class="pictogram" src="images/pocket-pics/key.png">
<img class="pictogram" src="images/pocket-pics/car-key.png">
</div>
</div>
The CSS:
figure {
z-index: 97;
position: fixed;
overflow: hidden;
width: 100%;
height: 100%;
top: 40%;
text-align: center;
}
.padding {
z-index: 95;
position: relative;
background-color: #D2D2D2;
height: 100%;
width: 100%;
top: -50px;
overflow: hidden;
border-bottom: 50px solid #D2D2D2;
}
.main-pocket img {
z-index: 96;
position: relative;
width: 30%;
height: auto;
margin: 0 auto;
max-width: 300px;
}
.inside-pocket {
width: 100%;
height: 100%;
position: absolute;
margin: 0 auto;
text-align: center;
}
.icon-container {
position: relative;
max-width: 300px;
width: 30%;
top: 37%;
margin: 0 auto;
}
.pictogram {
height: auto;
width: 100%;
margin-bottom: 200%;
}
Okay I know where I was going wrong - I should have been setting the top margin to the .inside-pocket class rather than the .icon-container class. The markup is here:
/* #Pocket
================================================== */
figure {
z-index: 97;
position: fixed;
overflow: hidden;
width: 100%;
height: 100%;
top: 40%;
text-align: center;
}
.padding {
z-index: 95;
position: relative;
background-color: #D2D2D2;
height: 100%;
width: 100%;
top: -50px;
overflow: hidden;
border-bottom: 50px solid #D2D2D2;
}
.main-pocket img {
z-index: 96;
position: relative;
width: 30%;
height: auto;
margin: 0 auto;
max-width: 300px;
}
.inside-pocket {
width: 100%;
height: 100%;
top: 37%;
position: absolute;
margin: 0 auto;
text-align: center;
}
.icon-container {
position: relative;
max-width: 300px;
width: 30%;
margin: 0 auto;
}
.pictogram {
height: auto;
width: 100%;
margin-bottom: 200%;
}
If anyone could let me know WHY this is correct it would be great! Cheers

Renders centered on PC browser but not align in iphone browser

Well, i have one centered div used as a footer simply by: <div id="bottom-footer">Powered by Coolname</div> and the style:
#bottom-footer {
width: 100%;
height: 20px;
position: absolute;
bottom: 1px;
text-align: center;
}
And that renders ok in PC browser:
But when you tried on an iphone, its looks like this:
Clearly not centered, what im doing wrong?
looks like there is a margin or a padding on the containing body element or the div itself. Add this to your style sheet to reset the browsers natural behaviour:
html {
margin:0px;
padding:0px;
}
body {
margin:0px;
padding:0px;
}
#bottom-footer {
width: 100%;
height: 20px;
position: absolute;
bottom: 1px;
text-align: center;
margin:0px;
padding:0px;
}
Remove width:100%
#bottom-footer {
height: 20px;
position: absolute;
bottom: 1px;
text-align: center;
}