I am building my first website and I am having some hidden speech bubbles appear when you hover over image like this demo
However I don't know how to affect the positioning measurements of the speech bubble, how could I make it so the speech bubble is aligned in the center of the box bellow it?
Any help would be much appreciated!
HTML:
<div id="container">Hover over me!<span>Hidden message here.</span></div>
CSS:
#container {
background-color: #FF0;
margin: 100px;
float: left;
height: 200px;
width: 200px;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
a.hoverbubble {
position: relative;
text-decoration: none;
}
a.hoverbubble span {display: none;
}
a.hoverbubble:hover span {
display: block;
position: absolute;
padding: .5em;
content: attr(title);
min-width: px;
text-align: center;
width: auto;
height: auto;
white-space: nowrap;
top: -40px;
background: rgba(0,0,0,.8);
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
color: #fff;
font-size: 0.86em;
font-family: Arial, Helvetica, sans-serif;
}
a.hoverbubble:hover span:after {
position: absolute;
display: block;
content: "";
border-color: rgba(0,0,0,.8) transparent transparent transparent;
border-style: solid;
border-width: 10px;
height: 0;
width: 0;
position: absolute;
bottom: -20px;
left: 1em;
}
Set your container div to position:relative
remove position:relative from your a tag
Changing position:relative from your a tag to your div container will allow your absolutely positioned span to align relative to the container rather than the a tag.
set your span to position:absolute
align your span by editing the values top:40%; left: 11%;
you can now position your span element relative to your container.
http://jsfiddle.net/e4q7K/18/
On the assumption that the hidden message is to be centered on the link..
JSFiddle Demo
HTML
<div id="container">
<a href="#" class="hoverbubble">Hover over me!
<span>Hidden message here.</span>
</a>
</div>
CSS
#container {
background-color: #FF0;
margin: 100px;
float: left;
height: 200px;
width: 200px;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
a.hoverbubble {
position: relative;
text-decoration: none;
background-color: lightblue;
}
a.hoverbubble span {display: none;}
a.hoverbubble:hover span {
display: block;
position: absolute;
padding: .5em;
text-align: center;
width: auto;
height: auto;
white-space: nowrap;
top: -40px;
left:50%; /* push the block halfway over to the right */
-webkit-transform:translate(-50%, 0); /* move it back left half it's own width */
background: rgba(0,0,0,.8);
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
color: #fff;
font-size: 0.86em;
font-family: Arial, Helvetica, sans-serif;
}
a.hoverbubble:hover span:after {
position: absolute;
display: block;
content: "";
border-color: rgba(0,0,0,.8) transparent transparent transparent;
border-style: solid;
border-width: 10px;
height: 0;
width: 0;
position: absolute;
bottom: -20px;
left: 1em;
}
Related
So, it's my first time getting into HTML/CSS and naturally, I'm having problems with certain parts.
I made a "Contine" button in my setup.html and gave it a class so I can style it in my styles.css, now the problem is that text-align center doesnt work on the button. I also have a "Start" button in my index.html, but strangely text-align center works there. I tried giving both buttons the same class and different classes. I'm not sure what to do at this point in time.\
My Button in HTML:
<div class="startcontainer">
<a href="./home.html">
<button id="continue"><span>Continue</span></button>
</a>
</div>
My CSS:
.startcontainer {
position: fixed;
border-radius: 5px;
width: calc(100% - 20px);
height: calc(100% - 120px);
left: 10px;
right: 10px;
bottom: 3%;
margin-bottom: 10px;
padding: 0px;
background-color: #1F1F1F;
float: middle;
text-align: center;
}
.startcontainer a {
position: relative;
display: block;
margin: 0 auto;
top: 40%;
text-decoration: none;
border: 0;
}
.startcontainer a #continue {
position: relative;
max-width: 280px;
max-height: 60px;
line-height: 60px;
padding: 10px 100px;
font-size: xx-large;
background-color: #1F1F1F;
color: #FFFFFF;
opacity: .87;
line-height: normal;
font-family: 'Open Sans', sans-serif;
border: 5px solid #8644A1;
border-radius: 45px;
display: block;
margin: 0 auto;
top: 40%;
transition: 0.4s;
outline: 0;
cursor: pointer
}
.startcontainer a #continue span {
display: block;
line-height: 30px;
}
.startcontainer a #continue:hover {
background-color: #8644A1;
}
Like I said the #contine part in my styles.css is the exact same for the "start" button, but it only works for the start button.
Problem is with max-width: 280px; and padding: 10px 100px; of button.
you are giving padding of 200px on the horizontal scale and then you are limiting button width to 280px. which leaves only 80px for text within. Remove button width for a better look of a button. Alternatively, you can trade off any of the CSS property over others.
.startcontainer {
position: fixed;
border-radius: 5px;
width: calc(100% - 20px);
height: calc(100% - 120px);
left: 10px;
right: 10px;
bottom: 3%;
margin-bottom: 10px;
padding: 0px;
background-color: #1F1F1F;
float: middle;
text-align: center;
}
.startcontainer a {
position: relative;
display: block;
margin: 0 auto;
top: 40%;
text-decoration: none;
border: 0;
}
.startcontainer a #continue {
position: relative;
/* max-width: 280px; */
max-height: 60px;
line-height: 60px;
padding: 10px 100px;
font-size: xx-large;
background-color: #1F1F1F;
color: #FFFFFF;
opacity: .87;
line-height: normal;
font-family: 'Open Sans', sans-serif;
border: 5px solid #8644A1;
border-radius: 45px;
display: block;
margin: 0 auto;
top: 40%;
transition: 0.4s;
outline: 0;
cursor: pointer
}
.startcontainer a #continue span {
display: block;
line-height: 30px;
}
.startcontainer a #continue:hover {
background-color: #8644A1;
}
<div class="startcontainer">
<a href="./home.html">
<button id="continue"><span>Continue</span></button>
</a>
</div>
Currently I am trying to center my arrows that are created using CSS when I hover over my nav menu. Even though I have set the margin left and right to auto. It still does not seem to want to center. It could be because of the format of my HTML. I have tried a number of options but none of them seem to have helped.
Please see my HTML and CSS below:
(Unfortunately I cannot seem to re-create my code but I will post it and continue to try and recreate it in the mean time)
#navbar {
overflow: hidden;
background-color: $base-white;
font-size: 11px;
z-index: 2;
border: 1px solid $base-grey;
height: 50px;
}
.navbar-links {
margin-left: 10em;
height: 100%;
padding: 0em 4em 0em 1em;
min-width: 348px;
margin-top: auto;
margin-bottom: auto;
}
#navbar .navbar-links a {
display: block;
float: left;
color: $base-grey;
padding: 14px 20px 14px 20px;
text-decoration: none;
font-size: 14px;
margin-top: auto;
margin-bottom: auto;
}
#navbar .navbar-links a:hover:after {
content: ' ';
position: absolute;
bottom: -10px;
width: 0;
height: 0;
text-align: center;
border-width: 10px 10px 0;
border-style: solid;
border-color: $base-grey transparent;
margin: 0 auto;
display: block;
}
<div class="navbar-links">
<div class="navbar-dropdown">
<button class="navbar-drop-btn">
<div class="navbar-arrow"></div>
</button>
<div class="navbar-dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<a [routerLinkActive]="['navbar-links-active']" [routerLink]="['insights']" (mouseover)="displayInsightDropDown();" (mouseleave)="hideInsightDropDown();">INSIGHTS</a>
<a [routerLinkActive]="['navbar-links-active']" [routerLink]="['explore']">EXPLORE</a>
<a [routerLinkActive]="['navbar-links-active']" [routerLink]="['aboutus']">ABOUT</a>
</div>
Here is a picture of the result:
As you can see the arrow is positioned to the left, but never the center.
Any suggestions would help, thank you in advance.
You need to set the context for the absolutely positioned ::after. To do so, add a non static position (position: relative in this case) to the <a> tags.
To center the ::after element, I've used left: calc(50% - 10px) because the width of the arrow is known (20px). If to arrow can have variable size, you can use:
left: 50%;
transform: translateX(-50%);
.navbar-links {
margin-left: 10em;
height: 100%;
padding: 0em 4em 0em 1em;
min-width: 348px;
margin-top: auto;
margin-bottom: auto;
}
.navbar-links a {
position: relative; /** the absolute context **/
display: block;
float: left;
color: grey;
padding: 14px 20px 14px 20px;
text-decoration: none;
font-size: 14px;
margin-top: auto;
margin-bottom: auto;
}
.navbar-links a:hover::after {
left: calc(50% - 10px);
position: absolute;
content: ' ';
bottom: -10px;
width: 0;
height: 0;
border-width: 10px 10px 0;
border-style: solid;
border-color: grey transparent;
display: block;
content: ' ';
}
body {
overflow: hidden;
}
<div class="navbar-links">
INSIGHTS
EXPLORE
ABOUT
</div>
Although answer is accepted but I've another solution using flex property of CSS, add two line inside .navbar-links a
display: flex;
justify-content: center;
no need for calculation
.navbar-links {
margin-left: 10em;
height: 100%;
padding: 0em 4em 0em 1em;
min-width: 348px;
margin-top: auto;
margin-bottom: auto;
}
.navbar-links a {
position: relative;
/** the absolute context **/
display: flex;
justify-content: center;
float: left;
color: grey;
padding: 14px 20px 14px 20px;
text-decoration: none;
font-size: 14px;
margin-top: auto;
margin-bottom: auto;
}
.navbar-links a:hover::after {
position: absolute;
bottom: -10px;
width: 0;
height: 0;
border-width: 10px 10px 0;
border-style: solid;
border-color: grey transparent;
content: ' ';
}
body {
overflow: hidden;
}
<div class="navbar-links">
INSIGHTS
EXPLORE
ABOUT
</div>
My problem is that the :after element is on the text in an element. Here is an example:
On CodePen
I want the :after to be below the text.
How can I fix this?
body {
text-align: center;
}
a {
display: inline-block;
text-decoration: none;
padding: 10px;
background: #222;
color: #f3f3f3;
font-size: 2em;
margin: 20px auto;
position: relative;
}
a:after {
content: "";
width: 100%;
height: 50%;
background: #00A3A3;
position: absolute;
left: 0;
top: 0;
}
Home page
Just change top:0 to top:50px; in after css. By keeping top:0
The top property sets the top edge of an element to a unit above/below the top edge of its nearest positioned ancestor.
you are making the element to stay on the top by keeping it 0
body {
text-align: center;
}
a {
display: inline-block;
text-decoration: none;
padding: 10px;
background: #222;
color: #f3f3f3;
font-size: 2em;
margin: 20px auto;
position: relative;
}
a:after {
content: "";
width: 100%;
height: 50%;
background: #00A3A3;
position: absolute;
left: 0;
top: 50px;
}
Home page
Use top: 100% on the :after pseudo element to place it exactly below the main element.
body {
text-align: center;
}
a {
display: inline-block;
text-decoration: none;
padding: 10px;
background: #222;
color: #f3f3f3;
font-size: 2em;
margin: 20px auto;
position: relative;
}
a:after {
content: "";
width: 100%;
height: 50%;
background: #00A3A3;
position: absolute;
left: 0;
top: 100%;
}
Home page
I have some hidden speech bubbles that appear when you hover over links like this demo:
http://jsfiddle.net/mmorrell2014/e4q7K/
HTML:
<div id="container">Hover over me!<span>Hidden message here.</span></div>
CSS:
#container {
background-color: #FF0;
margin: 100px;
float: left;
height: 200px;
width: 200px;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
a.hoverbubble {
position: relative;
text-decoration: none;
}
a.hoverbubble span {display: none;
}
a.hoverbubble:hover span {
display: block;
position: absolute;
padding: .5em;
content: attr(title);
min-width: px;
text-align: center;
width: auto;
height: auto;
white-space: nowrap;
top: -40px;
background: rgba(0,0,0,.8);
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
color: #fff;
font-size: 0.86em;
font-family: Arial, Helvetica, sans-serif;
}
a.hoverbubble:hover span:after {
position: absolute;
display: block;
content: "";
border-color: rgba(0,0,0,.8) transparent transparent transparent;
border-style: solid;
border-width: 10px;
height: 0;
width: 0;
position: absolute;
bottom: -20px;
left: 1em;
}
I was wondering if it is possible to make this tooltip appear when you hover over an image instead of a link?
If you want a very simple solution, change your code like below.
<div id="container"><img src="sample.gif" border="0" /><span>Hidden message here.</span></div>
If you don't want to use anchor tag itself then check the below jsfiddle, I have updated your code.
http://jsfiddle.net/e4q7K/19/
I currently have a problem with my z-index with IE.
I have a div, an image in this div and some text over this image.
Here is my HTML code:
<section id="content_right">
<div class="mini_bloc_image">
<img alt="Camionnette VCI" src="img/mini_reparation_site_nb.png" />
<span>Réparation sur site</span>
<span>Nous nous déplaçons</span>
</div>
and the CSS:
#content_right {
width: 230px;
height: 484px;
float: right;
}
.mini_bloc_image {
height: 148px;
margin-bottom: 20px;
position: relative;
}
.mini_bloc_image > img {
position: absolute;
}
.mini_bloc_image > span:first-of-type {
display: block;
position: absolute;
top: 95px;
left: 0px;
font-size: 1.1em;
background-color: #ffffff;
padding: 4px 5px 4px 5px;
}
.mini_bloc_image > span:last-of-type {
display: block;
top: 95px;
left: 0px;
position: absolute;
left: 50px;
top: 125px;
color: #ffffff;
font-size: 1.1em;
font-family: 'Marck Script', cursive;
}
IE don't understand my text must be OVER the image...
I found some solutions like this http://www.adrenatie.com/z-index-et-ie6/ or this http://systembash.com/content/css-z-index-internet-explorer/ but it don't works.
Can someone help me please?
Problem is you're dealing with spans, which are rendered inline by default. If you use display:block, the z-index will be used:
.mini_bloc_image > span:first-of-type {
display: block;
position: absolute;
z-index: 10;
font-size: 1.1em;
background-color: #ffffff;
padding: 4px 5px 4px 5px;
margin-top: 95px;
}
.mini_bloc_image > span:last-of-type {
display: block;
position: absolute;
z-index: 10;
color: #ffffff;
font-size: 1.1em;
font-family: 'Marck Script', cursive;
margin-left: 30%;
margin-top: 125px;
}
For more about inline elements and positioning, see this article.