absolute positioned element extends past sticky footer - html

I have a dynamic mega menu item when opened the height varies depending on the data, often the height will cause the element to extend past the sticky footer (also position absolute), which is not really what i want at all, is there any solution other than creating unnesesary content to fill the void?
html -
<nav class="menu__base drop-shadow--standard desktop" style="background:#034774;;">
<div class="container">
<ul class="menu__items menu__items--hidden">
<li class="menu__item menu__sub-menu-item">nav item</li>
<li class="menu__item menu__sub-menu-item">nav item</li>
<li class="menu__item menu__sub-menu-item open">
<span class="menu__sub-menu-item__title">Open nav item</span>
<span class="menu__item__hover-underline"></span>
<div class="menu__sub-menu-wrapper drop-shadow--standard" style="height: 732px; left: -2px; background-color: #034774;">
<div class="menu__sub-menu" style="margin-top: 0px;">
<div class="menu__mega-menu">
<div class="mega-menu-multi-race ">
<table class="mega-menu-multi-race__table">
content, lots and lots of content inside the open nav item
</table>
</div>
</div>
</div>
</div>
</li>
<li class="menu__item menu__sub-menu-item">nav item</li>
</ul>
</div>
</nav>
<div class="container">
<p>
content inbetween
</p>
</div>
<div class="container">
<p>
more content
</p>
</div>
<div class="container">
<p>
more content.............
</p>
</div>
<footer class="container-fluid footer">
<section class="row">
<div class="container padding-all-10">
<div class="footer__info">
<div class="col-lg-6 col-md-6 col-xs-12 padding-lf-0">
<p class="margin-all-0">Sticky footer</p>
</div>
</div>
</div>
</section>
</footer>
css -
.menu__sub-menu-wrapper {
position: absolute;
top: 100%;
left: 0;
overflow: hidden;
margin-top: 2px;
left: -2px;
}
.menu__sub-menu {
left: 0;
top: 0;
}
.menu__item {
float: left;
position: relative;
border-right: solid 2px #053b5e;
font-weight: bold;
font-size: 17px;
list-style-type: none;
min-width: 100px;
text-align: center;
padding:5px;
}
.menu__items {
list-style-type: none;
margin: 0;
padding: 0;
float: left;
}
.footer {
width: 100%;
background:red;
font-size: 17px;
position: absolute;
bottom: 0;
}
link to fiddle - https://jsfiddle.net/2648daniel/wo3jxjb8/

Dan,
I have modified your fiddle a fair bit and have achieved what you are after. The menu no longer overlaps the footer and scales as required, based on a fixed height or whatever content within that block.
https://jsfiddle.net/2gLLkoks/7/
In summary I have used a combination of floating elements left/clearing the floats as appropriate. eg
.menu__sub-menu-wrapper {
float:left;
...
.menu__sub-menu {
float:left;
...
....
<div class="clear"></div>
</nav>
etc
I have also removed the absolute positioning from the elements and added a content wrapper which is absolutely positioned with a negative z-index so it appears under the sub menu.
.containerWrapper {position:absolute;top:50px;float:left;z-index:-1}
<div class="containerWrapper">
<div class="container">
<p>
more content...........
Hope this helps ;)

Related

Two sidebars issue

I have problem with sidebars on my website. I have two sidebars both 250px, one is on the left side and the second on the right side and have between div with content. That left sidebar is ok but that second doesnt want to change place for the right side and is on the left on place that first.
.info {
float: right;
position: fixed;
z-index: 1000;
height: 100%;
width: 250px;
padding-right: 0;
padding-top: 50px;
box-sizing: border-box;
}
.sidebar-menu {
position: fixed;
z-index: 1000;
height: 100%;
width: 250px;
display: block;
padding-left: 0;
padding-top: 50px;
box-sizing: border-box;
}
.content-main {
height: 100%;
padding-top: 56px;
width: 100%;
}
<div class="fluid-container">
<ul class="sidebar-menu">
<div class="photo">
</div>
<div class="name">
<h2 class="getname">Tommy Hilfiger</h2>
</div>
<div class="active">
<p class="menu">Activity</p>
</div>
<div class="followers">
<p class="menu">Followers</p>
</div>
<div class="friends">
<p class="menu">Friends</p>
</div>
<div class="photos">
<p class="menu">Photos</p>
</div>
<div class="edit">
<p class="menu">Edit</p>
</div>
</ul>
<ul class="info">
<div class="aqt">
</div>
</ul>
<div class="content-main">
</div>
</div>
First, don't use <ul> with <div>, you should use <ul><li>...</li></ul> otherwise change <ul> to <div> (<ul> is unordered list, <li> is list item).
Secondly, the way you're building the html, you're not splitting <div> elements (division), you're actually building one block with two lists and a division.
if you want to have [SideBar][Content][secondBar] use this:
<div class="wrapper">
<div class="leftbar">
anything
</div>
<div class="content">
</div>
<div class="rightbar">
</div>
</div>
Use the following css as fundamental, style after:
div.wrapper{
display: grid;
grid-template-areas: "leftbar content rightbar";
grid-template-rows: 1fr;
}
div.leftbar{
grid-area: leftbar;
}
div.content{
grid-area: content;
}
div.rightbar{
grid-area: rightbar;
}

adding margin-left creates horizontal scroll bar to white space

I'm writing the CSS for my site. I have text that I am putting on top of my background image. My HTML and CSS is below:
HTML
<header class="site-header">
<div class="site-header__menu-icon">
<div class="site-header__menu-icon__middle"></div>
</div>
<div class="site-header__menu-content">
<div class="site-header__btn-container">
Request A Demo
</div>
<nav class="primary-nav primary-nav--pull-right">
<ul>
<li>Home</li>
<li>Services</li>
<li>Why Us</li>
</ul>
</nav>
</div>
</div>
</header>
<div class="section">
<picture>
<img src="assets\images\pepper.jpg">
</picture>
<div>
<div class="section__text-content">
<h1 class="section__title">Company</h1>
<h3 class="section__sub-title">Company Slogan</h3>
<div class="btn-container">
<a class="btn" href="#">Talk To A Specialist</a>
<a class ="btn btn__white btn__pepper-white" href="#">Get A Quote</a>
</div>
</div>
</div>
</div>
CSS
.section {
position: relative;
max-width: 100%;
&__text-content {
position: absolute;
top: 30%;
width: 100%;
margin-left:
}
&__title {
font-size: 7rem;
font-weight: 300;
color: #ffffff;
margin-bottom: 0;
}
&__sub-title {
font-size: 2.5rem;
font-weight: 300;
margin-top: 3%;
margin-bottom: 2%;
color: #ffffff;
}
}
The problem arises when I try to add a margin-left to the .section class in my CSS, because then a blank which space to the right of my screen appears with a horizontal scroll bar in direct proportion to the amount of margin I specified to move to the left.
I know that I could use a simple "background-image" for my css, but I'd prefer to do it this way for responsive imaging (it's how I learned to do it and I'm on a bit of a time crunch).
Any suggestions?
FIXED
My problem was I was writing my margin in relative terms by doing:
.section__text-content {
position: absolute;
margin-left: 10%
}
Which is wrong, because the &__text-content is set to position: absolute
Percentage is relative position, with an absolutely positioned image you need absolute margins (i.e. pixels)

Sticky footer container that doesn't overlap other content

I have a sidenav which has a container with social media context that is meant to stick to the bottom of the sidenav which spans the entire view-port height like so:
sidenav {
height: 100%;
background: #007979;
left: 0;
position: fixed;
text-align:
width: 25rem;
}
The sidenav immediate child is a container which has it's position property set to relative to I can then assign a position property and value to the social media container to stick to the bottom, like so:
sidenav-inner {
position: relative;
height: 100%;
}
My issue is that if I set the social media containers position property to either absolute or relative, if the view-port height is adjusted slightly, the social media container overlaps the navigation list that is at the top, as it is positioned in correspondence to the sidenav-inner container.
Question
How do I position the social media container at the bottom of the sidenav, without using the position proeprty? Or how do I use the position property without it overlapping other content in the sidenav?
<nav class="sidenav">
<div class="sidenav-inner">
<div class="sidenav-header">
<div class="row">
<div class="col-md-12">
<img src="/">
</div>
</div>
</div>
<ul class="nav">
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
</ul>
<div class="side-nav-social">
<div>
//social media content
</div>
//more social media content
</div>
</div>
</nav>
You can easily solve this by defining .sidenav-inner as a flexbox and then having the header and footer not grow, but the ul grow to take up all the space. It will thus push the social media to the bottom of the box.
.sidenav {
height: 100%;
background: #007979;
left: 0;
position: fixed;
text-align:
width: 25rem;
}
.sidenav-inner {
position: relative;
height: 100%;
display: flex;
flex-direction: column;
}
.sidenav-header {
flex: 0 1 auto;
}
.sidenav-inner ul {
flex: 1 0 auto;
}
.side-nav-social {
flex: 0 1 auto;
}
https://jsfiddle.net/d2u85u4q/
You can do it like this:(be aware of margins)
html
<nav class="sidenav">
<div class="sidenav-inner">
<div class="sidenav-header">
<div class="row">
<div class="col-md-12">
header
<img src="/">
</div>
</div>
</div>
<ul class="nav sidenav-body">
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
<li><a>Item</a></li>
</ul>
<div class="side-nav-social">
<div>
//social media content
</div>
//more social media content
</div>
</div>
</nav>
css:
.sidenav {
height: 250px;
background: #007979;
left: 0;
position: fixed;
width: 200px;
}
.sidenav-inner {
position: relative;
height: 90%;
}
.sidenav-header{
height:10%;
}
.sidenav-body{
overflow:auto;
height:70%;
}
.side-nav-social{
position:absolute;
bottom:0;
height:10%;
}
plnker code

Centering div content within multiple nested divs

I am trying to center some so that they are displayed within the center, however the tricky part is the html is within a number of (part of the html is static, and part of it is dynamic from a database).
See the screenshot as an example of how it currently looks (I want this content in the centre)
http://postimg.org/image/5fc6ecgy7/
note - the site is using the base 960 grid system
Below is the HTML:
<div class="">
<div class="">
<div class="">
<div id="national-prize-feed" class="panel-wrapper ">
<div class="border">
<div class="content clearfix add-radius">
<div style="padding:10px 0px;">
<div id="nation-prizes-collection" class="clearfix">
<div class="summary"></div>
<div class="">
<div class="national-prizes">
<div class="prizes">
<img class="prizes-img" alt="iPod Shuffle" src="/images/prizes/ipod-shuffle.png">
</div>
</div>
<div class="national-prizes">
<div class="prizes">
<img class="prizes-img" alt="Football" src="/images/prizes/football.png">
</div>
</div>
</div>
<div class="keys" title="/pages/index/slug/prizes" style="display:none">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
My specific css (there is a lot more.. it is based on a grid based layout)
div.prizes {
float: left;
}
div.prizes img {
width: 280px;
}
.prizes-img {
padding: 0 7px 0 7px;
margin: 7px 5px 7px 5px;
max-width: 100%;
height: auto;
}
In order to position a DIV to the center of a screen, you need to set a static width of the div to be centered, left: 0px, right: 0px, and the respective margins to auto.
Here is an example: http://jsfiddle.net/pR4hq/
<style>.center{
position: relative;
display: block;
width: 120px;
background: rgb(90,90,90);
left: 0px;
right: 0px;
margin-left: auto;
margin-right: auto;
text-align: center;
}</style>
<div class="center">Center Content</div>

evenly distribute divs in footer

I have a footer in my webpage which nests 3 divs with twitter bootstraps span4 class. I want to have the 'Connect With Us' the same distance from the right as the 'Contact Us' header is from the left and the 'Useful Links' in the middle with all the text for each div left justified underneath.
This is what I have so far:
You can see that Contact Us is closer to the left edge than Connect With Us is from the right edge.
I have tried using text align for the headers which works however the list items below do not left align with the elements.
Here is an image which shows what it is like with the text-align on the headers. You can see that they are laid out as I want but the content below them is not left aligned with them:
Here is the HTML for the footer:
<footer class="footer">
<div class="row-fluid">
<div class="span12">
<div class="span4" id="leftFooter">
<h5><b>Contact Us</b></h5>
<ul>
<li>Tel: 01234 567897</li>
<li>E-mail: info#oom.com</li>
</ul>
</div>
<div class="span4" id="middleFooter">
<div class="middle"><h5><b>Useful Links</b></h5>
<ul>
<li>Contact Us</li>
<li>About Us</li>
<li>Copyright Information</li>
<li>Terms & Conditions</li>
</ul> </div>
</div>
<div class="span4" id="rightFooter">
<h5><b>Connect With Us</b></h5>
<ul>
<li><img src="images/facebook/png/FB-f-Logo__blue_29.png" width="29px" height="29px"> Facebook</li>
<li><img src="images/twitter/twitter-bird-white-on-blue.png" width="29px" height="29px"> Twitter</li>
</ul>
</div>
</div>
</div>
</footer>
Here is the CSS for the footer:
.footer {
padding: 10px;
position: relative;
color: #ccc2a0;
background-color: #333333;
height: 150px;
clear:both;
padding-top:20px;
}
.footer ul {
list-style: none;
padding: 0;
margin: 0;
}
#leftFooter {
color: #ccc2a0;
padding-left: 50px;
}
#middleFooter {
color: #ccc2a0;
/* text-align: center; */
}
#rightFooter {
padding-right: 50px;
/*text-align: right; */
color: #ccc2a0;
}
#rightFooter li {
padding-top: 5px;
}
.follow { line-height: 19px; }
Can anyone help?
Thanks
EDIT:
Here are the changes I made to the right footer:
<div class="span4" id="rightFooter">
<div class="trow"> <h5 class="tcell"><b>Connect With Us</b></h5> </div>
<ul>
<div class="trow"> <li class="tcell"><img src="images/facebook/png/FB-f-Logo__blue_29.png" width="29px" height="29px"> Facebook</li> </div>
<div class="trow"> <li class="tcell"><img src="images/twitter/twitter-bird-white-on-blue.png" width="29px" height="29px"> Twitter</li> </div>
</ul>
</div>
CSS:
.trow {
display: table-row;
background-color: green;
margin-right: 0;
}
.tcell {
display: table-cell;
background-color: green;
}
.trow h5 {
display: table-row;
background-color: yellow;
}
and here is what it looks like with the rows and cells coloured:
You can use display: table-cell to make the block behave as table cells, which can style further to make them the same width.
You can also float the blocks or use display: inline-block and give each block a third of the width, but when zooming you may get rounding errors that can cause the last block to jump to the next line. When the block behave like table-cells, you don't have that problem.
I renamed some of your CSS ids and removed some markup in your HTML like the b tag (not sure why you were using that). Your ampersand & should be &.
Added a couple DIVs .outer and .inner that center the contents of the second .span4 but maintain the left alignment. The main thing there is the float: left; on .outer which sets the width of .outer to it's content. You could also use display: inline-block; instead of float: left;. .outer is moved left 50% of it's container and then .inner is moved right 50% of it's container (.outer). In the end it ends up in the center of .span4.
For the third .span4 we added a DIV with the class .pull-right which is from your Twitter Bootstrap that floats things to the right. This sets everything to the right side of the third .span4 without re-aligning your text.
.footer {
padding: 10px;
position: relative;
color: #ccc2a0;
background-color: #333333;
height: 150px;
clear:both;
padding-top:20px;
}
.footer ul {
list-style: none;
padding: 0;
margin: 0;
}
#contact-us {
padding-left: 50px;
}
.outer {
position: relative;
left: 50%;
float: left;
}
.inner {
position: relative;
right: 50%;
}
#connect-with-us {
padding-right: 50px;
}
#connect-with-us li {
padding-top: 5px;
}
#connect-with-us a {
padding-left: 5px;
}
.follow {
line-height: 19px;
}
<footer class="footer">
<div class="row-fluid">
<div class="span12">
<div id="contact-us" class="span4">
<h5>Contact Us</h5>
<ul>
<li>Tel: 01234 567897</li>
<li>E-mail: info#oom.com</li>
</ul>
</div>
<div class="span4">
<div class="outer">
<div class="inner">
<h5>Useful Links</h5>
<ul>
<li>Contact Us</li>
<li>About Us</li>
<li>Copyright Information</li>
<li>Terms & Conditions</li>
</ul>
</div>
</div>
</div>
<div id="connect-with-us" class="span4">
<div class="pull-right">
<h5>Connect With Us</h5>
<ul>
<li><img src="images/facebook/png/FB-f-Logo__blue_29.png" width="29px" height="29px">Facebook</li>
<li><img src="images/twitter/twitter-bird-white-on-blue.png" width="29px" height="29px">Twitter</li>
</ul>
</div>
</div>
</div>
</div>
</footer>