


Ask for advice: How to nest another drop down list inside a drop down list and get the value_html/css_WEB-ITnose
Jun 24, 2016 pm 12:19 PM I recently encountered a technical problem during web front-end development, but I couldn’t find a solution. I would like to ask: How to implement a "parent" drop on the web client side? Nest another "child" drop down list inside the down list and pass the value of the sub-drop-down menu to the upper-level drop-down menu and output
Reply to discussion (solution)
1. The outer drop down list is simulated through other elements such as div
2. Redesign it to make it more reasonable. This situation can be like the common selection of provinces. Select the city and other related options like that
Thank you friends upstairs. Since my experience is very limited, I wonder if I can provide some examples or give a link for reference.
Thank you!
The current situation is as follows:
(1) Running abnormally on firefox;
(2) The value taken from the child dropdownlist, I don’t know how to assign it to the previous dropdownlist (That is, the parent dropdownlist simulated by css and div)
The exercise source code is as follows:
demo.html
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Custom Drop-Down List Styling</title> <link rel="stylesheet" type="text/css" href="style.css" /> <link rel='stylesheet' type='text/css' /> <script type="text/javascript" src="modernizr.custom.79639.js"></script> <noscript><link rel="stylesheet" type="text/css" href="noJS.css" /></noscript> </head> <body> <div class="container"> <!-- Codrops top bar --> <div class="codrops-top"></div><!--/ Codrops top bar --> <header> <h1> </h1> <h2> </h2> <nav class="codrops-demos"></nav> </header> <section class="main"> <div class="wrapper-demo"> <div id="dd" class="wrapper-dropdown-1" tabindex="1"> <span>Select Contact</span> <ul class="dropdown" tabindex="1"> <li><a href="#"> <form> <select id="myselect"> <option value="1">Ed Bradley</option> <option value="2">Contact2</option> <option value="3">Contact3</option> </select> </form> </a> </li> <li><a href="#"> <form> <select id="myselect"> <option value="0">Select a Saved List</option> <option value="1">List1</option> <option value="2">List2</option> <option value="3">List3</option> </select> </form> </a> </li> <li><a href="#">Active Search - 200 Contacts</a></li> <li><a href="#">All Contacts - 70000 Contacts</a></li> </ul> </div> ?</div> </section> </div> <!-- jQuery if needed --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script type="text/javascript"> function DropDown(el) { this.dd = el; this.placeholder = this.dd.children('span'); this.opts = this.dd.find('ul.dropdown > li'); this.val = ''; this.index = -1; this.initEvents(); } DropDown.prototype = { initEvents : function() { var obj = this; obj.dd.on('click', function(event){ $(this).toggleClass('active'); return false; }); obj.opts.on('click',function(){ var opt = $(this); obj.val = opt.text(); obj.index = opt.index(); obj.placeholder.text('Select Contact: ' + obj.val); }); }, getValue : function() { return this.val; }, getIndex : function() { return this.index; } } $(function() { var dd = new DropDown( $('#dd') ); $(document).click(function() { // all dropdowns $('.wrapper-dropdown-1').removeClass('active'); }); }); </script> </body></html>
style.css
@import url('demo.css');@import url('font-awesome.css');/* GLOBALS */*,*:after,*:before { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; padding: 0; margin: 0;}::selection { background: transparent; }::-moz-selection { background: transparent; }.wrapper-demo { margin: 60px 0 0 0; *zoom: 1; font-weight: 400;}.wrapper-demo:after { clear: both; content: ""; display: table;}/* DEMO 1 */.wrapper-dropdown-1 { /* Size and position */ position: relative; /* Enable absolute positionning for children and pseudo elements */ width: 400px; padding: 10px; margin: 0 auto; /* Styles */ background: #9bc7de; color: #fff; outline: none; cursor: pointer; /* Font settings */ font-weight: bold;}.wrapper-dropdown-1:after { content: ""; width: 0; height: 0; position: absolute; right: 16px; top: 50%; margin-top: -6px; border-width: 6px 0 6px 6px; border-style: solid; border-color: transparent #fff; }.wrapper-dropdown-1 .dropdown { /* Size & position */ position: absolute; top: 100%; left: 0; right: 0; /* Styles */ background: #fff; list-style: none; font-weight: normal; /* Cancels previous font-weight: bold; */ /* Hiding */ opacity: 0; pointer-events: none;}.wrapper-dropdown-1 .dropdown li a { display: block; text-decoration: none; color: #9e9e9e; padding: 10px 20px;}/* Hover state */.wrapper-dropdown-1 .dropdown li:hover a { background: #f3f8f8;}/* Active state */.wrapper-dropdown-1.active .dropdown { opacity: 1; pointer-events: auto;}.wrapper-dropdown-1.active:after { border-color: #9bc7de transparent; border-width: 6px 6px 0 6px ; margin-top: -3px;}.wrapper-dropdown-1.active { background: #9bc7de; background: -moz-linear-gradient(left, #9bc7de 0%, #9bc7de 78%, #ffffff 78%, #ffffff 100%); background: -webkit-gradient(linear, left top, right top, color-stop(0%,#9bc7de), color-stop(78%,#9bc7de), color-stop(78%,#ffffff), color-stop(100%,#ffffff)); background: -webkit-linear-gradient(left, #9bc7de 0%,#9bc7de 78%,#ffffff 78%,#ffffff 100%); background: -o-linear-gradient(left, #9bc7de 0%,#9bc7de 78%,#ffffff 78%,#ffffff 100%); background: -ms-linear-gradient(left, #9bc7de 0%,#9bc7de 78%,#ffffff 78%,#ffffff 100%); background: linear-gradient(to right, #9bc7de 0%,#9bc7de 78%,#ffffff 78%,#ffffff 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9bc7de', endColorstr='#ffffff',GradientType=1 );}/* No CSS3 support */.no-opacity .wrapper-dropdown-1 .dropdown,.no-pointerevents .wrapper-dropdown-1 .dropdown { display: none; opacity: 1; /* If opacity support but no pointer-events support */ pointer-events: auto; /* If pointer-events support but no pointer-events support */}.no-opacity .wrapper-dropdown-1.active .dropdown,.no-pointerevents .wrapper-dropdown-1.active .dropdown { display: block;}
demo.css
/* General Demo Style */body { font-family: 'Lato', 'Arial', sans-serif; background: #ddd url(../images/bg.jpg); font-weight: 300; font-size: 15px; color: #333; -webkit-font-smoothing: antialiased; overflow-y: scroll; overflow-x: hidden;}a { color: #555; text-decoration: none;}.container { width: 100%; position: relative;}.clr { clear: both; padding: 0; height: 0; margin: 0;}.main { width: 90%; margin: 0 auto; position: relative;}.container > header { margin: 10px; padding: 20px 10px 10px 10px; position: relative; display: block; text-shadow: 1px 1px 1px rgba(0,0,0,0.2); text-align: center;}.container > header h1 { font-size: 30px; line-height: 38px; margin: 0; position: relative; font-weight: 300; color: #666; text-shadow: 1px 1px 1px rgba(255,255,255,0.7);}.container > header h2 { font-size: 14px; font-weight: 300; margin: 0; padding: 15px 0 5px 0; color: #888; font-family: Cambria, Georgia, serif; font-style: italic; text-shadow: 1px 1px 1px rgba(255,255,255,0.9);}/* Header Style */.codrops-top { line-height: 24px; font-size: 11px; background: #fff; background: rgba(255, 255, 255, 0.5); text-transform: uppercase; z-index: 9999; position: relative; font-family: Cambria, Georgia, serif; box-shadow: 1px 0px 2px rgba(0,0,0,0.2);}/* Clearfix hack by Nicolas Gallagher: http://nicolasgallagher.com/micro-clearfix-hack/ */.codrops-top:before,.codrops-top:after { content: " "; /* 1 */ display: table; /* 2 */}.codrops-top:after { clear: both}.codrops-top a { padding: 0px 10px; letter-spacing: 1px; color: #333; display: inline-block;}.codrops-top a:hover { background: rgba(255,255,255,0.6);}.codrops-top span.right { float: right;}.codrops-top span.right a { float: left; display: block;}/* Demo Buttons Style */.codrops-demos { text-align:center; display: block; line-height: 30px; padding: 5px 0px;}.codrops-demos a { display: inline-block; margin: 0px 4px; padding: 0px 6px; color: #aaa; line-height: 20px; font-size: 12px; font-weight: 700; text-shadow: 1px 1px 1px #fff; border: 1px solid #fff; background: #ffffff; /* Old browsers */ background: -moz-linear-gradient(top, #ffffff 0%, #f6f6f6 47%, #ededed 100%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(47%,#f6f6f6), color-stop(100%,#ededed)); /* Chrome,Safari4+ */ background: -webkit-linear-gradient(top, #ffffff 0%,#f6f6f6 47%,#ededed 100%); /* Chrome10+,Safari5.1+ */ background: -o-linear-gradient(top, #ffffff 0%,#f6f6f6 47%,#ededed 100%); /* Opera 11.10+ */ background: -ms-linear-gradient(top, #ffffff 0%,#f6f6f6 47%,#ededed 100%); /* IE10+ */ background: linear-gradient(top, #ffffff 0%,#f6f6f6 47%,#ededed 100%); /* W3C */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ededed',GradientType=0 ); /* IE6-9 */ box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);}.codrops-demos a:hover { color: #333; background: #fff;}.codrops-demos a:active { background: #fff;}.codrops-demos a.current-demo,.codrops-demos a.current-demo:hover { background: #f0f0f0; border-color: #d9d9d9; color: #aaa; box-shadow: 0 1px 0 rgba(255,255,255,0.3); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f6f6f6', endColorstr='#f6f6f6',GradientType=0 ); /* IE6-9 */}.support-note span { color: #ac375d; font-size: 16px; display: none; font-weight: bold; text-align: center; padding: 5px 0;}.no-cssanimations .support-note span.no-cssanimations,.no-csstransforms .support-note span.no-csstransforms,.no-csstransforms3d .support-note span.no-csstransforms3d,.no-csstransitions .support-note span.no-csstransitions { display: block;}
noJS.css
/* DEMO 1 */.wrapper-dropdown-1:focus .dropdown { opacity: 1; pointer-events: auto;}.wrapper-dropdown-1:focus:after { border-color: #9bc7de transparent; border-width: 6px 6px 0 6px ; margin-top: -3px;}

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The key to keep up with HTML standards and best practices is to do it intentionally rather than follow it blindly. First, follow the summary or update logs of official sources such as WHATWG and W3C, understand new tags (such as) and attributes, and use them as references to solve difficult problems; second, subscribe to trusted web development newsletters and blogs, spend 10-15 minutes a week to browse updates, focus on actual use cases rather than just collecting articles; second, use developer tools and linters such as HTMLHint to optimize the code structure through instant feedback; finally, interact with the developer community, share experiences and learn other people's practical skills, so as to continuously improve HTML skills.

The reason for using tags is to improve the semantic structure and accessibility of web pages, make it easier for screen readers and search engines to understand page content, and allow users to quickly jump to core content. Here are the key points: 1. Each page should contain only one element; 2. It should not include content that is repeated across pages (such as sidebars or footers); 3. It can be used in conjunction with ARIA properties to enhance accessibility. Usually located after and before, it is used to wrap unique page content, such as articles, forms or product details, and should be avoided in, or in; to improve accessibility, aria-labeledby or aria-label can be used to clearly identify parts.

To create a basic HTML document, you first need to understand its basic structure and write code in a standard format. 1. Use the declaration document type at the beginning; 2. Use the tag to wrap the entire content; 3. Include and two main parts in it, which are used to store metadata such as titles, style sheet links, etc., and include user-visible content such as titles, paragraphs, pictures and links; 4. Save the file in .html format and open the viewing effect in the browser; 5. Then you can gradually add more elements to enrich the page content. Follow these steps to quickly build a basic web page.

To create an HTML checkbox, use the type attribute to set the element of the checkbox. 1. The basic structure includes id, name and label tags to ensure that clicking text can switch options; 2. Multiple related check boxes should use the same name but different values, and wrap them with fieldset to improve accessibility; 3. Hide native controls when customizing styles and use CSS to design alternative elements while maintaining the complete functions; 4. Ensure availability, pair labels, support keyboard navigation, and avoid relying on only visual prompts. The above steps can help developers correctly implement checkbox components that have both functional and aesthetics.

To reduce the size of HTML files, you need to clean up redundant code, compress content, and optimize structure. 1. Delete unused tags, comments and extra blanks to reduce volume; 2. Move inline CSS and JavaScript to external files and merge multiple scripts or style blocks; 3. Simplify label syntax without affecting parsing, such as omitting optional closed tags or using short attributes; 4. After cleaning, enable server-side compression technologies such as Gzip or Brotli to further reduce the transmission volume. These steps can significantly improve page loading performance without sacrificing functionality.

It is a semantic tag used in HTML5 to define the bottom of the page or content block, usually including copyright information, contact information or navigation links; it can be placed at the bottom of the page or nested in, etc. tags as the end of the block; when using it, you should pay attention to avoid repeated abuse and irrelevant content.

HTMLhasevolvedsignificantlysinceitscreationtomeetthegrowingdemandsofwebdevelopersandusers.Initiallyasimplemarkuplanguageforsharingdocuments,ithasundergonemajorupdates,includingHTML2.0,whichintroducedforms;HTML3.x,whichaddedvisualenhancementsandlayout

To embed videos in HTML, use tags and specify the video source and attributes. 1. Use src attributes or elements to define the video path and format; 2. Add basic attributes such as controls, width, height; 3. To be compatible with different browsers, you can list MP4, WebM, Ogg and other formats; 4. Use controls, autoplay, muted, loop, preload and other attributes to control the playback behavior; 5. Use CSS to realize responsive layout to ensure that it is adapted to different screens. Correct combination of structure and attributes can ensure good display and functional support of the video.
