How to do drop-down box like "More action" in gmail - css

I see the "More Action" drop-down box in gmail inbox page.
It has levels and some disabled item in the list.
How to do that in HTML+CSS?
Thank you

In response to Rob, the reason not to use disabled is IE.
The reason why this is not a good idea is that IE still does not support this in IE6, IE7 or IE8.
http://webbugtrack.blogspot.com/2007/11/bug-293-cant-disable-options-in-ie.html

I'v been searching for something similar and this is my solution. You'll need icons to show/hide, add css and javascript (jquery in this example). It show/hide a menu but could be anything inside .hide div.
css:
.shortasc { background: url("/css/asc.gif") no-repeat 50% 50%;cursor:pointer;}
.shortdesc { background: url("/css/desc.gif") no-repeat 50% 50%;cursor:pointer;}
.hide{ display:none;}
.toggle-menu .title {
text-align:left;
}
.toggle-menu div.more{
position: absolute;
border:#999999 1px solid;
background-color:#FFFFFF;
}
.toggle-menu div.more ul{margin:0; padding:2px; text-align:left;}
.toggle-menu div.more ul li{list-style:none; padding:2px; border:#CCCCCC 1px solid;}
html wich call to a jquery function:
<span class="toggle-menu">
<span class="title" onclick="$(this).win('togglewin');">titulo del menu</span><span class="orden shortasc"> </span>
<div class="more hide">
<ul>
<li>Enlace 1</li>
<li>Enlace 2</li>
<li>and so on</li>
</ul>
</div>
</span>
add method to jquery function or edit to add onClick event in title or create your function, or whatever, this is an example with an jquery function http://docs.jquery.com/Plugins/Authoring#Getting_Started:
(function($) {
var methods={
//... your functions
togglewin:function(){
var p = $(this).position();
var parent = (this).closest('.toggle-menu');
if(parent.find('.more').is(':visible')){
parent.find('.orden').removeClass('shortdesc').addClass('shortasc');
parent.find('.more').slideUp();
}else{
parent.find('.orden').removeClass('shortasc').addClass('shortdesc');
parent.find('.more').slideDown().offset( { top:p.top+12,left:p.left } );
}
return this;
}
};
$.fn.win = function(method) {
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' inexistente en jQuery.win' );
}
}
})(jQuery);
Sorry, I can't upload images, but I like the result.

You can group and disable elements in an HTML <select> element without resorting to the use of JavaScript. Something like the following should work:
<select name="foo">
<optgroup label="Odds">
<option value="1">1</option>
<option value="3">3</option>
<option value="5">5</option>
</optgroup>
<optgroup label="Evens">
<option value="2">2</option>
<option value="4">4</option>
<option value="6" disabled="disabled">6</option>
</optgroup>
</select>
A brief inspection in Firebug shows that Google are faking their drop-down box with a whole bunch of HTML and some clever CSS. Personally, I think taking the "correct" approach and styling it to look prettier is a lot more readable than reinventing the wheel here.

You want an unordered list based popup/drop-down menu.

Related

Website background turns dim when focus on form input

I have a website that has a big search form and a big website background. I had an idea for my website. That is to make the website background dim when i click on the search form. But then, I saw same thing at bing.com. I tried to do it using css but failed no matter what i try. Any idea to make it happen?
Update
I have this now in my css file.
#dim {width:100%; opacity:0; background:#000; position:absolute; height:100%;}
I want a JS code to make it the opacity turns to 0.5 when i click on my form.
Below is the code of my form.
<form name="searchform" onsubmit="return !!(validateSearch() && dosearch());">
<input type="text" name="searchterms" class="terms" id="terms" placeholder="What are you searching for?">
<select name="sengines" class="state" id="state">
<option value="" selected>Select a State</option>
<option value="http://kl.onehomereno.com?s=">Klang Valley</option>
</select>
<div class="pad10"></div>
<input name="Search" type="submit" value="Search" class="button3">
</form>
I have the terms as id. Therefore, i need a js code to work with #terms and #dim. Any suggestion?
You could use JavaScript to listen for clicks on the form element and change opacity of the class with the background
For example
EDIT:
CSS
.dim {
background: url("home_page.PNG") no-repeat;
background-size: cover;
width: 100%;
height: 500px;
opacity: 0;
}
HTML
<div class="dim"></div>
<input type="text" id="term">
JavaScript
$(document).ready(function() {
$('#term').click(function(e) {
e.stopPropagation();
$('.dim').css('opacity', '0.5');
});
$(document).on("click", function() {
$(this).find('.dim').css('opacity', '0');
});
});
Hope you get how this works.

How to change color of Select box after option is selected

I have tried a lot but can not do this. I want to show the red background colour to the selectbox after option is selected.
<select>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<style type="text/css">
select:hover {
background:#Ff0000;
color : #ffffff;
}
</style>
Try this:
var select = document.getElementById('mySelect');
select.onchange = function () {
select.className = 'redText';
}
.redText {
background-color:#F00;
}
<select id="mySelect">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
You need to use javascript/jquery to handle change selection event for selectbox and add red background
HTML
<select>
<option>Select</option>
<option selected>im selected</option>
<option>im not</option>
<option>me too</option>
<option>me either</option>
</select>
CSS
select { color: black; background: red; }
option:not(:checked) { background: white; }
http://jsfiddle.net/kQ6c5/
EDIT
http://www.w3.org/TR/selectors/#checked:
the :checked pseudo-class initially applies to such elements that have the HTML4 selected and checked attributes
Absolutely yes, you can do this using :checked selector,
Check this demo jsFiddle
Syntax
option:checked { }
HTML
<select>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
CSS
option:checked {
background:#Ff0000;
color : #ffffff;
}

Dropdown Select Box not showing correctly with custom CSS?

How can I add custom CSS select box styling for Chrome and Safari? IS there a fix?
Answer:
You need to add -webkit-appearance: none; and a height value for Chrome and Safari.
Any Suggestions?
Resource:
http://bavotasan.com/2011/style-select-box-using-only-css/
Try it on JSFiddle Remove and add that style in Google Chrome:
Before:
- http://jsfiddle.net/JoshSalway/jw6Qy/
After:
- http://jsfiddle.net/JoshSalway/cMbTB/
select{
-webkit-appearance: none;
}
<select> tags are stubborn creatures but there is a way.
If there's a "size" parameter in the tag, almost any CSS will apply. Using this technique, I've created a fiddle that's practically equivalent to a normal select tag, plus the value can be edited manually like a ComboBox in visual languages (unless you put readonly in the input tag).
So here's a minimal example to see the principle behind:
(you'll need jQuery for the clicking mechanism):
<style>
/* only these 2 lines are truly required */
.stylish span {position:relative;}
.stylish select {position:absolute;left:0px;display:none}
/* now you can style the hell out of them */
.stylish input { ... }
.stylish select { ... }
.stylish option { ... }
.stylish optgroup { ... }
</style>
...
<div class="stylish">
<label> Choose your superhero: </label>
<span>
<input onclick="$(this).closest('div').find('select').slideToggle(110)">
<br>
<select size=15 onclick="$(this).hide().closest('div').find('input').val($(this).find('option:selected').text());">
<optgroup label="Fantasy"></optgroup>
<option value="gandalf">Gandalf</option>
<option value="harry">Harry Potter</option>
<option value="jon">Jon Snow</option>
<optgroup label="Comics"></optgroup>
<option value="tony">Tony Stark</option>
<option value="steve">Steven Rogers</option>
<option value="natasha">Natasha Romanova</option>
</select>
</span>
</div>
Here's the fiddle with some more styles:
https://jsfiddle.net/dkellner/7ac9us70/
Hope this helps!

How to style Disabled Options in a form

I'm using a form with a drop-down menu that contains some options disabled, so the users cannot select them. I'm trying to customize via css these elements but I have some problems with Chrome and IE7/8/9/10.
HTML:
<div class="formBody">
<select name="form[categoria][]" id="categoria" class="rsform-select-box">
<option selected="selected" value="">Scegli una categoria</option>
<option disabled="disabled" value="">Impresa </option>
</select>
<span class="formValidation">
<span id="component50" class="formNoError">Scegli una categoria</span>
</span>
</div>
CSS:
select option[disabled] { color: #000; font-weight: bold }
This code works only with Firefox and doesn't work with Chrome and IE (all version).
Any idea to solve this problem?
Below the html code for select-box
<div class="formBody"><select name="form[categoria][]" id="categoria" class="rsform-select-box" ><option selected="selected" value="">Scegli una categoria</option><option disabled="disabled" value="">Impresa </option><option value="Servizi">Servizi</option><option value="Informatica">Informatica</option><option value="Commercio">Commercio</option><option value="Telecomunicazioni">Telecomunicazioni</option><option value="Editoria/Stampa">Editoria/Stampa</option><option value="Meccanica/Elettrica">Meccanica/Elettrica</option><option value="Alimentare">Alimentare</option><option value="Chimica/Farmaceutica">Chimica/Farmaceutica</option><option disabled="disabled" value="">Edilizia </option><option value="Tessile/Moda">Tessile/Moda</option><option value="Mobili/Arredamenti">Mobili/Arredamenti</option><option value="Alberghi/Ristoranti">Alberghi/Ristoranti</option><option value="Trasporto/Logistica">Trasporto/Logistica</option><option value="Finanza">Finanza</option><option value="Altro">Altro</option><option disabled="disabled" value="">Professionista </option><option value="Commercialista">Commercialista</option><option value="Ragioniere">Ragioniere</option><option value="Notaio">Notaio</option><option value="Tributarista">Tributarista</option><option value="Avvocato">Avvocato</option><option value="Consulente del lavoro">Consulente del lavoro</option><option value="Altro">Altro</option><option disabled="disabled" value="">P.A. Locale </option><option value="Regione">Regione</option><option value="Provincia">Provincia</option><option value="Comune">Comune</option><option value="Comunità Montana">Comunità Montana</option><option value="ASL">ASL</option><option value="CCIA">CCIA</option><option value="Altro">Altro</option><option disabled="disabled" value="">P.A. Centrale </option><option value="Associazione di categoria">Associazione di categoria</option><option value="Privato">Privato</option><option value="Altro">Altro</option></select><span class="formValidation"><span id="component50" class="formNoError">Scegli una categoria</span></span></div>
What you're looking for is this:
select option:disabled {
color: #000;
font-weight: bold;
}
Here, have a fiddle.
Attention: according to reports on the comments section, this solution does not work on OS X.
I used :invalid to solve my issue, description below:
So these answers do style the disabled option but only within the dropdown. Not if you wanted to display the disabled option at the top of the list as a "Please select".
Hope this helps others having a similar issue to what I had.
Basically, the select needs to be a required field for this to work:
<select required>
Assuming the option is at the top of the list:
<option disabled selected value="">Please select</option>
And your SCSS looking something like this:
select {
// The select element is set to required
// as long as the selected options value
// is empty the element is not valid.
&:invalid {
color: gray;
}
// Styling for browsers which do support
// styling select option elements directly
[disabled] {
color: gray;
}
option {
color: black;
}
}
So it's the :invalid which allows us to colour the disabled selected option.
Thanks to Markus Oberlehner for his post:
Blog post: https://markus.oberlehner.net/blog/faking-a-placeholder-in-a-html-select-form-field/
Codepen: https://codepen.io/maoberlehner/pen/WOWrqO
There is a way to do this with CSS only. But you need to tweak your HTML to follow some rules:
set your select to be required
disabled options need to have empty value fields: value=""
you need to style the :valid and :invalid states
Here is the markup:
<select required>
<option value="" selected disabled>Disabled default</option>
<option value="" disabled>Just disabled</option>
<option value="" >Empty but valid</option>
<option value="a-value-here">Fully valid</option>
</select>
select {
width: 500px;
padding: 10px;
}
select:invalid {
background: red;
}
select:valid {
background: green;
}
Here is the fiddle: https://jsfiddle.net/james2doyle/hw1m2cd9/
Now, when an option that is disabled and also value="", the :invalid styling will be applied. You can see that empty values are still ok.
If only select supported pattern, then we could validate with regex instead. At the time of this comment, it does not and is only supported on input "text" types.
This solution should work on IE >= 10
I do not think you can target an option tag using pure CSS; you can only modify a select tag.
Effort to modify a select tag.
Same effort to modify an option tag.
However, there are workarounds. See this question.
<select>
<option value="volvo" >Volvo</option>
<option value="saab">Saab</option>
<option value="vw" disabled>VW</option>
<option value="audi" class="colr">Audi</option>
<option value="aaa">Something</option>
<option value="ccc">Other</option>
<option value="vw" disabled>VW</option>
<option value="vvv">Apple</option>
<option value="nnn" class="colr">Mango</option>
<option value="cmmmcc">Plum</option>
</select>
option:disabled {
background: #ccc;
width: 500px;
padding: 5px;
}
option.colr {
background: red;
width: 500px;
padding: 5px;
}
Check the link
http://jsfiddle.net/W5B5p/110/
I used a simple hack to make disabled options grey, hopefully someone finds it useful.
<label>
<div id="disabledMask"></div>
<select id="mySelect">
<option disabled selected>Please Select</option>
<option value="foo">Bar</option>
</select>
</label>
<style>
label {
position: relative;
}
#disabledMask {
position: absolute;
background-color: #fff;
opacity: 0.5;
pointer-events: none;
width: 100%;
height: 100%;
display: none;
}
</style>
<script>
var toggleMask = function(){
var option = this.options[this.selectedIndex];
var disabledMask = document.getElementById('disabledMask');
disabledMask.style.display = option.disabled? 'block' : 'none';
};
var mySelect = document.getElementById('mySelect');
mySelect.addEventListener('change', toggleMask);
toggleMask.bind(mySelect)();
</script>
Here is a jsfiddle: https://jsfiddle.net/jhavbzcx/
Disclaimer: depending on the styling of your select you may need to style the #disabledMask so as not to overlap the dropdown arrow.
<select class="dropdown" name="contactMethod">
<option selected disabled>Contact method:</option>
<option class="dropdownplus"> E-mail: </option>
<option class="dropdownplus"> Website </option>
<option class="dropdownplus"> None</option>
</select>
<style>
.dropdown {
background-color: rgba(195, 0, 97, 0.1);
width: 100%;
border: 1px solid #CC0061;
border-style: inset;
color: grey;
text-decoration: none;
display: inline-block;
font-size: 16px;
padding: 10px;
margin-top: 10px;
margin-bottom: 10px;
}
option.dropdownplus {
color: black;
}
</style>
See img https://ibb.co/d9453b
var select = document.getElementsByTagName("select");
for(var i = 0;i < select.length; i++)
{
var el = select[i];
var optVal = el.options[el.selectedIndex].value
el.addEventListener('change', function () {
// Using an if statement to check the class
if (optVal == "") {
el.classList.remove('not_chosen');
} else {
el.classList.add('not_chosen');
}
});
}

IE bug with hover on select and options

I'm trying to make a hover on a div but when I hover a option the hover of div is affected.
Example code:
<div class="levelThreeMenuColumnTwo" id="clientFormMenu">
<div class="formMenuPFS">
<select name="select1">
<option value="TN">
Tennessee
</option>
<option value="VA" selected="selected">
Virginia
</option>
<option value="WA">
Washington
</option>
<option value="FL">
Florida
</option>
<option value="CA">
California
</option>
</select>
</div>
</div>
<style>
.formMenuPFS{
display:none;
background-color:red;
width:110px;
height:110px;
position:absolute;
left:200px;
}
.levelThreeMenuColumnTwo:hover .formMenuPFS{
display:block;
}
.levelThreeMenuColumnTwo{
display:block;
background-color:green;
width:200px;
height:200px;
}
</style>
Woking in FF but not in IE.
Correct behaviour:
When hover green div show red div.
When hover select or option keep showing red div.
If javascript is needed I can use dojo 1.4.
Thank you.
I know this is an old problem but I had the same problem I fixed it the following way in your jsbin. Instead of using the CSS :hover I used the jQuery hover and add an event.stopPropagation() too the select.
JS
$(document).ready(function(){
$(".levelThreeMenuColumnTwo").hover(function() {
$('.formMenuPFS').show();
$('.formMenuPFS select').mouseleave(function(event) { event.stopPropagation(); });
}, function() {
$('.formMenuPFS').hide();
$('.formMenuPFS select').mouseleave(function(event) { event.stopPropagation(); });
});
});
jsbin
http://jsbin.com/xitafazoca/

Resources