Contents
- 1 Thủ Thuật về What is the correct HTML for making a drop-down list ?__? 2022
Thủ Thuật về What is the correct HTML for making a drop-down list ?__? 2022
Bạn đang tìm kiếm từ khóa What is the correct HTML for making a drop-down list ?__? được Update vào lúc : 2022-11-04 10:44:00 . Với phương châm chia sẻ Thủ Thuật về trong nội dung bài viết một cách Chi Tiết 2022. Nếu sau khi đọc Post vẫn ko hiểu thì hoàn toàn có thể lại phản hồi ở cuối bài để Ad lý giải và hướng dẫn lại nha.
<select>: The HTML Select element
Selecting multiple options
- Focusing on the <select> element (e.g. using Tab ).Selecting an item the top or bottom of the range they want to select using the Up and Down cursor keys to go up and down the options.Holding down the Shift key and then using the Up and Down cursor keys to increase or decrease the range of items selected.
- Focusing on the <select> element (e.g. using Tab ).Holding down the Ctrl key then using the Up and Down cursor keys to change the “focused” select option, i.e. the one that will be selected if you choose to do so. The “focused” select option is highlighted with a dotted outline, in the same way as a keyboard-focused link.Pressing Space to select/deselect “focused” select options.
Styling with CSS
- Styling HTML formsAdvanced styling for HTML forms
Basic select
<select name=”choice”>
<option value=”first”>First Value</option>
<option value=”second” selected>Second Value</option>
<option value=”third”>Third Value</option>
</select>
Advanced select with multiple features
<select name=”pets” multiple size=”4″>
<optgroup label=”4-legged pets”>
<option value=”dog”>Dog</option>
<option value=”cat”>Cat</option>
<option value=”hamster” disabled>Hamster</option>
</optgroup>
<optgroup label=”Flying pets”>
<option value=”parrot”>Parrot</option>
<option value=”macaw”>Macaw</option>
<option value=”albatross”>Albatross</option>
</optgroup>
</select>
</label>
- Multiple options are selectable because we’ve included the multiple attribute.The size attribute causes only 4 lines to display a time; you can scroll to view all the options.We’ve included <optgroup> elements to divide the options up into different groups. This is a purely visual grouping, its visualization generally consists of the group name being bolded, and the options being indented.The “Hamster” option includes a disabled attribute and therefore can’t be selected all.
Customizing select styles
- Clonesthe <select>’scontext (the <option>s) in a parent wrapper and reimplements the standard expected behavior using additional HTML elements and JavaScript. This includes basic tab behavior to provide keyboard accessibility.Maps some standards native attributes to data-attributes of the new elements in order to manage state and CSS.
<fieldset>
<legend>Standard controls</legend>
<select
name=1A
id=select
autocomplete=off
required
>
<option>Carrots</option>
<option>Peas</option>
<option>Beans</option>
<option>Pneumonoultramicroscopicsilicovolcanoconiosis</option>
</select>
</fieldset>
<fieldset id=custom>
<legend>Custom controls</legend>
<select
name=”2A”
id=”select”
autocomplete=”off”
required
>
<option>Carrots</option>
<option>Peas</option>
<option>Beans</option>
<option>Pneumonoultramicroscopicsilicovolcanoconiosis</option>
</select>
</fieldset>
</form>
font-family: Cambria, Cochin, Georgia, Times, ‘Times New Roman’, serif
.select:focus
border-color: blue;
html body toàn thân form fieldset#custom div.select[data-multiple] div.header
display: none;
html body toàn thân form fieldset#custom div.select div.header
content: ”;
display: -webkit-inline-box;
display: -ms-inline-flexbox;
display: inline-flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding: 0;
position: relative;
html body toàn thân form fieldset#custom div.select div.header::after
content: ”;
align-self: stretch;
display: flex;
align-content: center;
justify-content: center;
justify-items: center;
align-items: center;
padding: .5em;
html body toàn thân form fieldset#custom div.select div.header:hover:after
background-color: blue;
.select .header select
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
font-family: inherit;
font-size: inherit;
padding: 0;
border-width: 0;
width: 100%;
flex: 1;
display: none;
.select .header select optgroup
display: none;
.select select div.option
display: none;
html body toàn thân form fieldset#custom div.select
user-select: none;
box-sizing: border-box;
position: relative;
border-radius: 4px;
border-style: solid;
border-width: 0;
border-color: gray;
width: auto;
display: inline-block;
html body toàn thân form fieldset#custom div.select:focus
border-color: blue;
html body toàn thân form fieldset#custom div.select:hover
border-color: blue;
html body toàn thân form fieldset#custom div.select[data-open]
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
html body toàn thân form fieldset#custom div.select[data-open] datalist
display: initial;
html body toàn thân form fieldset#custom div.select datalist
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
position: absolute;
border-style: solid;
border-width: 1px;
border-color: gray;
left: 0;
display: none;
width: 100%;
box-sizing: border-box;
z-index: 2;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
html body toàn thân form fieldset#custom div.select datalist div.option
background-color: white;
margin-bottom: 1px;
cursor: pointer;
padding: 0.5em;
border-width: 0;
html body toàn thân form fieldset#custom div.select datalist div.option:hover
background-color: blue;
color: white;
html body toàn thân form fieldset#custom div.select datalist div.option:focus
background-color: blue;
color: white;
html body toàn thân form fieldset#custom div.select datalist div.option:checked
background-color: blue;
color: white;
html body toàn thân form fieldset#custom div.select div.optgroup div.option[data-disabled]
color: gray;
html body toàn thân form fieldset#custom div.select div.optgroup div.option[data-checked]
background-color: blue;
color: white;
html body toàn thân form fieldset#custom div.select div.optgroup div.label
font-weight: bold;
html body toàn thân form fieldset#custom div.select div.optgroup div.option div.label
font-weight: normal;
padding: .25em;
html body toàn thân form fieldset#custom div.select div.header
flex: 1;
display: flex;
width: auto;
box-sizing: border-box;
border-width: 1px;
border-style: inherit;
border-color: inherit;
border-radius: inherit;
html body toàn thân form fieldset#custom div.select div.header span
flex: 1;
padding: .5em;
for (const select of selects) {
const div = document.createElement(‘div’);
const header = document.createElement(‘div’);
const datalist = document.createElement(‘datalist’);
const optgroups = select.querySelectorAll(‘optgroup’);
const span = document.createElement(‘span’);
const options = select.options;
const parent = select.parentElement;
const multiple = select.hasAttribute(‘multiple’);
const onclick = function(e)
const disabled = this.hasAttribute(‘data-disabled’);
select.value = this.dataset.value;
span.innerText = this.dataset.label;
if (disabled) return;
if (multiple)
if (e.shiftKey)
const checked = this.hasAttribute(“data-checked”);
if (checked)
this.removeAttribute(“data-checked”);
else
this.setAttribute(“data-checked”, “”);
;
else
const options = div.querySelectorAll(‘.option’);
for (i = 0; i < options.length; i++)
const option = options[i];
option.removeAttribute(“data-checked”);
;
this.setAttribute(“data-checked”, “”);
;
;
;
const onkeyup = function(e)
e.preventDefault();
e.stopPropagation();
if (e.keyCode === 13)
this.click();
;
div.classList.add(‘select’);
header.classList.add(‘header’);
div.tabIndex = 1;
select.tabIndex = -1;
span.innerText = select.label;
header.appendChild(span);
for (attribute of select.attributes) div.dataset[attribute.name] = attribute.value;
for (i = 0; i < options.length; i++)
const option = document.createElement(‘div’);
const label = document.createElement(‘div’);
const o = options[i];
for (attribute of o.attributes) option.dataset[attribute.name] = attribute.value;
option.classList.add(‘option’);
label.classList.add(‘label’);
label.innerText = o.label;
option.dataset.value = o.value;
option.dataset.label = o.label;
option.onclick = onclick;
option.onkeyup = onkeyup;
option.tabIndex = i + 1;
option.appendChild(label);
datalist.appendChild(option);
div.appendChild(header);
for (o of optgroups)
const optgroup = document.createElement(‘div’);
const label = document.createElement(‘div’);
const options = o.querySelectorAll(‘option’);
Object.assign(optgroup, o);
optgroup.classList.add(‘optgroup’);
label.classList.add(‘label’);
label.innerText = o.label;
optgroup.appendChild(label);
div.appendChild(optgroup);
for (o of options)
const option = document.createElement(‘div’);
const label = document.createElement(‘div’);
for (attribute of o.attributes) option.dataset[attribute.name] = attribute.value;
option.classList.add(‘option’);
label.classList.add(‘label’);
label.innerText = o.label;
option.tabIndex = i + 1;
option.dataset.value = o.value;
option.dataset.label = o.label;
option.onclick = onclick;
option.onkeyup = onkeyup;
option.tabIndex = i + 1;
option.appendChild(label);
optgroup.appendChild(option);
;
;
div.onclick = function(e)
e.preventDefault();
parent.insertBefore(div, select);
header.appendChild(select);
div.appendChild(datalist);
datalist.style.top = header.offsetTop + header.offsetHeight + ‘px’;
div.onclick = function(e)
if (multiple)
else
const open = this.hasAttribute(“data-open”);
e.stopPropagation();
if (open)
this.removeAttribute(“data-open”);
else
this.setAttribute(“data-open”, “”);
;
div.onkeyup = function(sự kiện)
sự kiện.preventDefault();
if (sự kiện.keyCode === 13)
this.click();
;
document.addEventListener(‘click’, function(e)
if (div.hasAttribute(“data-open”)) div.removeAttribute(“data-open”);
);
const width = Math.max(…Array.from(options).map(function(e)
span.innerText = e.label;
return div.offsetWidth;
));
console.log(width)
div.style.width = width + ‘px’;
}
document.forms[0].onsubmit = function(e)
const data = new FormData(this);
e.preventDefault();
submit.innerText = JSON.stringify([…data.entries()]);
# the-select-elementBrowser compatibility
- Events fired by <select>: change, inputThe <option> elementThe <optgroup> element
Video What is the correct HTML for making a drop-down list ?__? ?
Bạn vừa tìm hiểu thêm nội dung bài viết Với Một số hướng dẫn một cách rõ ràng hơn về Review What is the correct HTML for making a drop-down list ?__? tiên tiến và phát triển nhất
Chia Sẻ Link Down What is the correct HTML for making a drop-down list ?__? miễn phí
Người Hùng đang tìm một số trong những Chia Sẻ Link Down What is the correct HTML for making a drop-down list ?__? Free.
Giải đáp vướng mắc về What is the correct HTML for making a drop-down list ?__?
Nếu sau khi đọc nội dung bài viết What is the correct HTML for making a drop-down list ?__? vẫn chưa hiểu thì hoàn toàn có thể lại phản hồi ở cuối bài để Admin lý giải và hướng dẫn lại nha
#correct #HTML #making #dropdown #list