CSS position icon at top right of div, goes behind div - html

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.

Related

the color background is not applied to the block (html & css)

There are several answers on StackOverflow, but the code structure of each is too different to directly understand.
My question is to know why the blue background does not take all the block? I still have white spaces.
my example
dashboard.html
<nav>
<div class="sidebar-button">
<div class="menu-container">
<i class="bx bx-menu sidebarBtn"></i>
<span class="dashboard">Dashboard</span>
</div>
<div class="menu-summary-container">
<span class="user">Utilisateur : Toto </span>
</div>
</div>
</nav>
style.css
.home-section nav .sidebar-button {
display: flex;
align-items: center;
font-size: 24px;
font-weight: 500;
width: 100%;
background-color: #0a2558;
color: #fff;
}
.menu-container {
display: flex;
align-items: center;
}
.menu-container i {
font-size: 35px;
margin-right: 10px;
}
.menu-summary-container {
display: grid;
margin: auto;
text-align: center;
}
The code is available also on this following link.
I do not see what is missing?
Assuming I've understood your question, you've applied the background-color to the .homesection nav .sidebar-button rather than .home-section nav.
I've adjusted your styles.css as below:
.home-section nav {
display: flex;
justify-content: space-between;
height: 80px;
background: #fff;
align-items: center;
position: fixed;
width: calc(100% - 330px);
left: 330px;
z-index: 100;
background-color: #0a2558;
padding: 0px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
transition: all 0.5s ease;
}
Great first question by the way! Very well structured and the stackblitz is very useful!
The source of the problem is the align-items: center; and padding: 0 20px; styles defined in the .home-section nav section. The issue is resolved when the specified styles are removed.
The problem is that you are applying the color to a element that is inside the nav, not the whole nav. The element inside the nav is not taking up all the space. You can either change the color of the nav itself:
nav{
background: blue;
}
Or make the child fill up all the space in the nav:
.child{
height: 100%;
width: 100%;
}

CSS how to keep span element fixed in progresbar

I am using the following CSS to display a progresbar and in it I display the time that is left. For some reason no matter what I try the displayed time wont stay at its place and is moving left as the proress bar width is decreasing. I have tried a lot of ways to keep the text from moving and keep it centered but none seems to work. Please help !
CSS:
.progress {
background: rgba(255,255,255,0.1);
justify-content: flex-start;
border-radius: 100px;
align-items: center;
position: relative;
padding: 0 5px;
display: flex;
height: 20px;
width: 300px;
}
.progress-value {
box-shadow: 0 10px 40px -10px #fff;
border-radius: 100px;
background: red;
height: 15px;
}
The div ( the div with the ID timer needs to be in the middle of the progres bar and it should not move while the progres bar is degreasing !)
<div class="progress">
<div id='progress' class="progress-value"><span id='timer' style="display: inline; width: 300px !important;"></span></div></center></div></center>
I solved this by wrapping the progress bar and the time element in another div, position relative, then I can absolutely position the time element in any position; in this case I centered it in the div.
The time stays put because it's out of the flow of the document but it's div takes up the same space as the progress bar.
.progress {
background: rgba(5,5,5,0.5);
justify-content: flex-start;
border-radius: 100px;
align-items: center;
padding: 0 5px;
display: flex;
height: 20px;
width: 100%;
}
.progress-value {
box-shadow: 0 10px 40px -10px #fff;
border-radius: 100px;
background: red;
height: 15px;
width: 35%;
}
.progress-and-timer {
position: relative;
}
.timer-value {
position: absolute;
text-align: center;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
height: 20px;
color: white;
font-family: Arial, sans-serif;
font-size: 14px;
line-height: 20px;
}
<div class="progress-and-timer">
<div id="timer" class="timer-value">time</div>
<div class="progress">
<div id="progress" class="progress-value">
</div>
</div>
</div>

Any way for leader dots to extend from inside the text?

I think it's best to explain with the image above, is there a way to make the dots extend all the way to the volume? Whatever I try the text on the left is inside a block with a set width so the dots are contained inside of it and I can't use a white background to only cover the text area.
Codepen
.two-line-menu-item {
width: 100%;
text-align: left;
}
.two-line-menu-item__title {
color: #4ca099;
}
.two-line-menu-item-info {
display: flex;
justify-content: space-between;
align-items: flex-end;
}
.two-line-menu-item-info__type-vol {
max-width: 70%;
padding-right: 0.33rem;
background-color: white;
}
.two-line-menu-item-info__price {
padding-left: 0.33rem;
background-color: white;
}
.dots {
position: relative;
z-index: -1;
top: -9px;
height: 3px;
border-top: 3px dotted;
}
<div class="two-line-menu-item">
<div class="title-text two-line-menu-item__title">Cappy Juices</div>
<div class="two-line-menu-item-info">
<span class="two-line-menu-item-info__type-vol">orange, apple, apricot, peach, black currant, smoothie 0.2 l</span>
<span class="two-line-menu-item-info__price">16 kn</span>
</div>
<div class="dots"></div>
</div>

overflow-x scroll ignoring margin / padding right

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!

Show text on hovering a div under a flex-container

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;
}