A sliding image gallery has started performing terribly after updating Chrome to 88. See this site for example:
https://fionaandbobby.com/
You can view it in FF or Safari to see it performing how it used to perform in Chrome. After some research I distilled the behavior down a bit in a snippet below.
It appears to be totally dependent on the width of the element being transitioned. I'm sure there are other ways the slider on this site could be coded/styled, and possibly that's the solution. However, it's been working on many, many websites this way for years. Wondering if anyone has ideas about how to bypass this behavior. I've tried using the image-rendering CSS property on the img's themselves to no avail.
var button = document.getElementsByTagName('button')[0];
var ul = document.getElementsByTagName('ul')[0];
button.addEventListener('click', function() {
ul.classList.toggle('move');
});
var select = document.getElementsByTagName('select')[0];
select.addEventListener('change', function(e) {
ul.setAttribute('style', `width: ${e.target.value}px`);
});
div {
overflow: hidden;
}
ul {
margin: 0;
padding: 0;
list-style: none;
transition: transform 0.68s ease;
transform: translate3d(0, 0, 0);
}
ul.move {
transform: translate3d(100px, 0, 0);
}
li {
list-style: none;
margin: 0;
padding: 0;
}
img {
height: 300px;
width: 533px;
}
footer {
margin-top: 40px;
}
Select different widths of the containing ul element in the dropdown below and then click the translate button to see the effect.
<div>
<ul>
<li style="width: 500px">
<img src="https://images.unsplash.com/photo-1593642702821-c8da6771f0c6?ixid=MXwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=3289&q=80" />
</li>
</ul>
</div>
<footer>
<label>
Width of wrapping element being translated
<select>
<option value="1000">1000px</option>
<option value="100000">100000px</option>
<option value="10000000">10000000px</option>
</select>
</label>
<button>translate</button>
</footer>
This was a regression in Chrome 88, that is fixed in Chrome 89 (in beta at the time of writing this).
I have this html for an select control
<select class="form-control">
<option value="0"></option>
<option value="1: 1" >Jr.</option>
<option value="2: 2">Sr.</option>
<option value="3: 3">I</option>
<option value="4: 4">II</option>
<option value="5: 5">III</option>
</select>
It is getting rendered as expected in chrome
chrome image 1
chrome image 2
but in IE, the select option is hiding the control when it is clicked or in other words the the select option is not getting opened from the bottom of the select control as seen in this following screen shot
IE image 1
IE image 2
is this a default behaviour or can I change it? I tried giving using this css but did not work
select.form-control {
width: 100%;
max-width: 325px;
border-width: 0 0 1px 0;
box-shadow: none;
border-radius: 0;
-moz-appearance: none;
text-indent: .01px;
text-overflow: '';
position: relative;
}
option, select.form-control option {
color: blue !important;
top: 0px !important;
position: absolute !important;
}
any suggestion?
This is standard behavior. Every browser renders elements slightly different and has their own styles for it. Some styles can be changed, others are hidden in the shadow root of the elements and cannot be changed. option sadly has only a few styles like color that can be set...
One solution for this would be to hide the select element and control it via another element that can be styled (e.g. span) and JavaScript. That is not really pretty but many css frameworks already do so and if you absolutely have to make it look good (most of the times that is the case) that is your only option.
Here's a quick example of a custom built select box. As you can see, even putting images in the options is possible now. Hope this helps you.
Fontawesome is used for the caret. Documentation in the JS source code.
// Create a reference to the select box
const selectBox = document.getElementById("selected");
// Add an event listener to detect the click and make the options (in)visible
selectBox.addEventListener("click", function() {
// Add or remove class 'open'
document.getElementById("options").classList.toggle("open");
});
// Put all options in an array
const options = [...document.getElementsByClassName("option")];
// Add event listener for each option
options.map( option => option.addEventListener("click", function() {
// Create a reference to the input field
const myInput = document.getElementById("sel");
// Retrieve the text from the clicked option
const optionText = this.getElementsByTagName("span")[0].innerHTML;
// Put the text in the input field value
myInput.value = optionText;
// Put the text in the select box
selectBox.innerHTML = optionText;
// Close the select box
document.getElementById("options").classList.toggle("open")
}));
.container {
display: flex;
flex-wrap: wrap;
width: 25%;
}
#selected {
border: thin solid darkgray;
border-radius: 5px;
background: lightgray;
display: flex;
align-items: center;
cursor: pointer;
height: 1.5em;
margin-bottom: .2em;
padding-left: .5em;
min-width: 150px;
position: relative;
}
#selected:after {
font-family: FontAwesome;
content: "\f0d7";
margin-left: 1em;
position: absolute;
right: .5em;
}
#options {
display: none;
margin: 0;
padding: 0;
}
#options.open {
display: inline-block;
}
li {
display: flex;
justify-content: flex-start;
align-items: center;
cursor: pointer;
}
li>img {
margin-right: 1em;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<form>
<input type="hidden" id="sel">
<div class="container">
<div id="selected">Select an option</div>
<ul id="options">
<li class="option"><img src="http://placehold.it/50/00ff00"><span>Option 1</span></li>
<li class="option"><img src="http://placehold.it/50/ff0000"><span>Option 2</span></li>
<li class="option"><img src="http://placehold.it/50/0000ff"><span>Option 3</span></li>
</ul>
</div>
</form>
You can correct the behavior with CSS
select {
float: left;
display: inline-block;
}
<select class="form-control">
<option value="0"></option>
<option value="1: 1" >Jr.</option>
<option value="2: 2">Sr.</option>
<option value="3: 3">I</option>
<option value="4: 4">II</option>
<option value="5: 5">III</option>
</select>
How do you change the outline color of the dropdown options in a select?
This is what I currently have:
select:focus{
outline-color: #986fa5;
}
<select>
<option>1</option>
<option>2</option>
</select>
I have tried changing option:focus but yet when I click on the select and the dropdown options show up, the options menu has a web-ring colored outline. How do I change that outline color?
If you want a highly customized select, your best bet is making it by yourself. Here is an example:
$("document").ready(function() {
$(".option").click(function() {
$(".option").slideDown();
});
$(".option:not(.selected)").click(function() {
$(".option:not(.selected)").slideUp();
$(".option.selected").text($(this).text())
$("#selectVal").val($(this).data("value"))
});
});
li {
list-style: none
}
.option {
display: none
}
.option:first-child {
display: block
}
.option:not(.selected):hover {
background: red
}
#select {
border: 1px solid black;
width: 100px;
cursor: pointer
}
#select img{width:30px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="select">
<li class="option selected">--</li>
<li class="option" data-value="0"><img src="http://www.flags.net/images/largeflags/SPAN0002.GIF" alt=""/>Spain</li>
<li class="option" data-value="1"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/Flag_of_Portugal.svg/255px-Flag_of_Portugal.svg.png" alt=""/>Portugal</li>
</ul>
<input id="selectVal" type="hidden" value="" />
It's very easy to understand, and you can get the value as you would get it from a common select. The main difference is that with this approach you can ensure that you will have the same look in all browsers that support css3.
The select tag has a default implemented style which will vary between browsers but below is a css solution
#d option:last-child {
border-bottom: solid red 2px;
overflow: visible;
}
#d option:first-child {
border-top: solid red 2px;
}
#d option {
border-left: solid red 2px;
border-right: solid red 2px;
}
<div>
<select id="d">
<option>1</option>
<option>2</option>
</select>
</div>
I have a working demo on jsfiddle of 2 related divs where you click on a listitem on the left div, and this changes the listitems on the right div.
I cannot get this working in my asp application when I try to put it in a asp:panel:
It comes out really bad:
I then updated the JSFiddle to include an asp:panel, but now it is even worse.
Can I please ask how the HTML is supposed to be used in the asp:panel so that it renders properly as in the first jsfiddle link please.
There are quite a few changes I would recommend making:
asp:panel is not a standard HTML element, it will render in HTML as a div so in the fiddle it should be a div
lis need to be contained in a ul
Inline styles are valid but not optimal, it's best to move the styles into the stylesheet
borderTopColor:yellow; is not a valid CSS property, this should be border-top-color: yellow;
div:not(.container) is a very broad rule, it seems to be used to target .sort-me so it would be best to set it up this way
The main issue seems to be with the div:not(.container) rule, it was set to target any div without the class container so it was also applying the styles to the panel causing the undesired layout.
$(function () {
// $('.sort-me').sortable({connectWith: '.sort-me, #also-sort-me'});
});
$(".x").click(function () {
$('li').removeClass('selectedItem');
$(this).addClass('selectedItem');
var x = $(this);
//alert($( this ).attr("data-value"));
$("li").not(".x").each(function () {
$(this).find('input').val(x.attr("data-value"));
});
});
$("#pnl1").dialog({
modal: true,
zIndex: 9000,
beforeClose: function () {
}
});
$("#pnl1").show();
#pnl1 {
display: none;
}
.sort-me {
background-color: #00274c;
list-style-position: inside;
margin: 10px;
min-height: 30px;
padding: 10px;
vertical-align: top;
width: 390px;
}
li {
background-color: #ffcb05;
cursor: move;
margin: 5px;
padding: 5px;
}
.sort-me-input {
float: right;
}
.selectedItem {
background-color: yellow;
color: black;
font-weight: bold;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<form id="form1">
<div id="pnl1">
<div class='container'>
<ul class='sort-me'>
<li class="x" data-value="1">First</li>
<li class="x" data-value="2">Second</li>
<li class="x" data-value="3">Third</li>
</ul>
<ul class='sort-me'>
<li>Lorem
<input class="sort-me-input" />
</li>
<li>ipsum
<input class="sort-me-input" />
</li>
<li>dolor
<input class="sort-me-input" />
</li>
<li>dolor
<input class="sort-me-input" />
</li>
<li>dolor
<input class="sort-me-input" />
</li>
</ul>
</div>
</div>
</form>
JS Fiddle: http://jsfiddle.net/evrqeu7d/1/
I have a simple select drop down when I am going to select an option there is Menu navigation item, so now when I am going to hover on menu items navigation is going back to select option list which is open. It's happening in all browsers. I don't know whether it's a bug or what. Steps are:
Open select dropdown options
Same time hover on navigation menu items
Now the navigation items are going behind the option list (not behind the select tag)
I have tried giving z-index with positions. But nothing is working. I think its not an issue but need explanation on same. Any suggestions will be greatly appreciated.
This is the sample code:
<style type="text/css">
/* #################### Navigation bar CSS styling ################## */
.mynavbar {
position: relative;
width: 100%;
height: 23px; /* corresponds to 'line-height' of a.navbartitle below */
margin: 0; border: 0; padding: 0;
background-color: #666633;
}
a.navbartitle {
display: block;
float: left;
color: white;
background-color: #666633;
font-family: Verdana, Arial, Geneva, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
margin: 0; border: 0; padding: 0;
line-height: 23px; /* corresponds to 'top' value of .submenu below */
text-align: center;
text-decoration:none;
}
a.navbartitle:hover {
background-color: #447755;
}
/* menu title widths */
#t1 { width: 104px; }
#t2 { width: 100px; }
#t3 { width: 102px; }
#t4 { width: 102px; }
#t5 { width: 180px; }
/* We just specify a fixed width for each menu title. Then, down below we specify
a fixed left position for the corresponding submenus (e.g. #products_submenu, etc.)
Using these fixed values isn't as elegant as just letting the text of each
menu title determine the width of the menu titles and position of the submenus,
but we found this hardwired approach resulted in fewer cross-browser/cross-OS
formatting glitches -- and it's pretty easy to adjust these title widths and the
corresponding submenu 'left' positions below, just by eyeballing them whenever
we need to change the navbar menu titles (which isn't often). */
.submenu {
position:absolute;
z-index: 2;
top: 23px; /* corresponds to line-height of a.navbartitle above */
padding: 0; margin: 0;
width:166px; /* If adjust this, then adjust width of .submenu below a too */
color: white;
background-color: #666633;
border: 1px solid #447755; /* box around entire sub-menu */
font-family: Verdana, Arial, Geneva, Helvetica, sans-serif;
font-size: 11px;
}
/* Fix IE formatting quirks. */
* html .submenu { width: 148px; } /* IE needs narrower than width of .submenu above */
/* End */
/* position of each sub menu */
/* We just eyeball the position of each submenu here -- can move left or right as needed.
If you adjust menu title text, you might want to adjust these too. */
#products_submenu { left: 0px; visibility: hidden; }
#services_submenu { left: 104px; visibility: hidden; }
#funstuff_submenu { left: 204px; visibility: hidden; }
#aboutus_submenu { left: 306px; visibility: hidden; }
#contact_submenu { left: 408px; visibility: hidden; }
/* Note, each submenu is hidden when the page loads - then made visible when
the mouse goes over the menu title. Using the 'visibility' property instead
of using the 'display' property avoided a bug in some versions of Safari.
(The bug is pretty where esoteric: The browser ignored the 'hover' property
on 'li' objects inside an object whose display property was set to 'none'
when the page loaded...) Using the 'visibility' property instead of 'display'
would normaly take up extra room on the page, but that's avoided here by putting
the submenu on a second layer: see 'position: absolute' and 'z-index: 2'
in .submenu definition, higher up this page. */
.submenu a
{
display: block;
color: #eee;
background-color: #666633;
width: 146px; /* This should be width of .submenu above minus right-side padding on next line */
padding: 5px 0px 4px 20px;
text-decoration: none;
background-color: #666633;
border-bottom: #447755 dotted 1px;
border-top: 0; border-left: 0; border-right: 0;
}
ul { position: relative; display: block; }
li { position: relative; display: block; }
.submenubox {
margin: 0; padding: 0; border: 0;
}
.submenubox ul
{
margin: 0; padding: 0; border: 0;
list-style-type: none;
}
.submenubox ul li {
margin: 0; padding: 0; border: 0;
}
.submenubox ul li a:link { }
.submenubox ul li a:visited { }
.submenubox ul li a:hover
{
color: #c6e8e2; /* text color for submenu items */
background-color: #447755;
border-bottom: #447755 dotted 1px;
}
</style>
<script type="text/javascript">
// JavaScript functions to show and hide drop-down menus.
// In SimpleNavBar.html we call ShowMenuDiv each time the mouse goes over
// either the menu title or the submenu itself, and call HideMenuDiv when the
// mouse goes out of the menu title or the submenu iteslf (onMouseOut).
function ShowItem (itemID) {
var x = document.getElementById(itemID);
if (x)
x.style.visibility = "visible";
return true;
}
function HideItem (itemID) {
var x = document.getElementById(itemID);
if (x)
x.style.visibility = "hidden";
return true;
}
// As noted in the SimpleNavBarStyles.css file, using x.style.visibility as
// seen below seemed to have better cross browser support than using
// x.style.display="block" and x.style.display="none" to show and hide
// the menu.
</script>
<div class="mynavbar">
<a onmouseover="ShowItem('products_submenu');" onmouseout="HideItem('products_submenu');" href="placeholder.html" id="t1" class="navbartitle">Products</a><a onmouseover="ShowItem('services_submenu');" onmouseout="HideItem('services_submenu');" href="placeholder.html" id="t2" class="navbartitle">Services</a><a onmouseover="ShowItem('funstuff_submenu');" onmouseout="HideItem('funstuff_submenu');" href="placeholder.html" id="t3" class="navbartitle">Fun Stuff</a><a onmouseover="ShowItem('aboutus_submenu');" onmouseout="HideItem('aboutus_submenu');" href="placeholder.html" id="t4" class="navbartitle">About Us</a><a onmouseover="ShowItem('contact_submenu', 't5');" onmouseout="HideItem('contact_submenu');" href="placeholder.html" id="t5" class="navbartitle">Contacts & Directions</a>
<!-- REPLACE each "placeholder.html" URL below with the specific page you want
the user to go to when the given submenu item is clicked. -->
<!-- Products sub-menu, shown as needed -->
<div onmouseout="HideItem('products_submenu');" onmouseover="ShowItem('products_submenu');" id="products_submenu" class="submenu" style="visibility: hidden;">
<div class="submenubox">
<ul>
<li><a class="submenlink" href="placeholder.html">Flying Cars</a></li>
<li><a class="submenlink" href="placeholder.html">Super Squirters</a></li>
<li><a class="submenlink" href="placeholder.html">Sling Shots</a></li>
<li><a class="submenlink" href="placeholder.html">Bamboozlers</a></li>
<li><a class="submenlink" href="placeholder.html">Kazoos</a></li>
</ul>
</div>
</div>
<!-- Services sub-menu, shown as needed -->
<div onmouseout="HideItem('services_submenu');" onmouseover="ShowItem('services_submenu');" id="services_submenu" class="submenu">
<div class="submenubox">
<ul>
<li><a class="submenlink" href="placeholder.html">Toy Design</a></li>
<li><a class="submenlink" href="placeholder.html">Market Research</a></li>
<li><a class="submenlink" href="placeholder.html">IP Consulting</a></li>
<li><a class="submenlink" href="placeholder.html">Licensing</a></li>
</ul></div>
</div>
<!-- Fun Stuff sub-menu, shown as needed -->
<div onmouseout="HideItem('funstuff_submenu');" onmouseover="ShowItem('funstuff_submenu');" id="funstuff_submenu" class="submenu" style="visibility: hidden;">
<div class="submenubox">
<ul>
<li><a class="submenlink" href="placeholder.html">Toys We Designed</a></li>
<li><a class="submenlink" href="placeholder.html">Press Ravings</a></li>
<li><a class="submenlink" href="placeholder.html">Our Blog</a></li>
</ul>
</div>
</div>
<!-- About Us sub-menu, shown as needed -->
<div onmouseout="HideItem('aboutus_submenu');" onmouseover="ShowItem('aboutus_submenu');" id="aboutus_submenu" class="submenu" style="visibility: hidden;">
<div class="submenubox">
<ul>
<li><a class="submenlink" href="placeholder.html">Team</a></li>
<li><a class="submenlink" href="placeholder.html">Investors</a></li>
<li><a class="submenlink" href="placeholder.html">Partners</a></li>
<li><a class="submenlink" href="placeholder.html">Careers</a></li>
<li><a class="submenlink" href="placeholder.html">Our Blog</a></li>
</ul>
</div>
</div>
<!-- CONTACTS & DIRECTIONS sub-menu, shown as needed -->
<div onmouseout="HideItem('contact_submenu');" onmouseover="ShowItem('contact_submenu');" id="contact_submenu" class="submenu" style="visibility: hidden;">
<div class="submenubox">
<ul>
<li><a class="submenlink" href="placeholder.html">Contact</a></li>
<li><a class="submenlink" href="placeholder.html">Getting Here</a></li>
</ul>
</div>
</div><!-- end of sub-meus -->
</div>
<div><select style="margin-left: 200px; position: relative; z-index: 0;">
<option value=""></option>
<option value="28">Test</option>
<option value="Eff2">Test</option>
<option value="Effort1">Test</option>
<option value="FC">Test</option>
<option value="Effort1">Test</option><option value="Effort1">Test</option><option value="Effort1">Test</option><option value="Effort1">Test</option>
</select>
</div>
The <select> element is an interactive content element in HTML5 and a menu in HTML4.01. As such it is an object which requires user input and behaves like a right click context menu and is rendered above all document elements if active. Try it for yourself - open your contextmenu and hover over the navigation.
This bug is connected to the behavior of other interactive content elements such as video (see also HTML5 rendering).
The only way to prevent such behavior is to change the display property of an active select to none while hovering an interactive element. visibility:hidden; won't help since the options are still shown, and using display:none; on options will results in rendering errors.
Here is a small demonstration of the technique described above:
.mynavbar:hover ~ * .selecthack > select:focus
.mynavbar:hover ~ .selecthack > select:focus{
display:none;
}
its very simple
$('IdOfMenu').on('mouseenter', function() {
$("IdOfDropDown").blur();
});
Set your z-index to -1 for it to appear on the bottom. So on your select element you have an inline style defining the z-index to 1. Change it to negative 1.
<select style="margin-left: 200px; position: relative; z-index: -1;">
I tried this in IE8 and it worked. The select drop-down was behind the menu options.
for those who have the same problem it is very easy, add the code below under your code's Menu, this worked for all the navigators.
<input id="HideMenusTxt" name="HideMenusTxt" type="text" value="0" style="width:0;height:0;position:absolute;z-index:-1"/>
<script type="text/javascript">
//menuId= The Id of the div menu
$('#menuId').on('mouseenter', function() {
//in case we have opened select dropdown options, on mouseenter of the menu we set focus to "HideMenusTxt".
$('#HideMenusTxt').focus();
});
Other solution, check if there is a select in the form and focus to the first element in the form instead of creating a hidden field.
$('#menuId').mouseover(function () {
//in case we have opened select dropdown options, on mouseover of the menu we set focus to the first element in the form.
var firstSelectElement = $('form:first select:first');
if (firstSelectElement.length > 0) {
$('form:first *:input[type!=hidden]:first').focus();
}
});
Using display: none causes the dropdown to lose it's focus, if it has - at least in Chrome, not so in Firefox. This can cause trouble, if some content shall be displayed instead of the <select> when the dropdown is used (replace options by some custom HTML).
Using position: relative; z-index: -1 may also cause trouble: As it makes the <select> disappear behind the default layer, it may become impossible to click the dropdown. Further, the "focus" event may be fired after the options have been rendered, so changing the z-index via JavaScript may not work as intended.
I came up with the solution to shift the dropdown out of view on "focus" and shift it back on "blur":
position: relative; left: -9999px;
Compared to display: none, this solution also keeps the layout intact (except that the dropdown disappears), as the dropdown may define the height of its parent block element.
As Zeta said, the select box is an interactive element, you can't display anything above it using HTML/CSS, so the only option is to hide it when showing your menu, or simply to blur any focused selects on the page.
If you don't want to add any additional css classes though, you could simply blur() either at the start of your ShowItem function:
...
function ShowItem (itemID) {
//jQuery version
$('select:focus').blur();
//OR non-jQuery:
document.activeElement.blur();
//note this will blur any focused element, so you might want to check
//if document.activeElement.tagName == 'SELECT' first, or other conditions
var x = document.getElementById(itemID);
...
...or more generically (for other readers not in your specific situation) in a hover or mouseenter event callback on the menu items that trigger the submenus appearance.