Position a tooltip not relative to the "origin" [css] - html

I have several images which have a Tooltip on hover ( which display another image)
The thing looks like this
http://i.stack.imgur.com/PjywK.jpg
Now my problem is that, everytime I hover over one image it locks the tooltip to the image. So the tooltip is in a different position everytime I hover over a different image. my css for this looks like this:
.playertooltip {
outline: none;
text-decoration: none;
position: relative;
}
.playertooltip span {
display: none;
position:absolute;
border: 5px solid white;
}
.playertooltip:hover span {
display: block;
position:absolute;
border: 5px solid white;
z-index: 99;
}
Well, I want to find a fixed position for EVERY tooltip so that, when I hover over different images the tooltip appears in the same place.
Thanks for the help :)
For clarifycation:
http://jsfiddle.net/auNVb/

The hovered position needs to be changed to fixed, add a left/right position of 50% and a variable top position like the following:
.playertooltip {
outline: none;
text-decoration: none;
position: relative;
}
.playertooltip span {
display: none;
position:absolute;
border: 5px solid white;
}
.playertooltip:hover span {
display: block;
position:fixed; /* Changed from absolute */
border: 5px solid white;
z-index: 99;
left: 50%; /* Move it to the "half" of the page */
top: 20%; /* Move it to the "half" of the page (from the top).
You have to experiment with this,
as I had variable results depending
on the elements present in the page. */
}

Related

Breakable colored underline in CSS

I would like to have a colored underline that looks like this when it breaks:
text-decoration-color seems to be not supported widely enough.
I tried this:
.underline {
position: relative;
}
.underline:after {
position: absolute;
content: '';
height: 1px;
background-color: #ffc04d;
bottom: .1rem;
right: 0;
left: 0;
z-index: -1;
}
<h1><span class="underline">Sprouted Bread</span></h1>
What about a linear-gradient where it will be easy to control color, size and distance within a single element:
.underline {
position: relative;
font-size:28px;
background:
linear-gradient(yellow,yellow) /* Color */
left 0 bottom 2px/ /* Position */
100% 2px /* Size (width height)*/
no-repeat;
}
<div style="width:150px;text-align:center"><span class="underline">Sprouted Bread</span></div>
As a side note, border-bottom works fine used with inline element but of course you cannot easily control the distance to make it behave as a text-decoration:
.underline {
position: relative;
font-size:28px;
border-bottom:2px solid yellow;
}
<div style="width:150px;text-align:center"><span class="underline">Sprouted Bread</span></div>
Try this JSFiddle
By wrapping the elements like you have in a span. You can put the text decoration on the parent element and the text color on the span.
HTML:
<h1><span class="underline">Some Text</span></h1>
CSS:
h1 {
text-decoration: underline;
color: red;
}
.underline {
color: blue;
}
Just add a border!
Using display: inline, add a bottom border and space it with padding.
You could also use line-height and then place negative margins to increase the space in between the lines.
And...you could also animate it!
.underline {
position: relative;
padding-bottom: 1px;
border-bottom: 1px solid #ffc04d;
}
<h1 style="width: 5em">
<span class="underline">Sprouted Bread</span>
</h1>
As mentioned by #chriskirknielsen, you could use box-decoration-break, although not supported by IE or Edge. Credits: #Temani Afif

How put some horizontal offset to an element bottom border with CSS?

I use bottom-border on some a element, and I want to add some horizontal offset to the border.
What I have now:
Link very cool name
-------------------
What I want:
Link very cool name
----------------
How can I archive this? Only using an a element.
A pseudo-element is ideal here which can be styled in any fashion you want, color, width & height...even position below the link text.
a {
position: relative;
text-decoration: none;
}
a::after {
content: "";
position: absolute;
top: 100%;
right: 0;
width: 75%;
height: 2px;
background: orange;
}
Long stretch of text
You can try this:
a{
text-decoration: none;
display:inline-block;
}
a:after{
content: "";
border-bottom: dotted 2px red;
width: 70%;
float: right;
padding-top: 5px;
}
https://jsfiddle.net/9xc0x58c/1/
You could use a pseudo element ie :after element for this and abs pos it, 1px high background colour and width of you chosen link length etc.
Would that be the required result? Not sure the requirement as to why you would want this but it should achieve the required result.
you can use span
HTML
Link <span class="un">very cool name</span>
CSS
.un{
border-bottom: dotted 2px red;
}

How to make a span tag to be centered from it's current elemental ( Like Youtube share button )

I am currently working on my share buttons and I am trying to make them act like the share buttons on YouTube do, when a:hovered a span elemental appears with a text "Facebook/Twitter/RSS" etc.
The span element width should be auto since "Facebook" and "RSS" contains a different amount of letters, and I don't want to set a fixed width.
I want the span element to appear in the "middle" of it's current element, check the youtube share buttom for a hint.
I have come this far, see: http://jsfiddle.net/Kz2n2/
try this:
<span title="share">share</span>
css:
.tooltip{
display: inline;
position: relative;
}
.tooltip:hover:after{
background: #333;
background: rgba(0,0,0,.8);
border-radius: 5px;
bottom: 26px;
color: #fff;
content: attr(title);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 100%;
}
.tooltip:hover:before{
border: solid;
border-color: #333 transparent;
border-width: 6px 6px 0 6px;
bottom: 20px;
content: "";
left: 50%;
position: absolute;
z-index: 99;
}
working jsfiddle:
demo
With jQuery UI Tooltip you can make tooltips for your social icons.
Check out the following example, here is the jQuery UI Tooltip implemented.
$('.tooltip').tooltip();
The title tag on your <a href='#'>` is used as the text for your tooltip.
#<span>RSS.</span>

CSS drop-down menu fails to remain following hover activity

I'm currently working on a couple of drop-down menus on the following page:
http://icao.tungsten.hireserve-test.com/home.html
Originally, we only had one of these menus but our client has since changed their template and we now need to implement two drop-down menus. Previously this was done with jQuery hover() events which fired show() and hide() but now I have replaced this with CSS.
li.dynamic-children{
position: relative
}
li.dynamic-children ul{
display: none;
position: absolute;
}
li.dynamic-children:hover ul{
display: block;
left: -1px;
top: 18px;
position: absolute;
z-index: 100
}
li.dynamic-children:hover ul span{
width: 100%
}
The dropdown menu is displayed successfully on hover however because it is done with CSS there does not appear to be any way of ensuring that the drop-down persists when the user moves off of the link which triggers the drop-down. This means that the user cannot select any of the items in the dropdown menu rendering it useless.
Do any of you have any ideas as to how I can force the menu to persist long enough for users to be able to make a selection for the drop-down menus?
EDIT:
Based upon some of the code provided below I have now included the following CSS rules:
.s4-tn .horizontal ul.dynamic {
background-color: #ECF4FC;
border-top:4px solid #003D78;
margin: 0;
width: 255px;
z-index: 1000 !important;
}
.menu-horizontal li.static, .menu-horizontal a.static, .menu-horizontal span.static {
float: left;
padding-bottom: 5px;
}
These rules cause the menu to persist however in IE7 the drop-down menu now falls behind other elements on the page rendering it still useless in this browser. I have tried numerous z-index fixes to no avail.
try this one,
.s4-tn .horizontal ul.dynamic {
background-color: #ECF4FC;
border: 0 solid #003D78;
margin: 0;
width: 255px;
z-index: 101;
}
li.dynamic-children:hover ul {
display: block;
left: -1px;
position: absolute;
top: 22px;
}
Either 1 of the two:
Option 1 (Line 2840)
. .s4-tn li.static > .menu-item {
color: #3b4f65;
white-space: nowrap;
border: 1px solid transparent;
padding: 4px 10px;
display: inline-block;
height: 34px;
vertical-align: middle;
}
Option 2 (Line 99)
.s4-tn .horizontal ul.dynamic {
margin: 0 0 0 0;
border: 0px #003D78 solid;
width: 255px;
background-color: #ecf4fc;
}

How can I prevent the browser from scrolling on top of the page when clicking the checkbox?

Whenever I click on the checkbox, the browser window (firefox) will scroll on the top of the screen.
How can I prevent this behavior so when I click on the checkbox the browser window will not scroll on top?
Here is the code found from here http://jsfiddle.net/zAFND/6/
Thank you.
<html>
<head>
<title>Test</title>
<style>
div label input {
margin-right: 100px;
}
body {
font-family:sans-serif;
}
#ck-button {
margin: 4px;
background-color: #EFEFEF;
border-radius: 4px;
border: 1px solid #D0D0D0;
overflow: auto;
float: left;
}
#ck-button {
margin: 4px;
background-color: #EFEFEF;
border-radius: 4px;
border: 1px solid #D0D0D0;
overflow: auto;
float: left;
}
#ck-button:hover {
margin: 4px;
background-color: #EFEFEF;
border-radius: 4px;
border: 1px solid red;
overflow: auto;
float: left;
color: red;
}
#ck-button label {
float: left;
width: 4.0em;
}
#ck-button label span {
text-align: center;
padding: 3px 0px;
display: block;
}
#ck-button label input {
position: absolute;
top: -20px;
}
#ck-button input:checked + span {
background-color: #911;
color: #fff;
}
</style>
</head>
<body>
<br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<div id="ck-button">
<label>
<input type="checkbox" value="1"><span>red</span>
</label>
</div>
</body>
The problem is this rule:
#ck-button label input {
position:absolute;
top:-20px;
}
When you click on a label the browser tries to focus the related input. In your case the checkbox element is lying at the top of the page, even outside the viewport – so Firefox tries to scroll there.
You can solve it like this by adding:
#ck-button label {
display: block;
position: relative;
overflow: hidden;
}
Demo
Try before buy
Alternative
Heisenberg points out a problem in his answer which can occur when using extreme values. Unfortunately the proposed idea has the same quirk as the one shown above.
So an alternative solution is simply to hide the input. The functionality is not affected.
CSS
#ck-button label input {
display: none;
}
Demo
Try before buy
The answer accepted is not entirely true. Works, but not in all cases.
If you use the common css to hide elements (probably -999em or similar) at the "top" attribute, in this case position:relative has nothing to do because always -999em will be much higher than the viewport.
The answer accepted works fine because the "top" is only -20px . Try to set it a more higher number and you´ll see the problem.
So, the solution is not to set a relative position.
I think the correct way is only to set a negative value at left position (not top).
Try it. :)
you could hide your checkbox input like this:
#ck-button label input {
position:absolute;
top:+20px;
visibility: hidden;
}