Overflow auto does not show all content - html

So I'm trying to make an hamburger menu, and when the button is clicked it comes from top since it's styled as top: -100% at the beginning.
It's working fine but when its height is bigger than window height, overflow: auto makes vertical scroll so i can get to the bottom of menu.
The problem is that i cant always get to the very bottom and i dont see the bery last item, because it depends on window height.
.header__menu_mobile {
position: fixed;
top: -100%;
left: 0;
padding: 0;
width: 100%;
height: 100%;
background-color: white;
color: #252525;
z-index: 3;
overflow: auto;
transition: all 0.3s ease 0s;
}
.header__menu_mobile .header__list {
font-weight: 300;
font-size: 16px;
line-height: 19px;
width: 100%;
}
.header__menu_mobile .header__list li {
width: 100%;
padding: 20px 0;
}
.header__menu_mobile .header__list li a {
text-decoration: none;
color: #252525;
}
.header__menu_mobile.active {
top: 63px;
}
<div class="header__menu_mobile">
<div class="container">
<ul class="header__list">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
<li>Item 7</li>
<li>Item 8</li>
</ul>
<div class="contacts">
<a class="contact">Email</a>
<a class="contact">Instagram</a>
<a class="contact">Facebook</dav>
</div>
</div>
</div>
Meybe the problem is top: 63px while menu is active, but in this layout it has to be excactly like this. When i change it to top: 0, overflow auto shows me the last item on every window height.
So meybe these 63px is also taken away from the bottom of menu. But what should i do?

Thanks for help. The problem was solved when i changed height: 100% to height: calc(100% - 63px);. Thanks #Cbroe and #DiegoD for help

Related

How to I prevent dropdown menu from closing when moving cursor away from parent element?

What's a good solution in this case if I want to prevent dropdown menu from closing as mouse moves away from parent to dropdown menu. Dropdown menu should be further away from parent li element but should not close when I want to access dropdown menu. If cursor is moved away from nav completely then dropdown should close.
My html
<nav>
<ul class="primary-menu">
<li>item
<ul class="sub-menu">
<li>item 6</li>
<li>item 7</li>
</ul>
</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
<li>item 5</li>
</ul>
</nav>
My SCSS
nav {
.primary-menu {
display: flex;
gap: 24px;
position: relative;
li {
color: black;
.sub-menu {
position: absolute;
display: none;
background: red;
border-radius: 4px;
padding: 12px 24px;
top: calc(100% + 24px);
&:before {
position: absolute;
content: "";
width: 0;
height: 0;
border-style: solid;
border-width: 0 12px 12px 12px;
border-color: transparent transparent red transparent;
top: -12px;
}
li {
padding: 8px 12px;
}
}
&:hover {
.sub-menu {
display: block;
}
}
}
}
}
Example
https://jsfiddle.net/xs9wzr5h/2/
I've tried to push dropdown menu away with border-top: solid 24px transparent; but with this solution border-radius disappears from top corners. With this solution I tried to create fake padding so cursor will be always on parent/dropdown element which prevents dropdown from closing as cursor is moved from one element to another.
I also tried to use outline but this doesn't push element away from parent and can't be hovered.
I hope that my explanation was understandable. Cheers!
I managed to fix this with adding an after element to sub-menu
&:after {
position: absolute;
content: "";
width: 100%;
height: 26px;
top: -26px;
left: 0;
}
This will add a "fake padding" rectangle to top of div which on hover will keep sub-menu open.

Make div take the remaining height after another div take its height below it

I am trying to create a sidebar where year is displayed in the bottom and list of links on the top.
The year text should stay in the bottom and its height should be auto not absolute values (like 30px, 1em, 10% etc.)
The top links should remain inside the remaining height (screen height - height of year text).
When the links height exceeds, scrolling should be provided.
I have successfully achieved the first 2, but not the 3rd. When the links height exceeds, the year hides from the screen.
I have used table to achieve what I specified. (I could have used display: table; just being lazy here)
I want to achieve this using only CSS, no JavaScript.
/* Some styles */
.side-bar table {
color: #fff;
}
.side-bar-links {
background-color: #48c;
padding-top: 15px;
}
.side-bar-links li:nth-child(even) {
background-color: rgba(0,0,0,0.1);
}
.side-bar-links a {
display: block;
color: #fff;
padding: 5px 15px;
text-decoration: none;
}
.side-bar-links a:hover {
background-color: rgba(0,0,0,0.2);
}
.year {
background-color: #338;
font-size: 36px;
font-weight: 700;
padding: 5px 15px;
}
/* Positioning */
.side-bar {
position: fixed;
left: 0;
top: 0;
bottom: 0;
}
.side-bar table {
height: 100%;
table-layout: fixed;
}
.side-bar table tr:last-child td {
height: 1px;
}
.side-bar table td {
vertical-align: baseline;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="side-bar">
<table>
<tr>
<td class="side-bar-links">
<ul class="list-unstyled">
<li>> Link 1</li>
<li>> Link 2</li>
<li>> Link 3</li>
<li>> Link 4</li>
<li>> Link 5</li>
</ul>
</td>
</tr>
<tr>
<td class="year">
<b>2016</b>
</td>
</tr>
</table>
</div>
Try the following CSS and see if it works:
.side-bar {
position: fixed;
left: 0;
top: 0;
bottom: 0;
overflow: scroll;
overflow-y: auto;
overflow-x: auto;
}
You have to have something that determines the maximum height your container is going to be. Then you can handle overflow. I've modified your code a bit to change to a div layout and set up the overflow on the container. I believe this is what you're after.
The example in the snippet has a fixed height, so you may need to open it in full screen to see the whole example ('Run code snippet' - then 'full page').
You could also use percentages for heights to avoid using a fixed height.
/* Some styles */
.side-bar-links {
height: 300px;
max-height: 400px;
overflow:hidden;
background-color: #48c;
padding-top: 15px;
overflow-y: auto;
}
.side-bar-links li:nth-child(even) {
background-color: rgba(0,0,0,0.1);
}
.side-bar-links a {
display: block;
color: #fff;
padding: 5px 15px;
text-decoration: none;
}
.side-bar-links a:hover {
background-color: rgba(0,0,0,0.2);
}
.year {
background-color: #338;
font-size: 36px;
font-weight: 700;
padding: 5px 15px;
color: #fff;
}
/* Positioning */
.side-bar {
position: fixed;
left: 0;
top: 0;
bottom: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="side-bar">
<div class="side-bar-links">
<ul class="list-unstyled">
<li>> Link 1</li>
<li>> Link 2</li>
<li>> Link 3</li>
<li>> Link 4</li>
<li>> Link 5</li>
<li>> Link 1</li>
<li>> Link 2</li>
<li>> Link 3</li>
<li>> Link 4</li>
<li>> Link 5</li>
<li>> Link 1</li>
<li>> Link 2</li>
<li>> Link 3</li>
<li>> Link 4</li>
<li>> Link 5</li>
<li>> Link 1</li>
<li>> Link 2</li>
<li>> Link 3</li>
<li>> Link 4</li>
<li>> Link 5</li>
</ul>
</div>
<div class="year">
<b>2016</b>
</div>
</div>
Try the following:
<html><head>
<title>Page Title</title>
<style>
/* Some styles */
.side-bar table {
color: #fff;
}
.side-bar-links {
background-color: #48c;
padding-top: 15px;
}
.side-bar-links li:nth-child(even) {
background-color: rgba(0,0,0,0.1);
}
.side-bar-links a {
display: block;
color: #fff;
padding: 5px 15px;
text-decoration: none;
}
.side-bar-links a:hover {
background-color: rgba(0,0,0,0.2);
}
.year {
background-color: #338;
font-size: 36px;
font-weight: 700;
padding: 5px 15px;
position: fixed;
bottom: 0px;
height: auto !Important;
width: auto;
}
/* Positioning */
.side-bar {
position: fixed;
left: 0;
top: 0;
bottom: 0;
overflow: scroll;
overflow-y: auto;
overflow-x: auto;
height: calc(100% - 60px);
}
.side-bar tr:first-child{height:100%;}
.side-bar table {
height: 100%;
table-layout: fixed;
width:110px;
}
.side-bar table tr:last-child td {
height: 1px;
}
.side-bar table td {
vertical-align: baseline;
}
</style>
</head>
<body>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<div class="side-bar">
<table>
<tbody><tr>
<td class="side-bar-links">
<ul class="list-unstyled">
<li>> Link 1</li>
<li>> Link 2</li>
<li>> Link 3</li>
<li>> Link 4</li>
<li>> Link 5</li>
<li>> Link 5</li>
<li>> Link 5</li>
</ul>
</td>
</tr>
<tr>
<td class="year">
<b>2016</b>
</td>
</tr>
</tbody></table>
</div>
</body></html>

Scroll bar stays on top when scrolling in an iframe

I'm quite new to web development. I have a page that displays another page in an iFrame. On certain pages when you scroll down using keyboard or mouse wheel the scroll bar sticks to the top even though the page is scrolling down. On other pages it works normally with the scroll bar moving down. What is causing the iFrame to do this?
I recreated the same problem when using the iFrame to link to the apple site which is used in the examples below.
Examples
Scrollbar not working:
<html>
<head>
<style>
*{
margin: 0;
padding: 0;
}
iframe {
display: block;
width: 100%;
height: 100%;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.tcontent{
display: block;
width: 100%;
height: 100%;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
#header, #footer{
position:fixed;
height: 56px;
display:block;
width: 100%;
background: #333;
z-index:9;
text-align:center;
color: #f2f2f2;
/*padding: 20px 0 0 0;*/
}
</style>
</head>
<body>
<div class="tcontent">
<iframe src="http://apple.com/mac/" width="100%" height="100%" frameborder="0" style="border:0" scrolling="yes"></iframe>
</div>
<div id="footer">
<ul id="menu">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
<li class="active">Link 5</li>
<li>Link 6</li>
<li>Link 7</li>
<li>Link 8</li>
<li>Link 9</li>
</ul>
</div>
</body>
</html>
http://jsfiddle.net/rzk4u80p/
Scrollbar working:
http://jsfiddle.net/b1qqotjq/

Prevent Div from moving

I am working with a website with css drop down menus within the header div. When the drop down menu appears it resizes the header div therefore shoving down the content div.
In the body of my index.php:
<div class="top"></div>
<div class="container">
<?php include_once("header.php"); ?>
<div class="content"></div>
</div>
The header.php
<div class="header">
<div style="display: table-cell; width: 250px; text-align: center;">
LOGO
</div>
<div style="display: table-cell;">
<br><br><br>
<ul>
<li>Link 1
<ul>
<li>Monkey 1</li>
<li>Monkey 2</li>
<li>Monkey 3</li>
<li>Monkey 4</li>
<li>Monkey 5</li>
<li>Monkey 6</li>
<li>Monkey 7</li>
</ul>
</li>
<li>Link 2
<ul>
<li>Monkey 1</li>
<li>Monkey 2</li>
</ul>
</li>
<li>
Link 3
<ul>
<li>Monkey 1</li>
<li>Monkey 2</li>
<li>Monkey 3</li>
</ul>
</li>
<li>Link 4</li>
<li>Link 5</li>
<li>Link 6</li>
</ul>
</div>
</div>
And main.css
ul{
padding: 0;
list-style: none;
}
ul li{
float: left;
width: 100px;
text-align: center;
}
ul li a{
display: block;
padding: 5px 10px;
color: #333;
background: #f2f2f2;
text-decoration: none;
}
ul li a:hover{
color: #fff;
background: #939393;
}
ul li ul{
display: none;
}
ul li:hover ul{
display: block; /* display the dropdown */
}
.top{
background: #1b2d3c;
width: 100%;
height: 40px;
}
.container{
width: 1100px;
height: 1000px;
}
.header{
display: table-row;
width: 1100px;
height: 130px;
}
.content{
position: absolute;
background: #fff;
width: 1100px;
height: 500px;
}
* {
background: #87a0b4;
margin: 0px;
padding: 0px;
margin-left: auto ;
margin-right: auto ;
}
I apologize for the lengthy post. How can I prevent the problem I am having? I want to be sure I am doing things correctly before I get too deep into the project.
You need to change position of ul li:hover ul to absolute, and add some other properties like this JSFiddel (Source)
ul li:hover ul {
display: block;
position: absolute;
width: 100px;
z-index: 100;
}
Hope this will help you ..
As was said in the previous answer, you need to set position: absolute. I'd like to add a bit of information as to why.
According to MDN:
Elements that are positioned relatively are still considered to be in the normal flow of elements in the document. In contrast, an element that is positioned absolutely is taken out of the flow and thus takes up no space when placing other elements. The absolutely positioned element is positioned relative to nearest positioned ancestor. If a positioned ancestor doesn't exist, the initial container is used.
Basically, by giving an element absolute positioning, it is no longer being taken into account when positioning the rest of the page. It will take up its alloted space in its set position no matter what.
In your case, the div was moving relative to the elements surrounding it. By using position: absolute, you are ommiting and relativity.

How to fill up the height within an object

I want a page that has two fixed-width columns on the left and a main column that fills up the rest of the width of <body>. Within each column, I want to place some <div> object on the top and a <ul> object that fills up the rest of the height. I tried the following, but could not make the height of the <ul> objects automatically adjust to fill in the height. Rather, it overflows to the bottom as much as the height of the <div> above them.
<html>
<style>
body{
margin:0;padding:0;
overflow: hidden;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color:red;
}
.column{
float: left;
background-color:blue;
}
.column>ul{
height: 100%;
width: 100;
overflow-y: scroll;
overflow-x: hidden;
background-color:green;
}
#main-column>ul{
height: 100%;
overflow-y: scroll;
overflow-x: hidden;
background-color:brown;
}
</style>
<body>
<div class="column">
<div>Column 1 Title</div>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</div>
<div class="column">
<div>Column 2 Title</div>
<ul>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</div>
<div id="main-column">
<div>Main Column Title</div>
<ul>
<li>Item 5</li>
<li>Item 6</li>
</ul>
</div>
</body></html>
How can I make it so that height of the <ul> objects are automatically adjusted to fill up the remaining height?
​
This is what I get so far. The scroll bar is cut off and extends below the window border, which indicates that its height is overflowing.
If you give the column titles a fixed height, you can use that along with position: absolute on the uls to get the layout you want. Demo: http://jsbin.com/ecilob/1/edit
HTML:
<body>
<div class="column fw">
<div class="title">Column 1 Title</div>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</div>
<div class="column fw">
<div class="title">Column 2 Title</div>
<ul>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</div>
<div class="column main">
<div class="title">Main Column Title</div>
<ul>
<li>Item 5</li>
<li>Item 6</li>
</ul>
</div>
</body>
CSS:
body {
margin: 0;
padding: 0;
}
.column .title {
height: 30px;
border-bottom: 1px dashed #333;
}
.column {
background: lightblue;
float: left;
position: absolute;
top: 0;
bottom: 0;
}
.column + .column {
background: coral;
left: 120px;
}
.column + .column + .column { background: goldenrod; }
.column.fw {
width: 120px;
}
.column.main {
left: 240px;
right: 0;
}
.column ul {
position: absolute;
margin: 0;
top: 30px;
bottom: 0;
left: 0;
right: 0;
overflow-y: scroll;
}