I am using Angular 8,
If we have 20 dropdowns <ul> entries, then dropdown toggle <ul> is going out of the screen.
I need to scroll the whole screen to see all the list of dropdown
Screenshot 1: DropDown that has 15 entries, but here I can see only 7 entries,
If I want to see all 15 entries then I need to scroll whole screen (Screenshot 2)
Screenshot 2: I need to scroll whole scree to see all data,
All I need to scroll only the dropdown till i find the last item or as soon as it goes out of screen, i need that dropdown to up , something like this Screenshot 3
Screenshot 3: I need something like this
#import "~src/assets/styles/bootstrap-theme";
#import "~src/assets/styles/icons";
:host {
form {
position: relative;
&.ng-invalid {
.dropdown-display {
border: $text-border-width solid $common-color-error-red;
background-color: $common-color-error-background;
z-index: 100; // to make sure the dropdown toggle border is drawn over the barcode button border
}
}
}
div.background {
position: fixed;
z-index: 1031;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
}
div.dropdown.disabled {
.form-control {
background-color: $input-disabled-bg;
}
.input-group-append button, .input-group-append .input-group-text {
background-color: $input-disabled-bg;
}
}
div.dropdown .dropdown-display {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
ul.dropdown-menu {
max-height: 50vh;
overflow-y: scroll;
z-index: 1040;
-webkit-overflow-scrolling: touch;
}
ul.dropdown-menu > li > a {
&:hover {
color:$common-color-white;
}
&.highlight-selection {
background-color: $highlight-input-background;
color: $highlight-input-text-color;
}
}
ul.dropdown-menu > li > input {
padding: 3px 15px; // px values since this is dependent on bootstrap, which also uses px for this
background-color: white;
}
ul.tags {
width: 100%;
display: flex;
flex-wrap: wrap;
list-style: none;
padding: 0;
margin-top: 0.5rem;
margin-bottom: 0;
border: $text-border-width solid darken($light-input-background, 5%);
li {
flex: 0 0 auto;
background-color: $light-input-background;
padding: 0.3125rem;
margin: 0.3125rem;
}
}
.input-group-append {
button {
padding-top: 0.0625rem;
padding-bottom: 0;
color: $primary;
background-color: $secondary;
border-color: $secondary;
}
.input-group-text {
background-color: $secondary;
border-color: $secondary;
}
}
}
HTML
<div class="background " *ngIf="showDropdownMenu" (click)="toggleDropdown()"></div>
<div class="dropdown">
<div class="input-group">
<div class="form-control flex-grow-1 dropdown-display"
(click)="toggleDropdownFromMenu($event)">
{{ model.selectedEntry}}
</div>
<div class="input-group-append" *ngIf="model.options.scannable">
<button class="btn btn-secondary"
type="button"
(click)="doScan($event)">
<fa-icon [icon]="faBarcode" size="2x"></fa-icon>
</button>
</div>
<div class="input-group-append"
(click)="toggleDropdownFromMenu($event)">
<fa-icon [icon]="faCaretDown" class="input-group-text"></fa-icon>
</div>
<span class="sr-only">Toggle Dropdown</span>
</div>
<ul class="dropdown-menu " role="menu" [ngClass]="{ show: showDropdownMenu }">
<li role="menuitem">
<input type="text"
formControlName="searchInput"
*ngIf="model.value.length > 3"
(click)="$event.stopPropagation()"
class="form-control"
[placeholder]="strings.searchPlaceholder"
>
</li>
<li role="menuitem"
*ngFor="let entry of searchMatchingEntries">
<a class="dropdown-item"
(click)="onSelected(entry)"
[ngClass]="{'highlight-selection':isSelected(entry)}">{{entry.displayName}}</a>
</li>
</ul>
</div>
Related
I have an HTML file where every time I click on the settings button, a popup with edit and delete buttons is supposed to appear like so:
(I clicked ash Ketchum)
[][1]
[1]: https://i.stack.imgur.com/tnXWm.png
However, as I move down the list, the popup is not relative to the button I click on, but rather is stuck in the same place like so:
[][2]
[2]: https://i.stack.imgur.com/Bgwzi.png
My question is, how could I style this popup to truly popup relative to the button chosen and not just stuck in a static position?
Here is the html and style file:
<div class="dropdown">
<nav>
<table class="tableLayout">
<ion-buttons slot="end" class="editButtonItem" (click)="onGetDragonIndex(dragon)">
<ion-button>
<label for="touch">
<span class="dropdown">
<ion-icon md="ellipsis-vertical" aria-label="ellipsis horizontal" role="img"
class="editButton"></ion-icon>
</span>
</label>
</ion-button>
</ion-buttons>
</table>
</nav>
<input type="checkbox" id="touch">
<div class="slide">
<div class="listItem">
<label for="touch">
<dragon-dragon></dragon-dragon>
</label>
</div>
</div>
</div>
.css
label {
padding: 0px;
}
span.dropdown {
padding-bottom: 15px;
padding-top: 20px;
cursor: pointer;
display: block;
z-index: 1;
}
span::after {
float: right;
right: 10%;
z-index: 1;
}
.slide {
height: 0px;
overflow: hidden;
text-align: center;
box-shadow: 2px 2px 2px 0px rgba(0.2, 0.2, 0.2, 0.2);
width: 110px;
background: white;
z-index: 2;
position: absolute;
margin-top: -10px;
}
.slide .listItem {
padding-top: 5px;
padding-bottom: 5px;
}
#touch {
position: absolute;
opacity: 0;
height: 0px;
}
#touch:checked+.slide {
height: 85px;
}
.tableLayout {
table-layout: fixed;
width: 100%;
}
I have a dropDown menu and when the drop list is open is overlapping the div below, I wish to push the div below down when the dropdown is open, I've try with flex, grid, flexgrow, grid rows, positions relative/absolute, and I can't find any solution.
here is the HTML code:
<div class="container">
<div class="dropContainer">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Dropdown</button>
<div id="myDropdown" class="dropdown-content">
Home
About
Contact
</div>
</div>
</div>
<div class="inputContainer">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" />
</div>
</div>
and the CSS:
.container{
display: flex;
flex-direction: column;
height: 100vh;
}
.dropContainer{
display: block;
height: 100%;
margin-bottom: 2rem;
}
.inputContainer{
display: block;
height: 100%;
top: 5rem;
}
/* dropDown Menu */
.dropbtn {
background-color: #3498DB;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
padding-bottom: 140px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.show {display: block; }
and here is the code example working: https://codepen.io/raulcosalux/pen/VwzGyYO
kind regards,
Using absolute positioning will not regard for content underneath. With that being said, you have to use position: relative; on your dropdown menu in order to allow the input or any other content below to adjust when the menu opens.
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
.container{
display: flex;
flex-direction: column;
height: 100vh;
}
.dropContainer{
display: block;
height: 100%;
margin-bottom: 2rem;
}
.inputContainer{
display: block;
height: 100%;
position: sticky;
}
/* dropDown Menu */
.dropbtn {
background-color: #3498DB;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: relative;
background-color: #f1f1f1;
min-width: 160px;
padding-bottom: 140px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.show {display: block; }
<div class="container">
<div class="dropContainer">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Dropdown</button>
<div id="myDropdown" class="dropdown-content">
Home
About
Contact
</div>
</div>
</div>
<div class="inputContainer">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" />
</div>
</div>
Change the position of the dropdown container that holds the menu to relative, then remove the padding you have on it. Remove this => padding-bottom: 140px; and change this => .dropdown-content { position: absolute; } to .dropdown-content { position: relative; }, this will push the content down below the menu element and the padding will no longer cover its content.
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
.container{
display: flex;
flex-direction: column;
height: 100vh;
}
.dropContainer{
display: block;
margin-bottom: 2rem;
}
.inputContainer{
display: block;
height: 100%;
top: 5rem;
}
/* dropDown Menu */
.dropbtn {
background-color: #3498DB;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.show {
display: block;
}
<div class="container">
<div class="dropContainer">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Dropdown</button>
<div id="myDropdown" class="dropdown-content">
Home
About
Contact
</div>
</div>
</div>
<div class="inputContainer">
<label for="fname">First name: </label>
<input type="text" id="fname" name="fname" />
</div>
</div>
I also removed the height on the dropContainer as well.
I have tried various possible options for height to cover the entire page/document, but none of them worked. When i make use of relative positions for elements, then the height covers entire page, but I am looking for way to fill/cover the height of entire page making use of "absolute" position for elements in my html, as i don't want to affect the behaviour other parts
html {
overflow-x: hidden;
height:100%;
min-height: 100% !important;
}
body{
font-family: Arial, Helvetica, sans-serif;
background-color: white;
margin:0;
padding:0;
height: 100%;
/* min-height: 100% !important; */
/* min-height: 100vh; */
}
#body-container{
height:100%;
}
/* ------------------------------------header start---------------------------------*/
#header-id {
position: absolute;
top:0px;
right:3px;
left:3px;
height: 60px;
background-color: #272822;
width: 100%;
}
/* ------------------------------------header end---------------------------------*/
/* ------------------------------------fa fa-navicon and a fa-home start------------------------------------*/
.fa-navicon,
.fa-home {
padding-top: 10px;
padding-bottom: 11px;
padding-left: 20px;
padding-right: 20px;
}
.fa-home {
background-color: #272822;
}
.fa-navicon {
background-color: darkslategrey;
}
.fa-navicon:hover,
.fa-home:hover {
background-color: darkslateblue;
}
/* ------------------------------------fa fa-navicon and a fa-home end------------------------------------*/
/* ------------------------------------top navigation menu start------------------------------------*/
#topnav-id {
overflow: scroll;
white-space: nowrap;
background-color: #7a7777;;
position: absolute;
top: 70px;
left:3px;
/* width: 100%; */
height: 41px;
/* Hide scrollbar for IE, Edge and Firefox */
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
/* Hide scrollbar for Chrome, Safari and Opera */
#topnav-id::-webkit-scrollbar {
display: none;
}
#topnav-id a {
display: inline-block;
color: #f2f2f2;
background-color: #272822;
text-align: center;
padding-top: 13px;
padding-bottom: 10px;
padding-left: 14px;
padding-right: 14px;
text-decoration: none;
font-size: 14px;
}
#topnav-id a:hover {
background-color: darkred;
}
#topnav-id .icon {
display: none;
}
/* ------------------------------------top navigation menu end------------------------------------*/
/* ------------------------------------side navigation menu type 2 start---------------------------------*/
#sidenav-container-id{
width: 260px;
top: 120.5px;
left: 3px;
height: 100%;
position: absolute;
}
.dropdown-btn {
padding: 6px 9px 6px 12px;
background-color:#272822;
margin-bottom: 3px;
text-decoration: none;
text-align: left;
font-size: 14px;
color: white;
display: block;
border: 0px;
width: 260px;
}
.dropdown-btn:focus {
outline: none;
box-shadow: none;
}
.sidenav-dropdown-content-class {
display: none;
top: 0px;
min-height: 100%;
width: 260px;
position: relative;
z-index: 1;
left: 0px;
padding-top: 0px;
padding-bottom: 0px;
}
.sidenav-dropdown-content-class a {
padding: 6px 8px 6px 12px;
background-color:darkslateblue;
margin-bottom: 3px;
text-decoration: none;
font-size: 14px;
color: white;
display: block;
}
.show {display: block;}
/* ------------------------------------side navigation menu type 2 end---------------------------------*/
/* ------------------------------------content start---------------------------------*/
#content-id {
/* min-height: 100%; */
margin-left: 260px; /* Same as the width of the sidenav */
position: absolute;
top: 120px;
left: 10px;
padding: 10px 10px;
margin-right: 180px;
background-color: #d1cdcd;
/* height: 100%; */
min-height: 100vh;
}
#pre-id {
height: 100%;
white-space: pre-wrap;
display: inline-block;
}
/* ------------------------------------content end---------------------------------*/
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="js/index-script.js"></script>
<link type="text/css" rel="stylesheet" href="css/index-style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div id="body-container">
<div id="header-id"></div>
<div id="topnav-id" class="topnav-class">
<i class="fa fa-navicon" onclick="openCloseHambugerMenu()" style="font-size:20px; color: white"></i>
<i class="fa fa-home" style="font-size:20px; color: white"></i>
Link1
Link2
Link3
Link4
Link5
</div>
<div id="sidenav-container-id">
<div id="sidenav-navigation-id" class="sidenav-navigation-class">
<button id="button1" class="dropdown-btn"
onclick="toggleSidenavDropdown('dropdown1')">Outer Link</button>
<div id="dropdown1" class="sidenav-dropdown-content-class">
Link
Link
Link
Link
Link
</div>
<button id="button2" class="dropdown-btn"
onclick="toggleSidenavDropdown('dropdown2')">Outer Link</button>
<div id="dropdown2" class="sidenav-dropdown-content-class">
Link
Link
Link
</div>
<button id="button3" class="dropdown-btn"
onclick="toggleSidenavDropdown('dropdown3')">Outer Link</button>
<div id="dropdown3" class="sidenav-dropdown-content-class">
Link
Link
Link
</div>
<button id="button4" class="dropdown-btn"
onclick="toggleSidenavDropdown('dropdown4')">Outer Link</button>
<div id="dropdown4" class="sidenav-dropdown-content-class">
Link
Link
Link
</div>
<button id="button5" class="dropdown-btn"
onclick="toggleSidenavDropdown('dropdown5')">Outer Link</button>
<div id="dropdown5" class="sidenav-dropdown-content-class">
<a href="#">Link
Link
</div>
<button id="button6" class="dropdown-btn"
onclick="toggleSidenavDropdown('dropdown6')">Outer Link</button>
<div id="dropdown6" class="sidenav-dropdown-content-class">
Link
Link
Link
Link
</div>
<button id="button7" class="dropdown-btn" onclick="toggleSidenavDropdown('dropdown7')">Outer Link</button>
<div id="dropdown7" class="sidenav-dropdown-content-class">
Link
Link
Link
</div>
<button id="button8" class="dropdown-btn"
onclick="toggleSidenavDropdown('dropdown8')">Outer Link</button>
<div id="dropdown8" class="sidenav-dropdown-content-class">
Link
Link
Link
</div>
</div>
</div>
<div id="content-id" class="content-class">
<h2>Content</h2>
<pre id="pre-id">
import java.io.*;
import java.util.*;
class ArrayListExample {
public static void main(String[] args) {
// Size of the
// ArrayList
int n = 5;
// Declaring the ArrayList with
// initial size n
ArrayList<Integer> arrli
= new ArrayList<Integer>(n);
// Appending new elements at
// the end of the list
for (int i = 1; i <= n; i++)
arrli.add(i);
// Printing elements
System.out.println(arrli);
// Remove element at index 3
arrli.remove(3);
// Displaying the ArrayList
// after deletion
System.out.println(arrli);
// Printing elements one by one
for (int i = 0; i < arrli.size(); i++)
System.out.print(arrli.get(i) + " ");
}
}
</pre>
</div>
</div>
</body>
</html>
You want to use viewport units, like vw (view width) and vh (view height). To make an absolutely positioned div fill the whole screen, you'd do:
.my-div {
width: 100vw;
height: 100vh;
position: absolute;
top: 0;
left: 0;
z-index: 100; // or wherever in the stack you want the layer
}
So this problem is making me go crazy guys. I created a dropdown menu using Boostrap 4, however when the screen is mobile size I used media query. I want to make my dropdown menu use 100% with when in mobile, and I already tried putting width 100% in some divs or position fixed, but none of that worked.
Here is my screen:
The part that is marked in blue is the one that I want to cover the whole screen.
Here is my HTML code:
<div class="notification-container dropdown">
<button
class="btn notification-button"
type="button"
id="dropdownMenuButton"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
<i class="fa fa-bell-o"></i>
</button>
<div
class="dropdown-menu dropdown-menu-right notification-container-header"
aria-labelledby="dropdownMenuButton"
>
{{ notifications.length }} notificações
<div class="notification-container-list-body">
<ul class="list-group list-group-flush">
<ng-template
ngFor
let-notification
[ngForOf]="notifications"
let-i="index"
>
<ng-template [ngIf]="notification.imagem">
<li class="notification-container-list-body-item">
<a
class="list-group-item notification-container-list-body-item-image"
routerLink="{{ notification.link }}"
>
<img src="{{ notification.imagem }}" alt="" />
<div>
<div>
{{ notification.titulo }}
</div>
<div>
{{ notification.descricao }}
</div>
</div>
</a>
<button
class="btn delete-notification"
(click)="dropdownPersist($event)"
(click)="deleteNotification(notification.id)"
>
<i class="fa fa-close"></i>
</button>
</li>
</ng-template>
<ng-template [ngIf]="!notification.imagem">
<li class="notification-container-list-body-item">
<a
class="list-group-item notification-container-list-body-item-noimage"
href="{{ notification.link }}"
>
<div>
<div>
{{ notification.titulo }}
</div>
<div>
{{ notification.descricao }}
</div>
</div>
</a>
<button
class="btn delete-notification"
(click)="dropdownPersist($event)"
(click)="deleteNotification(notification.id)"
>
<i class="fa fa-close"></i>
</button>
</li>
</ng-template>
</ng-template>
</ul>
</div>
</div>
</div>
And here is my SCSS code:
p,
a {
margin: 0;
padding: 0;
border: 0;
text-decoration: none;
}
.notification-button {
border-color: transparent;
box-shadow: none;
i {
color: #fff;
}
&:focus {
i {
color: #0ff;
}
}
}
.notification-container-header {
text-align: center;
font-size: 0.9rem;
padding-top: 0px;
padding-bottom: 0px;
border-bottom: 0px;
border-radius: 0;
background-color: #0ff;
color: #000;
font-weight: 500;
}
.notification-container-list-body {
margin-left: 3px;
margin-right: 3px;
ul {
margin-bottom: 3.5px;
max-height: 250px;
overflow: auto;
}
}
.notification-container-list-body-item {
display: grid;
background: #000;
grid-template-columns: 1fr 0.1fr;
padding: 10px 10px 6px 11px;
border-bottom: 1px solid #fff;
}
.notification-container-list-body-item-image {
background: #000;
display: grid;
grid-template-columns: 0.2fr 1fr;
justify-content: center;
img {
height: 30px;
width: 60px;
padding-right: 9px;
}
div {
text-align: left;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 200px;
color: #fff;
&:nth-child(1) {
font-size: 10px;
}
&:nth-child(2) {
font-size: 14px;
}
}
}
.notification-container-list-body-item-noimage {
#extend .notification-container-list-body-item-image;
grid-template-columns: 1.9fr 0.1fr;
div {
width: 261px;
}
}
.delete-notification {
padding: 0;
border-color: transparent;
box-shadow: none;
i {
height: 12px;
width: 12px;
color: #646464;
}
&:focus {
i {
color: #646464;
}
}
}
#media (max-width: 576px) {
.notification-container-header {
margin-top: 0;
border: 0;
}
.notification-container-list-body-item {
grid-template-columns: 1.7fr 0.3fr;
padding: 10px 10px 6px 11px;
}
.notification-container-list-body-item-image {
img {
height: 30px;
width: 70px;
padding-right: 9px;
align-self: center;
}
div {
color: #fff;
&:nth-child(1) {
font-size: 12px;
}
&:nth-child(2) {
font-size: 16px;
}
}
}
.notification-container-list-body-item-noimage {
grid-template-columns: 2.3fr 0.3fr;
}
}
I am also using Angular 9, to make dynamic content.
Can some one help?
.notification-container-list-body {
width: 100%; <=====================================================
margin-left: 3px;
margin-right: 3px;
ul {
margin-bottom: 3.5px;
max-height: 250px;
overflow: auto;
}
}
As you can see on the image below, the dropdown div is a pixel wider than it should have been. The strangest thing is that on hover it only changes its color (line 22 of SCSS fiddle) and it's wider no more!
Apparently, its width is equal to its parent, but as you can see, it's not.
Maybe it's tied with button hover somehow?
Could somebody explain me the thing with this situation?
The code is like this.
https://jsfiddle.net/can528p2/12/
<div class="home">
<div class="submit">
<button class="btn-search">
Search Items
</button>
<div class="menu">
<ul role="menu">
<li>
<button>
Items1
</button>
</li>
<li>
<button>
Items2
</button>
</li>
</ul>
</div> <!-- /.menu -->
</div> <!-- /.submit -->
</div> <!-- /.home -->
SCSS
.home {
height: 200px;
padding: 20px;
background-color: rgba(0, 0, 0, 0.7);
button {
height: 40px;
line-height: 40px;
width: 100%;
}
.submit {
width: 20%;
position: relative;
.btn-search {
background: #ff530d;
color: #fff;
outline: none;
border: none;
&:hover,
&:focus,
&:active {
background-color: #f26202;
outline: none;
}
} //.btn-search
.menu {
position: absolute;
width: 100%;
border-radius: 0;
ul {
margin: 0;
padding: 0;
list-style-type: none;
background-color: transparent;
button {
background: #fff;
border: none;
outline: none;
&:hover,
&:focus,
&:active {
background: #ff530d;
border: none;
outline: none;
}
}
}
} //.menu
} //.submit
}
It's an optical illusion. It's tricking your brain because the dividing edges of the pixels on your monitor are dark and your brain contrasts them with a dark background. Try changing the whole background color to be a lighter shade and the effect diminishes:
.home {
height: 200px;
padding: 20px;
background-color: rgba(250, 250, 250, 0.7); <--
button {
height: 40px;
line-height: 40px;
width: 100%;
}
https://jsfiddle.net/can528p2/13/