display inline-block makes element focusable in Firefox - html

Does anyone know why the following issue occurs only in Firefox browser? And how to fix that?
When the user wants to use the keyboard with the Firefox browser unexpected behavior occurs around . menu-button button.
If you press tab after the . menu-button button you don't come out on the next ‘test 2’ button as expected, but the focus seems to disappear. If you then press TAB two more times you do end up on ‘test 2’ button.
Our research showed that the span with the attribute data-email="long" has the css property display: inline-block and that makes this span focusable. The display inline-block on [data-email="long"] span is needed so that the long email hooks off behind the white gradient.
You can find a demo of the issue here (test it in Firefox):
/* base */
html, body {
padding: 20px;
}
ul {
display: flex;
list-style: none
}
li {
position: relative;
}
button {
margin: 10px;
}
.menu-button {
display: inline-block;
position: relative;
color: #003082;
cursor: pointer;
font-weight: 700;
line-height: 1.5625rem;
width: 85px;
text-align: left;
&:focus {
&::after {
content: '';
display: block;
position: absolute;
top: -4px;
left: -4px;
right: -4px;
bottom: -4px;
border-radius: 4px;
border: 1px solid blue;
box-shadow: 0 0 0 1px #0063d3, 0 2px 28px rgba(#000, 0.1);
}
outline: none;
}
}
.menu-button-text {
margin-right: 0;
&::before {
content: "";
height: 2.1875rem;
width: 2.1875rem;
position: absolute;
left: -3px;
top: -4px;
}
}
[data-email=long] {
display: inline-block;
width: 68px;
overflow-x: hidden;
vertical-align: top;
&::after {
content: "";
position: absolute;
top: 0;
right: 0;
width: 3rem;
height: 100%;
z-index: 1;
opacity: 1;
background: linear-gradient(90deg,hsla(0,0%,100%,0),#fff 90%);
}
}
/* utils */
.unbutton {
border: none;
background: none;
padding: 0;
}
.alt {
position: absolute;
-webkit-clip-path: polygon(0 0,0 0,0 0,0 0);
clip-path: polygon(0 0,0 0,0 0,0 0);
width: 1px;
height: 1rem;
margin: 0;
overflow: hidden;
white-space: nowrap;
}
<ul>
<li>
<button>
test 1
</button>
</li>
<li>
<button class="unbutton menu-button">
<span class="alt">logged in with:</span>
<span class="menu-button-text menu-button-text--full">
<span class="h-acc-visible-l" data-email="long" >test#test.com</span>
</span>
</button>
</li>
<li>
<button>
test 2
</button>
</li>
</ul>
Only the button must be focusable and not the span(s)

Dirty, but: Set your buttons with attribute "tabindex" and positive values (1 to 3), while all your spans inside button #2 get tabindex="-1"; just tried your fiddle with this mod and works at least in FF85.

Related

CSS offset a tooltip

I am trying to attach a tooltip to a button.
.hangup_button {
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: 25px;
}
.contained_message {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
}
.messageContain:hover .contained_message{
visibility: visible;
}
<div class="container_div">
<button class="hangup_button messageContain">
End Chat
<span class="contained_message">Terminate session. Charges stop accumulating.</span>
</button>
</div>
The problem I have is that the tooltip appears at the bottom of the button. I am trying to make it appear to the top of the button. So far, I tried to switch the <span class="contained_message"> to the top of the End Chat text. But the tooltip still exceeds the bottom of the button. I also tried to add position: relative; to .contained_message. That seems to mess up the whole button. What should I do in order for the tooltip to appear on top of the button, without exceeding the bottom of the button?
I added some changes to make it work:
Use position: relative on parent element.
Use transform: translate to get the desired placement, as well as top: -5px (can be 0, but -5 gives it a nice space)
I changed it to display: none / block instead of using visibility, as it may be more desirable (providad you are not looking to do transitions).
To center the tooltip horizontally, left: 50% with translate(-50%, ...) does the trick.
Working snippet:
.hangup_button {
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: 25px;
margin-top: 80px;
position: relative;
}
.contained_message {
display: none;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
transform: translate(-50%, -100%);
left: 50%;
top: -5px;
}
.messageContain:hover .contained_message{
display: block;
}
<div class="container_div">
<button class="hangup_button messageContain">
End Chat
<span class="contained_message">Terminate session. Charges stop accumulating.</span>
</button>
</div>

Replacing a checkbox element with icons

I want to customize the browser checkbox. When the status is checked, the icon checked.svg should be displayed instead of checkbox and the icon unchecked.svg otherwise.
Here is my code.
HTML:
<div class="checkbox-custom">
<input type="checkbox"/>
<div class="checkmark">
<img src="#/assets/images/icons/checkbox/unchecked.svg" class="unchecked"/>
<img src="#/assets/images/icons/checkbox/checked.svg" class="checked"/>
</div>
</div>
SASS:
.checkbox-custom {
position: absolute;
width: 28px;
height: 28px;
left: 0;
top: 0;
// Hide default browser checkbox
input[type=checkbox] {
display: none;
}
input[type=checkbox] + .checkmark {
position: absolute;
left: 3.5px;
top: 3.5px;
right: 3.5px;
bottom: 3.5px;
display: inline-block;
cursor: pointer;
img {
width: 21px;
height: 21px;
}
.checked {
display: none;
}
}
input[type=checkbox]:checked + .checkmark {
.checked {
display: block;
}
.unchecked {
display: none;
}
}
}
When i click on the checkbox, nothing happens. What could be the error?
This can be accomplished without any javascript. Clicking the label element toggles the checkbox inside of it, so with some clever css, we can change the display based on the input's checked state.
input[type=checkbox] {
display: none;
}
.label {
border: 1px solid #000;
display: inline-block;
padding: 3px;
/* background: url("unchecked.png") no-repeat left center; */
/* padding-left: 15px; */
}
input[type=checkbox]:checked + .label {
background: #f00;
color: #fff;
/* background-image: url("checked.png"); */
}
<label><input type="checkbox"><span class="label">Check me</span></label>
Change the .label styles to use background-image of your choice (and position it to the left of your text).
http://jsfiddle.net/pKM3x/
CSS:
.checkbox{
width: 23px;
height: 21px;
background: transparent url(http://i.stack.imgur.com/S4p2R.png ) no-repeat 0 50%
}
.checked{
background: transparent url(http://i.stack.imgur.com/S4p2R.png ) no-repeat 80% 50%
}
HTML:
<div class="checkbox">
</div>
JQUERY:
$(".checkbox").click(function(){
$(this).toggleClass('checked')
});
This also possible to do with pure JS.

How to make this image lightbox work for both horizontal and vertical images?

I need to create an image lightbox. I basically started from this example from w3school, https://www.w3schools.com/howto/howto_js_lightbox.asp
However, it doesn't work for portrait oriented images. Eg. a landscape image is 1200x800 and a portrait can be 800x1200.
I need the images to resize responsive and work for both horizontal and vertical images.
It needs to work for all modern browsers, ios, android and also IE11.
you'll see I've added "max-width: 1200px;" to lightbox-content, which does the trick for horizontal images... but since a vertical image is 800 wide, it enlarges and the height exceeds.
<div class="lightbox">
<span class="close" onclick="closeLightbox()">×</span>
<div class="lightboxTitle">My Title</div>
<div class="lightbox-content">
<div class="slide"><img src="img1.jpg"></div>
<div class="slide"><img src="img2.jpg"></div>
<div class="slide"><img src="img2.jpg"></div>
<!-- Next/previous controls -->
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
/* The Modal (background) */
.lightbox {
display: none;
position: fixed;
z-index: 99999999;
padding-top: 60px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
}
/* Modal Content */
.lightbox-content {
position: relative;
margin: auto;
padding: 0;
width: 100%;
max-width: 1200px;
}
.lightboxTitle {
position: absolute;
top: 20px;
left: 25px;
font-size: 20px;
}
/* The Close Button */
.close {
color: white;
position: absolute;
top: 10px;
right: 25px;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #FF8511;
text-decoration: none;
cursor: pointer;
}
/* Hide the slides by default */
.slide {
display: none;
}
.slide img {
width: 100%;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
.prev {
left: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
color: #FF8511;
}
I had the same issue in one of my past projects. I solved it with this js library https://imagesloaded.desandro.com/,
It allows you to process the images after they are loaded, and you can then assign a css class to it according to the aspect ratio.
$('#container').imagesLoaded( function() {
// images have loaded
// check image height/width > 1, portrait
// check image heidht/width <= 1, square or landscape
// assign different classes for each case to handle
});
css:
.img-container {
//do whatever you need on the container
}
// keep the image classes like this
.img-container img.portrait {
height: 100%;
width: auto;
}
.img-container img.landscape {
width: 100%;
height: auto;
}

How can I hide content I've created using the :before pseudo selector when a HTML text element is empty?

I'm creating a chat bubble with CSS and HTML.
If there is no text in the chat bubble I do not want it to display.
I can get body of the chat bubble to go away using :empty but I cannot get the triangle part of the chatbox to disappear because it was created with the pseudo selector :before and content: ' '.
My code is below. Is there anyway to make this little triangle go away if the h4 element is empty?
/* CSS talk bubble */
.myFeedback h4:empty {
display: none;
}
.talk-bubble {
margin-top: 220px;
left: 390px;
display: inline-block;
position: absolute;
width: 200px;
height: auto;
background-color: purple;
}
.round {
border-radius: 10px;
}
.tri-right.right-in:before {
content: '';
position: absolute;
width: 0;
height: 0;
left: auto;
right: -20px;
top: 38px;
bottom: auto;
border: 12px solid;
border-color: purple transparent transparent purple;
}
/* talk bubble contents */
.talktext {
padding: 10px;
text-align: center;
line-height: 1.5em;
}
.talktext p {
/* remove webkit p margins */
-webkit-margin-before: 0em;
-webkit-margin-after: 0em;
}
/* end of talk bubble stuff */
<div class="myFeedback">
<div id='guess-feedback' class="talk-bubble tri-right round right-in">
<h4 class="talktext"></h4>
</div>
</div>
/* CSS talk bubble */
h4:empty {
display: none;
}
.talk-bubble {
margin-top: 220px;
left: 390px;
display: inline-block;
position: absolute;
width: 200px;
height: auto;
background-color: purple;
}
.round{
border-radius: 10px;
}
.tri-right.right-in h4:before {
content: '';
position: absolute;
width: 0;
height: 0;
left: auto;
right: -20px;
top: 38px;
bottom: auto;
border: 12px solid;
border-color: purple transparent transparent purple;
}
/* talk bubble contents */
.talktext{
padding: 10px;
text-align: center;
line-height: 1.5em;
}
.talktext p{
/* remove webkit p margins */
-webkit-margin-before: 0em;
-webkit-margin-after: 0em;
}
/* end of talk bubble stuff */
<div class="myFeedback">
<div id='guess-feedback' class="talk-bubble tri-right round right-in">
<h4 class="talktext"></h4>
</div>
</div>
<div class="myFeedback">
<div id='guess-feedback' class="talk-bubble tri-right round right-in">
<h4 class="talktext">With Text</h4>
</div>
</div>
Change below code in your CSS
From:
.tri-right.right-in:before
To
.tri-right.right-in h4:before

Css button sprite

I'm trying to get this Sprite done, but i'm stuck and can't figure out a solution.
FIDDLE HERE
I have a simple button:
<a href="#" class="ui-button sub-beta-button">
<span class="button-content">Beta Sign-Up</span>
</a>
and the css:
.sub-beta-button {
height: 78px;
background: transparent url("http://i.imgur.com/PSpIGLA.png") 100% -160px no-repeat;
padding-right: 50px;
margin-left: 30px;
bottom: 18px;
z-index: 1;
position: relative;
}
.ui-button {
background: 0;
border: 0;
cursor: pointer;
display: inline-block;
height: auto;
overflow: visible;
padding: 0;
margin: 0;
vertical-align: middle;
outline: 0;
text-align: center;
white-space: nowrap;
cursor: pointer;
}
.sub-beta-button .button-content {
background-image: url("http://i.imgur.com/PSpIGLA.png");
padding-left: 50px;
color: #fff;
font: normal normal 18px/86px "Bliz Quadrata", Times New Roman;
text-transform: uppercase;
text-shadow: 0 0 4px #000, 0 0 8px #000;
overflow: hidden;
min-width: 110px;
margin-left: -30px;
height: 76px;
z-index: 2;
}
.ui-button span {
outline: 0;
display: inline-block;
background-repeat: no-repeat;
}
but i'm getting only this result:
That's the Sprite:
FIDDLE HERE
your .ui-button class removes the background (background: 0).
You can better first get the button working without the ui-button class, and then rule by rule fill up the ui-button class. That way you are sure you are using minimal and correct css.
I've made an edit and removed all the junk code.
If you want the text to the center, edit padding-left and add text align:center
padding-left
and change it to
text-align:center
http://jsfiddle.net/va854