I have to create an icon navigation bar with webfont-icons on the top of the page, that is tiled 3 Sections:
upper-left: Icons are aligning on the left side
middle-center: Icons are aligning in the middle of the site
upper right: Icons are aligning on the right side
This part i got to work. With the following HTML ...
<div id="topNavigation">
<div id="topNavigationLeft">
<div class="iconButton makeAnIcon" data-icon="🙈"><span class="tooltiptext">The funky monkey</span></div>
<div class="iconButton makeAnIcon" data-icon="😎"><span class="tooltiptext">The cool smiley</span></div>
</div>
<div id="topNavigationMiddle">
<div class="iconButton makeAnIcon" data-icon="🚹"><span class="tooltiptext">Man rest room</span></div>
<div class="iconButton makeAnIcon" data-icon="🚺"><span class="tooltiptext">Woman rest room</span></div>
<div class="iconButton makeAnIcon" data-icon="🚾"><span class="tooltiptext">Water Closet</span></div>
</div>
<div id="topNavigationRight">
<div class="iconButton makeAnIcon" data-icon="🚻"><span class="tooltiptext">Mixed up rest room</span></div>
<div class="iconButton makeAnIcon" data-icon="🚼"><span class="tooltiptext">Baby room</span></div>
<div class="iconButton makeAnIcon" data-icon="🚽"><span class="tooltiptext">Toilet</span></div>
</div>
</div>
This is the CSS i had used:
.iconButton {
float: left;
margin-left: 10px;
margin-right: 10px;
}
.iconButton:hover {
color: #ff0000;
}
.iconButton .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
/* Position the tooltip */
position: absolute;
z-index: 1;
}
.iconButton:hover .tooltiptext {
visibility: visible;
}
.makeAnIcon:before
{
font-family: 'Arial';
content: attr(data-icon);
font-size:60px;
}
#topNavigation {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-between;
align-items: center;
position: absolute;
width: 100%;
height: 80px;
top: 0px;
left: 0px;
margin: 0px;
padding: 0px;
border-bottom: 1px solid;
}
#topNavigationLeft {
display: flex;
justify-content: flex-start;
flex-wrap: nowrap;
height: 100%;
/* Debug Color */
/* background-color: rgba(255, 0, 0, 0.2); */
}
#topNavigationMiddle {
display: flex;
justify-content: center;
flex-wrap: nowrap;
height: 100%;
/* Debug Color */
/* background-color: #711e82; */
}
#topNavigationRight {
display: flex;
justify-content: flex-end;
flex-wrap: nowrap;
height: 100%;
/* Debug Color */
/* background-color: rgba(255, 0, 0, 0.2); */
}
See my fiddle: https://jsfiddle.net/schludi/yrgaf6p9/
Now i have to show a text UNDER the Icons on hover.
My problem is, that it is under the flex-container i have used and it should not affect further elements that will be added under the "topnavigation"-div.
When i am on the upper right side, the Text should appear left-aligned to the icon, that no scroll bars will be generated because the span element is too big. How can i do this?
First off, for ToolTips i would highly recommend using a plugin. You'll run into issues where the tooltip goes off the screen (either x or y) and you can't detect that at all with CSS.
However, lets answer your question.
So if you've got a div that's appearing underneath another element, there's one nice css property that will solve this for you! I see you've already used it. What you can do is add z-index to your element that you want on top. The higher the index, the higher the element will be visually.
.iconButton .tooltiptext {
display:none;
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
/* Position the tooltip */
position: absolute;
z-index: 9999; /* This is extreme, don't always default to 9999 */
}
Just make sure the z-index of the element you want on top is higher than the other elements. If it's still not on top, then the chances are the parent is lower than the other element that you want on top, so on your flex-container make sure that the z-index is lower than the parent of .tooltiptext
For your specific case, the following would keep the last tooltip within the bounds of the page. It's not very dynamic, though.
#topNavigationRight .iconButton:last-of-type .tooltiptext {
right: 0;
}
Related
I got a quick question. I want an icon at the top right of the div, and the bottom right. I think I am doing it well, but for some reason it goes behind the div.
Image of what happens, you can see the green and red icon not going above it, but behind
This is the code I wrote:
HTML:
<div v-if="showMenu" class="wrapper">
<!-- Begin karakters onderaan -->
<div v-if="karakters" class="karakters-wrapper">
<span v-for="karakter in karakters" :key="karakter">
<div v-if="karakter !== undefined" class="karakter-box">
<p>{{karakter.charinfo.firstname}} {{karakter.charinfo.lastname}}</p>
<i class="fas fa-play-circle icoon-speel"></i>
<i class="fas fa-trash icoon-verwijder"></i>
</div>
<div v-else class="karakter-box">
<p>Leeg karakter slot</p>
</div>
</span>
</div>
<div v-else>
<h1 style="color:#fff;font-size:48px;">GEDULD!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!</h1>
</div>
<!-- Einde karakters onderaan -->
</div>
^^ Don't mind the v-if etc. that's from VueJS. Anyways, the div with class "karakter-box" is the div where I want an icon at the top right of.
CSS:
width: 100%;
height: 100%;
display: flex;
justify-content: flex-end;
align-items: center;
flex-direction: column;
}
.karakters-wrapper {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
padding: 10px;
}
/* Karakter boxjes */
.karakter-box {
position: relative;
display: flex;
justify-content: center;
align-items: center;
width: 300px;
height: 100px;
background-color: rgba(0, 0, 0, 0.7);
border-top: 8px solid var(--white);
padding: 5px;
margin: 5px;
color: var(--white);
transition: .25s ease-in-out;
}
.karakter-box:hover {
border-top: 8px solid var(--groen);
background-color: rgba(0, 0, 0, 0.9);
}
.icoon-speel {
position: absolute;
top: -10px;
right: -10px;
font-size: 2rem;
background-color: var(--groen);
color: var(--white);
padding: 10px;
border-radius: 100%;
}
.icoon-verwijder {
position: absolute;
bottom: -10px;
right: -10px;
font-size: 2rem;
background-color: var(--rood);
color: var(--white);
padding: 10px;
border-radius: 100%;
}```
I'm not sure why but it looks like there is an overflow: hidden karakter-box class.
even though i don't see it in the code sample you provided.
When i tested the code the sample this issue did not occur
Try Checking for css overflow on karakter-box
I suggest use another for the background and set its width to device width.
use this css code to get positions to right corners
Position: absolute;
and use this at css to get front of div
z-index:1;
index 1 is go front of styles and 2 3 4 going backward as ordered.
set the z-index of div to be -1
div{
z-index: -1;
}
and that of icons to be 1
i{
z-index: 1;
}
i will make the div behind your icons, so you can interact with your icons.
When hovering over a in html I want to display a text. Right now I have it this way:
echo "<td onmouseover='' style='cursor: pointer; background-color:#ffeb3b' title=$text id=$text></td>";
The problem is that it looks very small and without design.
How could I make it look bigger and with a little look?
I would like to do something similar to this in html.A box that appears on the right
For more information look here
body {
text-align: center;
}
.tooltip {
position: relative;
display: inline-block;
cursor: default;
}
.tooltip .tooltiptext {
visibility: hidden;
padding: 0.25em 0.5em;
background-color: black;
color: #fff;
text-align: center;
border-radius: 0.25em;
white-space: nowrap;
/* Position the tooltip */
position: absolute;
z-index: 1;
top: 100%;
left: 100%;
transition-property: visibility;
transition-delay: 0s;
}
.tooltip:hover .tooltiptext {
visibility: visible;
transition-delay: 0.3s;
}
<div class="tooltip">Hover over me
<span class="tooltiptext">Tooltip text</span>
</div>
This is how you can do it. First, create the main element, I'm using a text, and next to it add the text you wish to show on hover. Style everything according to your taste. Make sure you set the display of the extra text to none. Basically, we'll hide it and show it only when someone hovers over the main element.
Now, in the CSS, I've added .Main-Text:hover + .Extra-Text CSS Selector to achieve what we are trying to do. This basically means that when someone hovers on the element with class Main-Text, something will happen to the element with the class Extra-Text.
You can read about this more here.
* {
margin: 0px;
padding: 0px;
}
body {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20px;
min-height: 100vh;
}
.Main-Text:hover + .Extra-Text {
display: block;
}
.Extra-Text {
background-color: #FFFFFF;
margin-top: 10px;
width: 200px;
border: 2px solid #000000;
padding: 10px;
font-size: 16px;
display: none;
}
<html>
<div>
<p class="Main-Text">
Hover me to know more about me.
</p>
<div class="Extra-Text">
<p>
This is the extra information that will be displayed when the text is hovered.
</p>
</div>
</div>
</html>
I don't think so if this is something you are looking for but it's worth mentioning. You can use the title attribute in the HTML Elements to display some text when the user hovers over the element. Try it yourself. Run the snippet below and hover over the text.
* {
margin: 0px;
padding: 0px;
}
body {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20px;
min-height: 100vh;
}
<html>
<div>
<p class="Main-Text" title="This is some extra text">
Hover me to know more about me.
</p>
</div>
</html>
I'm trying to create a dropdown menu for one of the items in my nav bar. I based the code on this W3Schools example. Upon hover, the menu appears below the nav bar (as it should be) but it is 1) stacked horizontally rather than vertically and 2) appears to the far right on the page. I've look at similar questions here but haven't been able to figure out the problem in my code. Any help would be appreciated.
/* nav */
nav {
display: flex;
flex-wrap: wrap;
padding: .25rem 0;
color: #ffffff;
font: 30px 'Roboto', sans-serif;
margin: auto;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
overflow: hidden;
}
nav a {
display: block;
margin: 0 40px;
}
/* dropdown container */
.dropdown {
float: none;
position: relative;
overflow: visibile;
}
/* dropdown button */
.dropdown .dropbtn {
display: flex;
font-size: 30px;
border: none;
outline: none;
color: #ffffff;
padding: inherit;
background-color: inherit;
font-family: inherit;
margin: auto;
}
/* dropdown content (hidden by default */
.dropdown-content {
display: none;
position: absolute;
margin-top: 10px;
background-color: #ffffff;
width: 250px;
left: calc(50% - 125px);
}
.dropdown-content>a {
color: black;
text-align: left;
border-bottom: 1px solid #009EDB;
}
/* show dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
float: left;
margin: 0;
}
<nav class="justify-content-center">
About
<section class="dropdown">
<button class="dropbtn">
Work
</button>
<section class="dropdown-content">
Articles and Presentations
From Process to Flow Series
</section>
</section>
Github
Trailhead
</nav>
Your dropdown is structured of anchors (links, <a> tags), which naturally are inline elements. That means that naturally these elements are located as part of page or line flow. To make them appear vertical, you need to change them to be "block" elements, which you use by adding display: block to the styling on the dropdown a elements:
nav a {
margin: 0 40px;
display: block;
}
The 'margin' was already present in this particular element.
I've also removed all the "!important" from your styling because it's bad practice and wasn't helping at all. Since you're missing a background, I restyled the triggering element to have red text so it doesn't seem like a random white space was triggering the dropdown.
That being said, I don't see any "styled far right" behavior for the drop down. The menu is displayed directly under the triggering element (with a 40px margin, which if you have a really small screen might make it seem like it's super far right.)
/* nav */
nav {
display: flex;
flex-wrap: wrap;
padding: .25rem 0;
color: #ffffff;
font: 30px 'Roboto', sans-serif;
margin: auto;
justify-content: center;
overflow: hidden;
}
nav a {
margin: 0 40px;
display: block;
}
/* dropdown container */
.dropdown {
float: none;
overflow: hidden;
}
/* dropdown button */
.dropdown .dropbtn {
display: flex;
font-size: 30px;
border: none;
outline: none;
color: red;
padding: inherit;
background-color: inherit;
font-family: inherit;
margin: auto;
}
/* dropdown content (hidden by default */
.dropdown-content {
display: none;
position: absolute;
background-color: inherit;
width: 100%;
}
/* show dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
<nav class="justify-content-center">
About
<section class="dropdown">
<button class="dropbtn">Work</button>
<section class="dropdown-content">
Articles and Presentations
From Process to Flow Series
</section>
</section>
Github
Trailhead
</nav>
Problem number 1 was solved through Rody of the Frozen Peas answer.
For Problem number 2:
You want to align the center of dropdown-content relative to it's parent.
For that you want to shift dropdown-content to the left by half of it's width and then shift it a bit to the right by half of the width of the dropdown. Also the dropdown element needs to be relatively positioned otherwise the dropdown-content would be positioned realtive to the document. To make the dropdown-content visible you need to make dropdowns and the nav bars overflow visible.
nav {
overflow: visible;
}
.dropdown {
position: relative;
overflow: visible;
}
.dropdown-content {
position: absolute;
width: 250px;
left: calc(50% - 125px);
}
The reason this works is that you align the center of the dropdown-content with the left of dropdown by specifying left: -125px as you're shifting it to the left by half of the width of dropdown-content. To then align it with the center of dropdown you need to add 50% as it is absolutely positioned and will therefore use the parents width as reference and 50% of the parents width is the parents center.
Why I don't accept the padding solution of CSS overflow: hidden cuts shadow question is the paddings are the geometry and the box-shadow is the decoration; the decoration must not force the changing of geometry.
The conflict situation example
Suppose we have two themes for button component: with shadows and without shadows. To adapt the second theme with paddings, we need:
To interfere the geometry settings
To know the size of shadows.
And also: what if we place the element with different shadows in one container? We need to know the each shadow size?
About Z-Index solution
Generally, it does not work. There are the unknown for me conditions when it works so if you suggest this solution I ask you to clarify the conditions when it works.
The example which you can use is solution
The .Modal-MainSection element has overflow-y: scroll; settings for the cases when modal content is too large. Because of this, the shadow of buttons has been truncated:
<div class="Layout">
<div class="Modal">
<div class="Modal-TitleSection">
<div class="Modal-DummyTitle"></div>
</div>
<div class="Modal-MainSection">
<div class="Modal-DummyContent"></div>
<div class="Modal-ButtonsBar">
<button class="Button">Cancel</button>
<button class="Button">OK</button>
</div>
</div>
</div>
</div>
html {
height: 100%;
}
body {
height: 100%;
}
.Layout {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
background: #B2EBF2;
}
.Modal {
display: flex;
flex-direction: column;
width: 220px;
border-radius: 4px;
padding: 12px 14px;
overflow: hidden;
background: #42A5F5;
}
.Modal-TitleSection {
flex: 0 0 auto;
}
.Modal-DummyTitle {
width: 100px;
height: 20px;
background: #1976D2;
}
.Modal-MainSection {
flex: 1 1 auto;
overflow-x: hidden;
overflow-y: auto;
margin-top: 12px;
}
.Modal-DummyContent {
height: 140px;
background: #1976D2;
}
.Button {
border: none;
padding: 6px 8px;
box-shadow: 0 0 4px 4px #FFA726;
}
.Button + .Button {
margin-left: 12px;
}
.Modal-ButtonsBar {
margin-top: 12px;
display: flex;
justify-content: flex-end;
}
🌎 Fiddle
Also, assume that the buttons bar is the custom content. It means be does not know at advance when developing the modal component will be the buttons bar or no and which buttons will be.
I'm trying to make a carousel (run snippet below) that:
scrolls left to right
has equal amount of space on both sides of the inside of the carousel
makes it to where the first and last inner elements are centered when the scrollX value is all the way to the left or the right.
The issue I'm facing is that neither margin NOR padding is working on the right side of the carousel and is only displaying on the left.
To see the exactly what I'm talking about, run the snippet below, scroll all the way to the right, and compare to when the carousel is scrolled all the way to the left (Day 7 should be in the middle of the div at the end):
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
h1 {
text-align: center;
margin-top: 10px;
margin-bottom: 20px;
}
nav {
display: flex;
align-items: center;
justify-content: center;
}
.carousel-wrapper {
position: relative;
}
/* Arrows (ignore them, they don't work yet) */
.carousel-wrapper::before,
.carousel-wrapper::after {
content: "";
border-top: 2px solid black;
border-right: 2px solid black;
position: absolute;
height: 10px;
width: 10px;
top: calc(50% - 5px);
cursor: pointer;
}
.carousel-wrapper::before {
transform: rotate(-135deg);
left: -20px;
}
.carousel-wrapper::after {
transform: rotate(45deg);
right: -20px;
}
/* Where overflow hidden and overflow-x: scroll is */
.carousel {
border: 1px solid black;
background-color: #21abde;
overflow: hidden;
overflow-x: scroll;
width: 300px;
}
/* PROBLEM AREA (where the margin and padding should be but isn't working */
.links {
display: flex;
transform: skew(-15deg);
flex-shrink: 0;
margin: 0 100px;
margin-right: 100px;
}
/* Anchors */
a {
display: flex;
justify-content: center;
align-items: center;
color: white;
background-color: #21abde;
width: 100px;
height: 50px;
flex-shrink: 0;
text-decoration: none;
}
a span {
transform: skew(15deg);
}
a:hover {
background-color: #044c66;
}
<body>
<h1>Dates</h1>
<nav class="dates">
<div class="carousel-wrapper">
<div class="carousel">
<div class="links">
<span>Day 1</span>
<span>Day 2</span>
<span>Day 3</span>
<span>Day 4</span>
<span>Day 5</span>
<span>Day 6</span>
<span>Day 7</span>
</div><!-- Padding / margin should be showing up here -->
</div>
</div>
</nav>
<script src="app.js"></script>
</body>
Now that you've seen the code snippet...
2 questions:
Why is overflow hidden NOT accounting the padding on the right side of the links div
How do you make it show up?
Thanks guys!
Add this to you .items class:
width: max-content;
padding: 0 100px;
Remove the margin and margin-right!