Skip to content

Commit

Permalink
Add tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
tygern committed Nov 24, 2023
1 parent 8572745 commit 98d5f44
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
@import "tables.css";
@import "modals.css";
@import "dropdowns.css";
@import "tooltips.css";
36 changes: 36 additions & 0 deletions css/tooltips.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[data-tooltip] {
--caret-height: .4rem;

color: var(--text-color);
cursor: pointer;
text-decoration: underline;
position: relative;
}

[data-tooltip]:hover:before, [data-tooltip]:focus-within:before {
content: attr(data-tooltip);
position: absolute;
bottom: calc(100% + var(--caret-height));

padding: .33rem .5rem;
border-radius: var(--border-radius);
background-color: var(--inverted-background-color);
width: max-content;
max-width: 15rem;

color: var(--inverted-text-color);
font-size: .8rem;
line-height: 1.5;
}


[data-tooltip]:hover:after, [data-tooltip]:focus-within:after {
content: '';
position: absolute;
bottom: 100%;
left: 1rem;

border-left: var(--caret-height) solid transparent;
border-right: var(--caret-height) solid transparent;
border-top: var(--caret-height) solid var(--inverted-background-color);
}
3 changes: 3 additions & 0 deletions images/tooltip.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 22 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ <h2>Sections</h2>
Modals
</a>
</li>
<li>
<a href="#tooltips">
<svg>
<use xlink:href="images/tooltip.svg#icon"></use>
</svg>
Tooltips
</a>
</li>
</ul>

<h2>Profile</h2>
Expand Down Expand Up @@ -123,7 +131,7 @@ <h1>CSS Starter</h1>
</section>

<section id="typography">
<h2>Typography</h2>
<h1>Typography</h1>

<h1>Heading 1</h1>
<h2>Heading 2</h2>
Expand Down Expand Up @@ -285,6 +293,19 @@ <h2>Warning</h2>
</dialog>
<p>Click <a href="javascript:document.querySelector('dialog').showModal()">here</a> to open the modal</p>
</section>
<section id="tooltips">
<h1>Tooltips</h1>

<p>
<a href="javascript:{}" data-tooltip="Here is some additional info">Hover over me</a> to see a tooltip.
</p>

<p>
<a href="javascript:{}" data-tooltip="Here is some additional info. What do you think of it? I'd say it's very nice.">
Hover over me
</a> to see a tooltip with a ton of text.
</p>
</section>
</main>
<footer>
<ul>
Expand Down

0 comments on commit 98d5f44

Please sign in to comment.