An <a href> element surrounds two divs. One of the divs is only shown, if the link is active (moment of clicking). And it is placed above the other div. It is used as a feedback for clicking.
You can see and try this here: https://jsfiddle.net/pjgdtade/2/
a {
text-decoration: none;
display: flex;
position: relative;
width: 328px;
}
div.tile {
position: relative;
padding: 12px 10px;
box-sizing: border-box;
background-color: white;
color: black;
display: block;
width: 328px;
margin: 0;
box-shadow: 1px 2px 4px 0 #e0e0e0;
border: solid 1px #dcdcdc;
}
div.link-active-cover {
background: rgba(220, 220, 220, 0.6);
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
display: none;
}
a:active div.link-active-cover {
display: block;
}
<a href="https://www.google.de" target="_blank">
<div class="tile">
This is some content in a clickable box.
</div>
<div class="link-active-cover"></div>
</a>
In Chrome everything works as expected, but in Firefox the link is not executed. On click the div.link-active-cover shows up, but the new page does not open.
Funny fact: If div.link-active-cover is visible from the beginning (no display: none), the div is shown and the link works.
Am I wrong with this or is it a bug in Firefox?
Probably because when click event occurs (after mouseup), the mouse is not on primary clicked element.
No matter, the solution would be to use opacity change:
a {
text-decoration: none;
display: flex;
position: relative;
width: 328px;
}
div.tile {
position: relative;
padding: 12px 10px;
box-sizing: border-box;
background-color: white;
color: black;
display: block;
width: 328px;
margin: 0;
box-shadow: 1px 2px 4px 0 #e0e0e0;
border: solid 1px #dcdcdc;
}
div.link-active-cover {
background: rgba(220, 220, 220, 0.6);
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: .001;
}
a:active div.link-active-cover {
opacity: 1;
}
<a href="https://www.google.de" target="_blank">
<div class="tile">
This is some content in a clickable box.
</div>
<div class="link-active-cover"></div>
</a>
Updated Fiddle.
Related
I understand that my parent-child relationship is what is hindering my z-index from working properly. But of the solutions I have seen, I am not able to fix without losing the hierarchy needed for my future development (The active class functionality, which is not yet implemented).
Background Info:
I'm making a tabs component, and my goal is mirror this design (note the slanted tab ends):
Here's what I was able to do:
The only issue with this is that this code is using float: right; for the li elements instead of what I want float: left;.
So because of that my tabs are ordered 4-1 instead of the proper order of 1-4.
When I do use float: left;, this issue comes up where my divs for the slanted tab ends are hidden behind the li elements:
Only the last tab's slanted div is left visible, as it is the only one not blocked.
Here's the Code:
ul.tabs {
margin: 0px;
// overflow: hidden;
clip-path: inset(0 -100vw 0 0);
display: inline-block;
}
ul.tabs>li.active {
// z-index: 2;
float: left; // text-align:right;
padding-right: 40px;
padding-top: 6px;
padding-left: 40px;
height: 56px;
background: lightblue;
box-shadow: 0 10px 20px rgba(0, 0, 0, .5);
max-width: 222px;
position: relative;
z-index: 1;
box-sizing: border-box;
border: 1px solid #10172E;
}
.tab-slice.active:after {
content: '';
position: relative;
width: 10%; //40px
height: 100%;
top: 36px;
right: 1px;
border-right: 18px solid transparent;
border-bottom: 54.5px solid lightblue;
z-index: 3;
}
ul.tabs>li {
float: left;
padding-right: 40px;
padding-top: 6px;
padding-left: 40px;
height: 56px;
background: darkblue;
box-shadow: 0 10px 20px rgba(0, 0, 0, .5);
max-width: 222px;
position: relative;
z-index: 1;
box-sizing: border-box;
border: 1px solid #10172E;
}
ul.tabs>li>a {
display: inline-block;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
text-decoration: none;
color: $alis-white;
}
.tab-slice {
content: '';
position: absolute; //relative;
width: .5%;
height: 100%;
bottom: -1px;
right: -20px;
border-right: 18px solid transparent;
border-bottom: 56px solid #10172E;
z-index: 4;
}
.tab-slice:after {
content: '';
position: relative;
width: 10%; //40px
height: 100%;
top: 36px;
right: 1px;
border-right: 18px solid transparent;
border-bottom: 54.5px solid darkblue;
z-index: 4;
}
<div class="breadcrumb-container">
<div class="flight-search "><a (click)="openSearch"><mat-icon>search</mat-icon></a></div>
<ul class="tabs">
<li>
Tab 1
<div class="tab-slice "></div>
</li>
<li class="active">
Tab 2
<div class="tab-slice active"></div>
</li>
<li>
Tab 3
<div class="tab-slice"></div>
</li>
<li>
Tab 4
<div class="tab-slice"></div>
</li>
</ul>
</div>
The second to last option proposed in that article, almost works. but winds up looking like this:
I did this by commenting out the position attribute.
ul.tabs>li {
// position: relative;
}
How do I fix this layering issue?
This is the best I can fix it, the core solution is to reverse the elements when you add them in html. Then you can use the flex property flex-direction: row-reverse; so that the pseudo elements always come on the top!
Was not able to find a solution for the border thing for the pseudo element!
ul.tabs {
margin: 0px;
clip-path: inset(0 -100vw 0 0);
display: inline-flex;
flex-direction: row-reverse;
list-style: none;
align-items: center;
justify-content: center;
}
ul.tabs>li.active {
// z-index: 2;
float: left; // text-align:right;
padding-right: 40px;
padding-top: 6px;
padding-left: 40px;
height: 56px;
background: lightblue;
box-shadow: 0 10px 20px rgba(0, 0, 0, .5);
max-width: 222px;
position: relative;
z-index: 1;
box-sizing: border-box;
}
ul.tabs>li {
padding-right: 40px;
padding-top: 6px;
padding-left: 40px;
height: 56px;
background: darkblue;
box-shadow: 0 10px 20px rgba(0, 0, 0, .5);
max-width: 222px;
position: relative;
z-index: 1;
box-sizing: border-box;
border: 1px solid #10172E;
border-right:1px;
display:flex;
align-items: center;
justify-content: center;
}
ul.tabs>li>a {
display: inline-block;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
text-decoration: none;
color: $alis-white;
}
ul.tabs>li:after {
content: '';
position: absolute;
width: 10%;
height: 0;
top: 0px;
left: calc(100% - 1px);
border-right: 18px solid transparent;
border-bottom: 56px solid darkblue;
}
li.active:after {
border-right: 18px solid transparent !important;
border-bottom: 56px solid lightblue !important;
}
<div class="breadcrumb-container">
<div class="flight-search ">
<a (click)="openSearch">
<mat-icon>search</mat-icon>
</a>
</div>
<ul class="tabs">
<li>
Tab 4
</li>
<li>
Tab 3
</li>
<li class="active">
Tab 2
</li>
<li>
Tab 1
</li>
</ul>
</div>
I have a card that needs to be covered by link and have text at the bottom corner. Currently text is located at the top, how can I move it to the bottom while keeping link covering card?
.card{
background-color: #fff;
border-radius: 4px;
box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
width: 200px;
height: 250px;
padding: 10px;
position: relative;
}
.card a {
color: red;
text-decoration: none;
padding: 10px;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
.card a:hover {
cursor: pointer;
text-decoration: underline;
}
<div class='card'>
<p>Some description goes here</p>
<a href='#'>Read more</a>
</div>
It is usually called stretched link (for example in Bootstrap) and it uses pseudo (before/after) elements which are absolute while the original element can be somewhere else.
To place link at the bottom of the card (without using absolute position) I've set flex to .card and margin-top: auto to a.
Something like this:
.card {
display: flex;
flex-flow: column;
background-color: #fff;
border-radius: 4px;
box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
width: 200px;
height: 250px;
padding: 10px;
position: relative;
}
.card a {
color: red;
text-decoration: none;
margin-top: auto;
}
/* ↓↓ this is it ↓↓ */
.card a:after {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1;
content: "";
}
.card a:hover {
cursor: pointer;
text-decoration: underline;
}
<div class='card'>
<p>Some description goes here</p>
<a href='#'>Read more</a>
</div>
I have a CSS layout, with a tooltip. I have links on the page, and when visitor hover over the links, images appear in tooltips. SOmetimes there is only one image in the tooltip, sometimes two images, and even three.
My code looks like:https://jsfiddle.net/vehpw5zn/ (I suggest viewing on jsfiddle, as the builtin code snippet dispays the tooltip only when scrolling with the mouse.)
body {
margin: 64px 10px;
}
table.thumbnails {
border-spacing: 0px;
border-collapse: collapse;
}
table.thumbnails td {
padding: 0px;
margin: 0px;
text-align: left;
}
.tooltiptext img {
border: 1px solid black;
display: inline-block;
padding: 0px;
margin: 0px;
float: left;
}
.tooltip {
position: relative;
display: inline-block;
text-decoration: none;
}
.tooltip .tooltiptext {
display: none;
background-color: rgba(76, 175, 80, 0.5);
color: #fff;
text-align: center;
padding: 10px;
border-radius: 6px;
font-family: 'Courier';
font-size: 12px;
position: absolute;
z-index: 1;
bottom: -300px;
left: 100%;
margin-left: 10px;
}
/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
display: table;
}
/**to display a small triangle*/
.tooltip .tooltiptext::before {
content: "";
position: absolute;
top: 55px;
left: -5px;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent rgba(76, 175, 80, 0.5) transparent transparent;
}
<a href="#" class="tooltip">
<div class=tooltiptext>
<table class="thumbnails">
<tr>
<td><img src="https://i.imgur.com/NdLpRzU.png" loading="lazy"></td>
<td><img src="https://i.imgur.com/UmyTAgY.png" loading="lazy"></td>
</tr>
</table>
</div>
Link text
</a>
It basically works, but I have a small gap between the two images.
My other problem, is that when I try to display a small captcha image in the tooltip on top of the content, in a different z-index layer, then the height of the small captcha image appears in the previous layer div, and the green part of the div becomes larger. I get a larger margin below the two brown images, which is transparent green. How can I avoid that?
My code for this second phase: https://jsfiddle.net/vehpw5zn/1/
body {
margin: 64px 10px;
}
table.thumbnails {
border-spacing: 0px;
border-collapse: collapse;
}
table.thumbnails td {
padding: 0px;
margin: 0px;
text-align: left;
}
.tooltiptext img {
border: 1px solid black;
display: inline-block;
padding: 0px;
margin: 0px;
float: left;
}
.tooltip {
position: relative;
display: inline-block;
text-decoration: none;
}
.tooltip .tooltiptext {
display: none;
background-color: rgba(76, 175, 80, 0.5);
color: #fff;
text-align: center;
padding: 10px;
border-radius: 6px;
font-family: 'Courier';
font-size: 12px;
position: absolute;
z-index: 1;
bottom: -300px;
left: 100%;
margin-left: 10px;
}
/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
display: table;
}
/**to display a small triangle*/
.tooltip .tooltiptext::before {
content: "";
position: absolute;
top: 55px;
left: -5px;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent rgba(76, 175, 80, 0.5) transparent transparent;
}
img.captcha {
display:none;
border:1px solid black;
position: relative;
top:-46px;
left:4px;
z-index:3;
}
.tooltip:hover img.captcha {
display: block;
}
<a href="#" class="tooltip">
<div class=tooltiptext>
<table class="thumbnails">
<tr>
<td><img src="https://i.imgur.com/NdLpRzU.png" loading="lazy"></td>
<td><img src="https://i.imgur.com/UmyTAgY.png" loading="lazy"></td>
</tr>
</table>
<img class="captcha" src="data:image/gif;base64,R0lGODlhlgAoAPABAAAAAP///yH5BAAAAAAAIf8LSW1hZ2VNYWdpY2sOZ2FtbWE9MC40NTQ1NDUALAAAAACWACgAAAL+jI+py+0Po5y02ouz3rz7D4biSJbmiabqyrbuC8fyTCPAXefVDXy8DpT8OsMgDxe0ITlLXbGY9PWMzQA0imVOE9esd1c1dLXH8sO8QdfG4/RW3OaGMXFXe55W1JVvzZ51h5fR93dQGHHoFhfYJ5KYeCbo8TR3tABpAYnZsElxhWfJ1wiiKelp6qYHWobTKYQqN3rh+qoqa4VGG3nLCYvoOxuGCZxJDMd7iuzHqvarTCcMoctXMn1M0qVsfY1tzLBteynt/U3++mx4ab7biAoOXu6p3s38Z81MP1G1jgLff4jPi79/Ab84M2iLX5KBCI0YQtcwIpeHEivqC2Uxo8YJjRw7evwI0kIBADs=">
</div>
Link text
</a>
For your second issue, need to modify the position of the captcha image. The position property changed from relative to absolute, then align with bottom property instead of top property. left property changed from 4px to 15px. The value of bottom property and top property can be changed according to your need.
img.captcha {
display: none;
border: 1px solid black;
position: absolute; /* Change from relative to absolute */
bottom: 15px; /* Change from top:-46px; */
left: 15px; /* Change from 4px */
z-index: 3;
}
body {
margin: 64px 10px;
}
table.thumbnails {
border-spacing: 0px;
border-collapse: collapse;
}
table.thumbnails td {
padding: 0px;
margin: 0px;
text-align: left;
}
.tooltiptext img {
border: 1px solid black;
display: inline-block;
padding: 0px;
margin: 0px;
float: left;
}
.tooltip {
position: relative;
display: inline-block;
text-decoration: none;
}
.tooltip .tooltiptext {
display: none;
background-color: rgba(76, 175, 80, 0.5);
color: #fff;
text-align: center;
padding: 10px;
border-radius: 6px;
font-family: 'Courier';
font-size: 12px;
position: absolute;
z-index: 1;
bottom: -300px;
left: 100%;
margin-left: 10px;
}
/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
display: table;
}
/**to display a small triangle*/
.tooltip .tooltiptext::before {
content: "";
position: absolute;
top: 55px;
left: -5px;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent rgba(76, 175, 80, 0.5) transparent transparent;
}
img.captcha {
display: none;
border: 1px solid black;
position: absolute; /* Change from relative to absolute */
bottom: 15px; /* Change from top:-46px; */
left: 15px; /* Change from 4px */
z-index: 3;
}
.tooltip:hover img.captcha {
display: block;
}
<a href="#" class="tooltip">
<div class=tooltiptext>
<table class="thumbnails">
<tr>
<td><img src="https://i.imgur.com/NdLpRzU.png" loading="lazy"></td>
<td><img src="https://i.imgur.com/UmyTAgY.png" loading="lazy"></td>
</tr>
</table>
<img class="captcha" src="data:image/gif;base64,R0lGODlhlgAoAPABAAAAAP///yH5BAAAAAAAIf8LSW1hZ2VNYWdpY2sOZ2FtbWE9MC40NTQ1NDUALAAAAACWACgAAAL+jI+py+0Po5y02ouz3rz7D4biSJbmiabqyrbuC8fyTCPAXefVDXy8DpT8OsMgDxe0ITlLXbGY9PWMzQA0imVOE9esd1c1dLXH8sO8QdfG4/RW3OaGMXFXe55W1JVvzZ51h5fR93dQGHHoFhfYJ5KYeCbo8TR3tABpAYnZsElxhWfJ1wiiKelp6qYHWobTKYQqN3rh+qoqa4VGG3nLCYvoOxuGCZxJDMd7iuzHqvarTCcMoctXMn1M0qVsfY1tzLBteynt/U3++mx4ab7biAoOXu6p3s38Z81MP1G1jgLff4jPi79/Ab84M2iLX5KBCI0YQtcwIpeHEivqC2Uxo8YJjRw7evwI0kIBADs=">
</div>
Link text
</a>
I was studying how to make static navigation bars and managed to get up to this
https://jsfiddle.net/dm310tau/
.bottom-bar
{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
position: fixed;
z-index: 100;
bottom: 10px;
left: 0;
width: 100%;
height: 35px;
color: #999999;
background-color: #101010;
}
.bottom-bar li
{
float: left;
}
.bottom-bar a
{
display: block;
color: #999999;
text-align: center;
font-size: medium;
padding: 6px 16px;
text-decoration: none;
border: 1px solid transparent;
}
.bottom-bar a:hover:not(.active)
{
color: #EFEFEF;
border: 1px solid #AAAAAA;
}
.bottom-bar .active
{
color: #FEFEFE;
background-color: #303030;
padding: 3px 16px 8px 16px;
border: 1px solid #EEEEEE;
}
.bottom-bar .active:after
{
}
<ul class = "bottom-bar">
<li class = "bottom-link">
<a class = "active"
href = "/one">
One
</a>
</li>
<li class = "bottom-link">
<a href = "/two">
Two
</a>
</li>
<li class = "bottom-link">
<a href = "/three">
Three
</a>
</li>
</ul>
As the next step I was trying to make it so that active bar ends up a little bit taller like so,
However, I am not sure where is the first place to look for something like this. I have explored option of using
.bottom-bar .active:after, but, unfortunately, because the bar is supposed to be static, I can not make the part pop up a little bit higher by using a border like I have seen it done on other websites.
I do understand that I can do a few of these using Bootstrap, but that is not my intention. I would like to learn CSS instead of just using what's there and not understanding what is going on behind the scenes.
This works in Chrome at least. The comments explain what is happening.
<!DOCTYPE HTML>
<html>
<head>
<style>
#footer {
width: 100%;
height: 35px;
background-color: black;
position: fixed;
left: 0;
bottom: 0;
padding: 5px 0 0 20px; //top right bottom left
}
.link {
color: gray;
margin-right: 10px;
padding: 5px;
float: left;
position: relative;
}
.active {
color: white;
height: 50px;
border-bottom: none;
border-radius: 5px 5px 0 0;
}
.active:after { /*or :before*/
content: ""; /*allows shape to display*/
display: block;
width: 100%; /*cover element*/
top: -20px; /*position as you would like, just to show the difference*/
left: 0;
position: absolute;
height: 60px;
border: 1px solid white;
border-radius: 5px;
background-color: black;
z-index: -1; /*place behind element*/
}
</style>
</head>
<body>
<div id="footer">
<div id="links">
<div class="link active">Contact</div>
<div class="link">About</div>
<div class="link">Support me!</div>
</div>
</div>
</body>
</html>
According to a trick found in Stack overflow, I can change the background of the parent element hovering a child like this:
parent sibling { }
parent sibling:hover { }
parent:hover sibling { }
But I need to change the background color hovering different child elements. For example, hovering the Facebook button, the background goes blue, while hovering the Google + button, the backgroud goes red.
I've tried this:
<div class="share_box">
<div class="white-container">
<div class="facebook-sibling"/>
<a class="facebook-child-button"/>
<div class="twitter-sibling"/>
<a class="twitter-child-button"/>
<div class="googleplus-sibling"/>
<a class="googleplus-child-button"/>
</div>
</div>
but for multiple buttons it didn't work. The result I expect is similar to:
If you set the parent position: relative, it will contain any position: absolute children.
Create a new element inside the end of the parent, then make it position: absolute and position and size it so that it fills the parent.
Then use z-index: -1 to set it behind the rest of the content (e.g. the buttons).
Then you can use the General Sibling Combinator (~) to select the new element after the hovered element.
.facebook:hover ~ .background { background-color: rgb(50, 100, 150); }
.twitter:hover ~ .background { background-color: rgb(50, 150, 250); }
.google:hover ~ .background { background-color: rgb(250, 75, 50); }
.share {
position: relative;
}
.background {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: -1;
} /* Following styling for demo purposes only, not relevant */ .facebook:before { background-position:-46px -28px; width:101px; } .twitter:before { background-position:-151px -28px; width:90px; } .google:before { background-position:-245px -28px; width:94px; } .button:before { display:inline-block; content: ""; height:36px; background-image:url("http://i.stack.imgur.com/AXvMk.png"); border-radius: 3px; box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.2); } .button { display:inline-block; padding: 2px; } .white-container { padding: 10px 20px; font-size: 0; background: #fff; border-radius: 3px; } .background { background: #fff; } body { margin: 0 4px; border: 1px solid #aaa; border-top: 0px; box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.1) } .share { padding: 10px 15px; box-shadow: 0px 5px 5px -5px rgba(0,0,0,0.3) inset } body:before { content: ''; height: 4px; display: block; background: #fff; border-bottom: 1px solid #aaa } html { background: #efefef }
<div class="share">
<div class="white-container">
<div class="background"></div>
</div>
</div>
Is this what you want?
DEMO 1: http://jsfiddle.net/t73431y8/
DEMO 2: http://jsfiddle.net/t73431y8/2/
HTML:
<div class="PARENT">
<div class="RED">RED</div>
<div class="BLUE">BLUE</div>
<div class="GREEN">GREEN</div>
</div>
CSS:
.PARENT{
position: relative;
}
.RED{
display: inline-block;
margin: 5px;
padding: 5px;
color: #BB0000;
background: #FFF;
}
.RED:hover:after{
display: block;
width: 100%;
height: 100%;
background: #BB0000;
position: absolute;
top: 0px;
left: 0px;
content: ' ';
z-index: -1;
}
.BLUE{
display: inline-block;
margin: 5px;
padding: 5px;
color: #0000BB;
background: #FFF;
}
.BLUE:hover:after{
display: block;
width: 100%;
height: 100%;
background: #0000BB;
position: absolute;
top: 0px;
left: 0px;
content: ' ';
z-index: -1;
}
.GREEN{
display: inline-block;
margin: 5px;
padding: 5px;
color: #00BB00;
background: #FFF;
}
.GREEN:hover:after{
display: block;
width: 100%;
height: 100%;
background: #00BB00;
position: absolute;
top: 0px;
left: 0px;
content: ' ';
z-index: -1;
}