I'd like to add a dropdown menu to a fixed toolbar, but the .toolbar-dropdown-menu element is not displayed as shown in the screenshot below (tested with Google Chrome 80.0):
My first impression was that the behavior of .toolbar-dropdown-menu is as if its parent was set to overflow: hidden: If I make the parent .toolbar-btn wider, the .toolbar-dropdown-menu is shown within the boundaries of its parent:
However, even if I explicitly set all elements to overflow: visible, the .toolbar-dropdown-menu remains invisible, even if its display is set to block and its visibility to visible.
Question: Why is the .toolbar-dropdown-menu element invisible and how do I get it to show up?
Here's a code snippet:
(This is a reduced version of the toolbar. It can usually be assigned to varying positions and expanded to show labels, but I excluded those features to minimize the code you have to go through)
.floating-toolbar {
position: fixed;
z-index: 1031;
background: #333;
color: rgba(255, 255, 255, 0.5);
}
.floating-toolbar.left {
left: 0;
}
.floating-toolbar.left .toolbar-btn .toolbar-icon {
right: 0.5rem;
}
.floating-toolbar.left .toolbar-dropdown > .toolbar-dropdown-menu {
position: absolute;
left: 21rem;
top: 0;
}
.floating-toolbar.left.minimized {
left: -18.5rem;
}
.floating-toolbar .toolbar-btn {
position: relative;
border-bottom: 1px solid rgba(255, 255, 255, .5);
padding: 0.5rem;
font-size: 1rem;
width: 20rem;
cursor: pointer;
}
.floating-toolbar .toolbar-btn:last-child {
border-bottom: none;
}
.floating-toolbar .toolbar-btn.active {
color: #fff;
}
.floating-toolbar .toolbar-btn .toolbar-icon {
position: absolute;
text-align: center;
width: 1.5rem;
top: 0.5rem;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
<div id="studio-toolbar" class="floating-toolbar top left minimized">
<div class="toolbar-btn maximize-button">
<div class="toolbar-label"> </div>
<div class="toolbar-icon"><i class="fas fa-bars"></i></div>
</div>
<div class="toolbar-btn active">
<div class="toolbar-label">Edit Text</div>
<div class="toolbar-icon"><i class="fas fa-font"></i></div>
</div>
<div class="toolbar-btn">
<div class="toolbar-label">Element Properties</div>
<div class="toolbar-icon"><i class="fas fa-edit"></i></div>
</div>
<div class="toolbar-btn toolbar-dropdown">
<div class="toolbar-label">Layout Structure</div>
<div class="toolbar-icon"><i class="fas fa-grip-horizontal"></i></div>
<div class="toolbar-dropdown-menu">
<div class="toolbar-btn">
<div class="toolbar-label">Column Offset</div>
<div class="toolbar-icon"><i class="fas fa-long-arrow-alt-right"></i></div>
</div>
<div class="toolbar-btn">
<div class="toolbar-label">Column Width</div>
<div class="toolbar-icon"><i class="fas fa-arrows-alt-h"></i></div>
</div>
<div class="toolbar-btn">
<div class="toolbar-label">Add Row</div>
<div class="toolbar-icon"><i class="fas fa-plus-square"></i></div>
</div>
</div>
</div>
</div>
In your code example I see dropdown. Just background-color is white so it is not visible.
.floating-toolbar {
position: fixed;
z-index: 1031;
background: #333;
color: rgba(255, 255, 255, 0.5);
}
.floating-toolbar.left {
left: 0;
}
.floating-toolbar.left .toolbar-btn .toolbar-icon {
right: 0.5rem;
}
.floating-toolbar.left .toolbar-dropdown > .toolbar-dropdown-menu {
position: absolute;
left: 21rem;
top: 0;
background-color: #333;
}
.floating-toolbar.left.minimized {
left: -18.5rem;
}
.floating-toolbar .toolbar-btn {
position: relative;
border-bottom: 1px solid rgba(255, 255, 255, .5);
padding: 0.5rem;
font-size: 1rem;
width: 20rem;
cursor: pointer;
}
.floating-toolbar .toolbar-btn:last-child {
border-bottom: none;
}
.floating-toolbar .toolbar-btn.active {
color: #fff;
}
.floating-toolbar .toolbar-btn .toolbar-icon {
position: absolute;
text-align: center;
width: 1.5rem;
top: 0.5rem;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
<div id="studio-toolbar" class="floating-toolbar top left minimized">
<div class="toolbar-btn maximize-button">
<div class="toolbar-label"> </div>
<div class="toolbar-icon"><i class="fas fa-bars"></i></div>
</div>
<div class="toolbar-btn active">
<div class="toolbar-label">Edit Text</div>
<div class="toolbar-icon"><i class="fas fa-font"></i></div>
</div>
<div class="toolbar-btn">
<div class="toolbar-label">Element Properties</div>
<div class="toolbar-icon"><i class="fas fa-edit"></i></div>
</div>
<div class="toolbar-btn toolbar-dropdown">
<div class="toolbar-label">Layout Structure</div>
<div class="toolbar-icon"><i class="fas fa-grip-horizontal"></i></div>
<div class="toolbar-dropdown-menu">
<div class="toolbar-btn">
<div class="toolbar-label">Column Offset</div>
<div class="toolbar-icon"><i class="fas fa-long-arrow-alt-right"></i></div>
</div>
<div class="toolbar-btn">
<div class="toolbar-label">Column Width</div>
<div class="toolbar-icon"><i class="fas fa-arrows-alt-h"></i></div>
</div>
<div class="toolbar-btn">
<div class="toolbar-label">Add Row</div>
<div class="toolbar-icon"><i class="fas fa-plus-square"></i></div>
</div>
</div>
</div>
</div>
Related
TL;DR: Cannot correctly position & display tooltips in a table due to overflow: hidden.
I have created a simple reproducible example of a table whose tooltips are not displaying as intended. The issue exists in part because the table requires overflow: scroll in order for the horizontal scroll of the table to work as intended. Here is an example:
.gap {
height: 50px
}
div.table {
max-width: 200px;
overflow: scroll;
border: 2px solid blue;
display: inline-block;
font-family: 'Roboto Mono';
font-weight: 700;
}
.tr {
display:flex;
}
.td, .th {
border: 1px solid black;
min-width: 60px;
height: 50px;
}
.th {
position: relative;
font-size: 13px;
padding: 2px;
background-color: #888888;
text-align: center;
border-right: 1px solid #555555;
display: inline-block;
box-sizing: border-box;
}
.tip-wrapper {
position: absolute;
}
.tip0 {
visibility: hidden;
position: absolute;
top: -60%;
z-index: 1;
max-width: 325px;
min-width: 160px;
color: #333333;
text-align: left;
background: white;
border: 1px solid black;
}
.tip1 {
visibility: hidden;
position: fixed;
z-index: 1;
max-width: 325px;
min-width: 160px;
color: #333333;
text-align: left;
background: white;
border: 1px solid black;
}
.tooltip:hover .tip0, .tooltip:hover .tip1 {
visibility: visible;
}
<div class='gap'>.</div>
<div class='table'>
<div class='table-headers'>
<div class='tr'>
<div class='th tooltip'>
Z
<div class='tip0'>
Heres the ToolTip For Column Z, getting cut off (bad)
</div>
</div>
<div class='th'>Y</div>
<div class='th tooltip'>
X
<div class='tip-wrapper'>
<div class='tip1'>
Heres the Tooltip For Column X, which doesn't stay at the top (bad)
</div>
</div>
</div>
<div class='th'>W</div>
<div class='th'>V</div>
</div>
</div>
<div class='table-body'>
<div class='tr'>
</div>
<div class='tr'>
<div class='td stick'>A</div>
<div class='td'>B</div>
<div class='td'>C</div>
<div class='td'>D</div>
<div class='td'>E</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
</div>
</div>
In the table above, the Z and X header cells have tooltips that appear on, however. However, there are issues with both of these tooltips currently:
Column Z: Because of overflow: hidden, this tooltip is getting cut off. It is important that the table can scroll horizontally, so I cannot remove this overflow CSS property. However, its also important that the tooltip hovers above the top of the table, so as to not block the content of the table.
Column X: I tried this approach from this other post. Method 1. This allows the tooltip outside of the overflow: hidden. However, when I scroll this table vertically, the tooltip moves as well, which is not good. The tooltip should remain at the same height always, just above the top of the table.
I was hoping that this basic "tooltips inside the table headers" would work, but it isn't so far. Because of this, I am considering creating a separate tooltip div outside of the table's HTML, and using onMouseOver() and onMouseOut() handler functions to position the tooltip at the mouse location, and populate the tooltip with text. Maybe that is my only approach?
You are missing a .tip-wrapper element on tip0, if you add this and set the top position of .tip-wrapper using calc() to -(th height) - (top threshold in rem) in this case calc(-50px - 1.5rem) then the problem is solved and you have the tooltip placed on top of the table.
You could use dynamic units in th height such as vh, vmax, %.
Additionally you would need some #media queries to fine-tune the position of the tooltip.
.td,
.th {
border: 1px solid black;
min-width: 10%;
height: 5vh;
}
.tip-wrapper {
position: absolute;
top: calc(-5vh - 1.5rem);
}
.gap {
height: 100px
}
div.table {
max-width: 200px;
overflow: scroll;
border: 2px solid blue;
display: inline-block;
font-family: 'Roboto Mono';
font-weight: 700;
}
.tr {
display: flex;
}
.td,
.th {
border: 1px solid black;
min-width: 60px;
height: 50px;
}
.th {
position: relative;
font-size: 13px;
padding: 2px;
background-color: #888888;
text-align: center;
border-right: 1px solid #555555;
display: inline-block;
box-sizing: border-box;
}
.tip-wrapper {
position: absolute;
top: calc(-50px - 1.5rem);
}
.tip0 {
visibility: hidden;
position: fixed;
z-index: 1;
max-width: 325px;
min-width: 160px;
color: #333333;
text-align: left;
background: white;
border: 1px solid black;
}
.tip1 {
visibility: hidden;
position: fixed;
z-index: 1;
max-width: 325px;
min-width: 160px;
color: #333333;
text-align: left;
background: white;
border: 1px solid black;
}
.tooltip:hover .tip0,
.tooltip:hover .tip1 {
visibility: visible;
}
<div class='gap'>Gap</div>
<div class='table'>
<div class='table-headers'>
<div class='tr'>
<div class='th tooltip'>
Z
<div class='tip-wrapper'>
<div class='tip0'>
Tip For Column Z is a long tip with enough text to overflow above the page top
</div>
</div>
</div>
<div class='th'>Y</div>
<div class='th tooltip'>
X
<div class='tip-wrapper'>
<div class='tip1'>
Tip For Column Z is a long tip with enough text to overflow above the page top
</div>
</div>
</div>
<div class='th'>W</div>
<div class='th'>V</div>
</div>
</div>
<div class='table-body'>
<div class='tr'>
</div>
<div class='tr'>
<div class='td stick'>A</div>
<div class='td'>B</div>
<div class='td'>C</div>
<div class='td'>D</div>
<div class='td'>E</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
</div>
</div>
Solution
You can mimic your table canvas with a sibling element, then use custom overflow properties on that child to achieve whatever effect you'd like:
document.addEventListener('DOMContentLoaded', _ => {
const tool = document.querySelector('.tooltip-canvas > tooltip')
const toolEls = Array.from(document.querySelectorAll('.table [tooltip]'))
toolEls.forEach(t => {
t.onmouseenter = _ => {
tool.setAttribute('tooltip', t.getAttribute('tooltip'))
tool.style.left = `${t.clientLeft}px`
tool.style.top = `${t.clientTop - 2}px`
}
t.onmouseleave = _ => tool.removeAttribute('tooltip')
})
})
.gap {
height: 50px
}
.table-wrap {
position: relative;
display: inline-block;
}
.table-wrap > .tooltip-canvas {
position: absolute;
pointer-events: none;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.table-wrap > .tooltip-canvas > tooltip {
content: attr(tooltip);
position: absolute;
z-index: 1;
max-width: 325px;
min-width: 160px;
color: #333333;
text-align: left;
background: white;
border: 1px solid black;
opacity: 0;
transform: translateY(-100%);
transition: opacity .25s;
}
.table-wrap > .tooltip-canvas > tooltip[tooltip] {
opacity: 1;
}
.table-wrap > .tooltip-canvas > tooltip:before {
content: attr(tooltip)
}
div.table {
max-width: 200px;
overflow: scroll;
border: 2px solid blue;
display: inline-block;
font-family: 'Roboto Mono';
font-weight: 700;
}
.tr {
display:flex;
}
.td, .th {
border: 1px solid black;
min-width: 60px;
height: 50px;
}
.th {
position: relative;
font-size: 13px;
padding: 2px;
background-color: #888888;
text-align: center;
border-right: 1px solid #555555;
display: inline-block;
box-sizing: border-box;
}
<div class='gap'>.</div>
<section class='table-wrap'>
<div class='table'>
<div class='table-headers'>
<div class='tr'>
<div class='th' tooltip='Heres the ToolTip For Column Z, getting cut off (bad)'>
Z
</div>
<div class='th'>Y</div>
<div class='th' tooltip='Heres the Tooltip For Column X, which doesn&spquot;t stay at the top (bad)'>
X
</div>
<div class='th'>W</div>
<div class='th'>V</div>
</div>
</div>
<div class='table-body'>
<div class='tr'>
</div>
<div class='tr'>
<div class='td stick'>A</div>
<div class='td'>B</div>
<div class='td'>C</div>
<div class='td'>D</div>
<div class='td'>E</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
</div>
</div>
<aside class='tooltip-canvas'>
<tooltip></tooltip>
</aside>
</section>
Just change the top value in tip0:
.tip0 {
visibility: hidden;
position: absolute;
top: 40%;
z-index: 1;
max-width: 325px;
min-width: 160px;
color: #333333;
text-align: left;
background: white;
border: 1px solid black;
}
.gap {
height: 100px
}
div.table {
max-width: 200px;
overflow: scroll;
border: 2px solid blue;
display: inline-block;
font-family: 'Roboto Mono';
font-weight: 700;
}
.tr {
display:flex;
}
.td, .th {
border: 1px solid black;
min-width: 60px;
height: 50px;
}
.th {
position: relative;
font-size: 13px;
padding: 2px;
background-color: #888888;
text-align: center;
border-right: 1px solid #555555;
display: inline-block;
box-sizing: border-box;
}
.tip-wrapper {
position: absolute;
}
.tip0 {
visibility: hidden;
position: fixed;
z-index: 1;
max-width: 325px;
min-width: 160px;
color: #333333;
text-align: left;
background: white;
border: 1px solid black;
}
.tip1 {
visibility: hidden;
position: fixed;
z-index: 1;
max-width: 325px;
min-width: 160px;
color: #333333;
text-align: left;
background: white;
border: 1px solid black;
}
.tooltip:hover .tip0, .tooltip:hover .tip1 {
visibility: visible;
}
<div class='gap'>Gap</div>
<div class='table'>
<div class='table-headers'>
<div class='tr'>
<div class='th tooltip'>
Z
<div class='tip0'>
Tip For Column Z is a long tip with enough text to overflow above the page top
</div>
</div>
<div class='th'>Y</div>
<div class='th tooltip'>
X
<div class='tip-wrapper'>
<div class='tip1'>
Tip For Column Z is a long tip with enough text to overflow above the page top
</div>
</div>
</div>
<div class='th'>W</div>
<div class='th'>V</div>
</div>
</div>
<div class='table-body'>
<div class='tr'>
</div>
<div class='tr'>
<div class='td stick'>A</div>
<div class='td'>B</div>
<div class='td'>C</div>
<div class='td'>D</div>
<div class='td'>E</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
<div class='tr'>
<div class='td'>F</div>
<div class='td'>G</div>
<div class='td'>H</div>
<div class='td'>I</div>
<div class='td'>J</div>
</div>
</div>
</div>
For tooltip above the table
Remove top attribute and change the position attribute in .tip0 as below
.tip0 {
visibility: hidden;
position: fixed;
margin: -56px -4px;
z-index: 1;
max-width: 325px;
min-width: 160px;
color: #333333;
text-align: left;
background: white;
border: 1px solid black;
}
And add margin in .tip1 as below
.tip1 {
visibility: hidden;
position: fixed;
margin: -56px -4px;
z-index: 1;
max-width: 325px;
min-width: 160px;
color: #333333;
text-align: left;
background: white;
border: 1px solid black;
}
For displaying tooltip within table
Add margin attribute as below inside .tip0 and .tip1 to keep tooltip inside table.
margin: -17px 0px;
and
remove top attribute from .tip0
so im having little bit of strugle making this work.
So basicly what i am trying to make is image with caption under it and when you hover over image it gets greenish color with transparency and a plus sign on it.
What ive tried so far is to make <div class=parent> and inside of <div class=parent> i would have <img> and another <div class="overlay">
HTML
<section class="gallery">
<div class="container">
<div class="row">
<div class="parent">
<img src="img/showcase.jpg">
<div class="overlay">
<i class="fas fa-plus"></i>
</div>
</div>
</div>
</div>
</section>
CSS
.gallery .overlay {
background: rgba(0, 188, 156, 0);
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
} /* this div overlay will be greenish transparent color over an image when image is hovered */
.gallery .parent {
margin-top: 40px;
} /* this is just some spacing when images go one under another */
.gallery .parent:hover .overlay {
background: rgba(0, 188, 156, 0.8);
}
.gallery .parent:hover .fa-plus {
color: white;
}
.gallery .fa-plus {
position: absolute;
top: 50%;
left: 50%;
color: rgba(255, 255, 255, 0);
font-size: 1.75em;
}
so this works perfectly fine.
But when i put caption in my HTML.
<section class="gallery">
<div class="container">
<div class="row">
<div class="parent">
<img src="img/showcase.jpg">
<div class="overlay">
<i class="fas fa-plus"></i>
</div>
<div class="caption">
<h5>Lorem ipsum dolor.</h5>
<h6>lorem</h6>
</div>
</div>
</div>
<div class="overlay"> stretches all the way down
im running out of ideas how to make this possible especially because i need it to be responsive, images are changing widths and heights based on the resolution so i can put <div class="overlay> height on 80% or 90%
EG on medium devices.
Put the image inside its own container where you can add the overlay:
.img-container {
display:inline-block;
position:relative;
}
.img-container img {
display:block;
}
.overlay {
background: rgba(0, 188, 156, 0);
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.gallery .parent {
margin-top: 40px;
}
.gallery .img-container:hover .overlay {
background: rgba(0, 188, 156, 0.8);
}
.gallery .img-container:hover .fa-plus {
color: white;
}
.gallery .fa-plus {
position: absolute;
top: 50%;
left: 50%;
color: rgba(255, 255, 255, 0);
font-size: 1.75em;
}
<section class="gallery">
<div class="container">
<div class="row">
<div class="parent">
<div class="img-container">
<img src="https://lorempixel.com/400/200/ ">
<div class="overlay ">
<i class="fas fa-plus ">+</i>
</div>
</div>
<div class="caption ">
<h5>Lorem ipsum dolor.</h5>
<h6>lorem</h6>
</div>
</div>
</div>
I have a button near the bottom of the page that is centered. Additionally, I have three images that I centered by making each image a col-lg-2 with 3 empty columns in between each one. I cannot figure out why these two items don't line up nicely, and which one is the one that is off center.
https://codepen.io/colesam/full/OgamyB/
SCSS:
a {
color: $blue;
font-size: 1.4vw;
font-weight: 500;
line-height: 1.7vw;
transition: all 0.2s;
&:hover {
color: $orange;
font-size: 1.7vw;
cursor: pointer;
text-decoration: none;
}
&:focus {
color: $blue;
text-decoration: none;
&:hover {
color: $orange;
cursor: pointer;
}
}
}
body {
background: white;
color: $black;
font-family: 'Roboto', sans-serif;
font-weight: 300;
text-shadow: $text-shadow-light;
}
h2 {
font-size: 5vh;
margin-top: 5vh;
}
p {
font-size: 3vh;
letter-spacing: 2px;
margin-top: 3vh;
text-shadow: none;
}
.btn-next {
bottom: 0;
padding-bottom: 5vh;
position: absolute;
text-align: center;
transition: all 0.3s;
a {
font-size: 5vw;
&:hover {
font-size: 5.5vw;
}
}
}
.center-text {
text-align: center;
}
.left-text {
text-align: left;
}
.no-margin {
margin: 0;
}
.right-text {
text-align: right;
}
.title {
padding-left: 4vw;
h3 {
font-size: 3vw;
text-shadow: $text-shadow;
}
}
#portfolio-page {
min-height: 100vh;
position: relative;
}
h4 {
font-size: 2vw;
}
.active-item {
box-shadow: $box-shadow-o;
-moz-box-shadow: $box-shadow-o;
-webkit-box-shadow: $box-shadow-o;
}
.btn-portfolio {
padding-top: 20vh;
text-align: center;
transition: all 0.3s;
a {
font-size: 5vw;
&:hover {
font-size: 5.5vw;
}
}
}
#featured-content {
background: rgba(0, 0, 0, 0.1);
height: 65vh;
margin-top: 2vh;
padding: 3vh 0;
}
#featured-img img {
box-shadow: $box-shadow-light;
-moz-box-shadow: $box-shadow-light;
-webkit-box-shadow: $box-shadow-light;
}
#primary-featured {
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
height: 45.5vh;
top: 10%;
}
#secondary-featured {
margin-top: 3vh;
}
HTML(inside a div.container):
<div id="portfolio-page">
<div class="row">
<div class="col-lg-4 col-lg-offset-4">
<h2 class="center-text">My Portfolio</h2>
<hr>
</div>
</div>
<div class="row">
<div class="col-lg-12" id="featured-content">
<div class="row no-margin">
<div class="col-lg-1 btn-portfolio" id="left-button">
<a><i class="glyphicon glyphicon-chevron-left"></i></a>
</div>
<div class="col-lg-8 col-lg-offset-1" id="primary-featured">
<div class="row">
<div class="col-lg-5" id="featured-img">
<img src="includes/img/headers.jpg" alt="A cluster of header images." class="img-responsive">
</div>
<div class="col-lg-6 col-lg-offset-1" class="center-text">
<h4 id="featured-title">Placeholder</h4>
<hr>
<p id="featured-description">Placeholder text.</p>
</div>
</div>
</div>
<div class="col-lg-1 col-lg-offset-1 btn-portfolio" id="right-button">
<a><i class="glyphicon glyphicon-chevron-right"></i></a>
</div>
<div class="col-lg-6 col-lg-offset-3" id="secondary-featured">
<div class="row">
<div class="col-lg-2" id="secondary-feature1">
<img src="includes/img/placeholder.jpg" alt="A placeholder image." class="img-responsive">
</div>
<div class="col-lg-2 col-lg-offset-3" id="secondary-feature2">
<img src="includes/img/placeholder.jpg" alt="A placeholder image." class="img-responsive">
</div>
<div class="col-lg-2 col-lg-offset-3" id="secondary-feature3">
<img src="includes/img/placeholder.jpg" alt="A placeholder image." class="img-responsive">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12 btn-next">
<a>
<i class="glyphicon glyphicon-chevron-down"></i>
</a>
</div>
</div>
</div>
Edit: Your problem is with position: absolute on .btn-next.
For absolutely positioned elements
This property specifies the distance between the left margin edge of
the element and the left edge of its containing block.
You have margin-left: -15px, so it aligns to center with the margin-left: -15px.
How to fix:
Add this to .btn-next:
right: 0;
left: 0;
...or you can remove position: absolute from .btn-next.
Alternative option:
The "down arrow" at the bottom isn't centered, because it's in the row class and that class has margin-left: 15px and margin-right: 15px.
If you give it margin: 0px, it'll be fine.
Rename div class="row" to something else or give it another class like div class="row down".
Examples:
<div class="down">
<div class="col-lg-12 btn-next">
<a>
<i class="glyphicon glyphicon-chevron-down"></i>
</a>
</div>
</div>
or
<div class="row down">
<div class="col-lg-12 btn-next">
<a>
<i class="glyphicon glyphicon-chevron-down"></i>
</a>
</div>
</div>
CSS (only if using second option):
.row.down {
margin: 0px;
}
I need to alternate the background color of the class jl-member-info but this doesn’t work. I have this code:
.uk-grid .jl-member-item .jl-member-info:nth-child(odd) {
position: relative;
padding: 0 0.9rem;
background-color: rgba(0, 198, 197, 0.89);
width: 100%;
margin-top: -95px;
}
.uk-grid .jl-member-item .jl-member-info:nth-child(even) {
position: relative;
padding: 0 0.9rem;
background-color: #090963;
width: 100%;
margin-top: -95px;
}
<div class="jl-member ">
<div class=" uk-grid-large uk-grid uk-grid-width-small-1-2 uk-grid-width-medium-1-2 uk-grid-width-large-1-4" data-uk-grid-margin="">
<div class="jl-member-item default uk-row-first">
<div class="jl-member-item-img">
<img class="uk-overlay-spin" src="/templates/g5_helium/custom/images/Alain.jpg?595f26c4">
</div>
<div class="jl-member-info">
<div class="jl-member-name">Alain</div>
<div class="jl-member-role">Maire</div>
<div class="jl-member-desc"><span class="cloaked_email">mail#test.fr</span>
</div>
</div>
</div>
<div class="jl-member-item default">
<div class="jl-member-item-img">
<img class="uk-overlay-spin" src="/templates/g5_helium/custom/images/Alain.jpg?595f26c4">
</div>
<div class="jl-member-info">
<div class="jl-member-name">Alain</div>
<div class="jl-member-role">Maire</div>
<div class="jl-member-desc"><span class="cloaked_email">mail#test.fr</span>
</div>
</div>
</div>
<div class="jl-member-item default">
<div class="jl-member-item-img">
<img class="uk-overlay-spin" src="/templates/g5_helium/custom/images/Alain.jpg?595f26c4">
</div>
<div class="jl-member-info">
<div class="jl-member-name">Alain</div>
<div class="jl-member-role">Maire</div>
<div class="jl-member-desc"><span class="cloaked_email">mail#test.fr</span>
</div>
</div>
</div>
</div>
</div>
You need to recode like this, because you have only one .jl-member-info in .jl-member-item it will always be odd!
.uk-grid .jl-member-item .jl-member-info {
position: relative;
padding: 0 0.9rem;
width: 100%;
margin-top: -95px;
background-color: #090963;
}
.uk-grid .jl-member-item:nth-child(odd) .jl-member-info {
background-color: rgba(0, 198, 197, 0.89);
}
THE PROBLEM
I have a swiper slider: http://codepen.io/kerowan/pen/xqYrwJ (recreate problem for example by giving .product-info-wrapper a fixed height of around 100px)
In the slides, there is an image and an infobox, which initially looks like this:
When I click on "Kurzinfo", the box needs to expand and finally look like this (the .swiper-container ends just after the NEW badge, so it has to flow over the swiper-container):
The problem is, that .swiper-container has an overflow: hidden; attribute, to hide the slides that continue to the right side.
WHAT HAVE I TRIED?
1) I have tried changing overflow: hidden; on the .swiper-container to overflow-x: hidden; in an attempt to just hide the slides which flow to the right, but show stuff that overflows downwards. This results in .swiper-container just adding a scrollbar, which lets you scroll down to see the content that should overflow.
2) I have tried changing position: absolute; on .product-info-wrapper (which wraps the box and the badge) to position: fixed;, because I read that the overflow attribute is ignored by position: fixed;. This doesn't seem to solve the problem, however.
I have not tried anything else yet, simply because I don't know any other solution approach.
SNIPPET
I pasted the snippet here, but it won't work, because I used SCSS and unfortunately lack the time to rewrite it to pure CSS. Can be copied to codepen, though, if the link above should die.
$(document).ready(function() {
var productsInFocus = new Swiper ('.products-in-focus', {
nextButton: '.product-focus-next',
prevButton: '.product-focus-prev',
slidesPerView: 4,
loop: false,
spaceBetween: 20
});
});
.content-wrapper {
max-width: 1100px;
margin: 0 auto;
}
.product-wrapper {
position: relative;
margin-bottom: 1rem * 5;
margin-top: 1rem * 5;
.swiper-slide {
display: flex;
justify-content: center;
align-items: flex-start;
position: relative;
min-height: 230px;
.product-badge-wrapper {
position: absolute;
bottom: 0;
right: 0;
.product-badge {
position: relative;
width: 100px;
overflow: hidden;
&.red {
&:before,
&:after {
border-color: #CF043C;
background-color: transparent;
}
&:after {
background-color: transparent;
border-left-color: transparent;
}
.product-badge-content {
&:before {
border-color: darken(#CF043C, 10%);
border-left-color: transparent;
border-right-color: transparent;
}
}
}
&.dark-gray {
&:before,
&:after {
border-color: lighten(#000, 37.4%);
background-color: transparent;
}
&:after {
background-color: transparent;
border-left-color: transparent;
}
.product-badge-content {
&:before {
border-color: lighten(#000, 13.5%);
border-left-color: transparent;
border-right-color: transparent;
}
}
}
&:before,
&:after {
content: "";
position: absolute;
left: 0;
background-color: transparent;
border-color: lighten(#000, 73%);
}
&:before {
top: 20px;
right: 0;
bottom: 0;
}
&:after {
bottom: auto;
left: -1px;
top: -10px;
border-style: solid;
border-width: 0 0 75px 75px;
background-color: transparent;
border-left-color: transparent;
width: 100px;
}
.product-badge-content {
height: 43px;
padding-right: 5px;
padding-left: 22px;
display: flex;
justify-content: flex-end;
align-items: center;
text-align: right;
text-transform: uppercase;
font-weight: 700;
position: relative;
z-index: 10;
color: #fff;
&.text-small {
font-size: .7rem;
font-weight: 400 !important;
}
&:before {
content: "";
position: absolute;
left: 11px;
bottom: 0;
display: block;
border-style: solid;
border-color: lighten(#000, 37.4%);
border-left-color: transparent;
border-right-color: transparent;
border-width: 10px 10px 0 10px;
}
}
}
}
.product-info-wrapper {
position: absolute;
bottom: 0;
max-width: 100%;
width: 100%;
padding-bottom: 10px;
.product-info {
position: relative;
padding: 1rem * .5;
padding-right: 1rem * 2;
overflow: hidden;
&-link {
display: block;
a {
color: lighten(#000, 37.4%);
transition: color 400ms ease-in-out;
&:hover {
color: #CF043C;
text-decoration: none;
}
}
}
&-price {
color: #CF043C;
&-del {
color: lighten(#000, 37.4%);
text-decoration: line-through;
font-size: .9rem;
}
}
&:before,
&:after {
position: absolute;
content: "";
left: 0;
z-index: -1;
background-color: lighten(#000, 93.5%);
border-color: lighten(#000, 93.5%);
}
&:before {
top: 0;
right: 0;
bottom: 35px;
}
&:after {
top: auto;
right: -5px;
bottom: 0;
border-style: solid;
border-width: 35px 35px 0 0;
background-color: transparent;
border-right-color: transparent;
}
}
}
}
.product-focus-prev,
.product-focus-next {
position: absolute;
color: lighten(#000, 37.4%);
background-image: none;
display: flex;
justify-content: center;
align-items: center;
font-size: 2rem;
top: 50%;
transform: translateY(-50%);
cursor: pointer;
}
.product-focus-prev {
left: -1rem * 10;
}
.product-focus-next {
right: -1rem * 10;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://use.fontawesome.com/b13050afbe.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.1/js/swiper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.1/js/swiper.jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.1/css/swiper.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="content-wrapper narrow products-in-focus">
<div class="product-wrapper">
<div class="swiper-container products-in-focus">
<div class="swiper-wrapper">
<div class="swiper-slide">
<img src="http://www.placehold.it/80x130">
<div class="product-info-wrapper">
<div class="product-info">
<div class="row no-gutters">
<div class="col-7">
<strong class="text-uppercase">Amino Force</strong>
<span class="product-info-link">Kurzinfo</span>
</div>
<div class="col-5 text-right">
<div class="product-info-price">CHF 34.00</div>
</div>
</div>
</div>
<div class="product-badge-wrapper">
<div class="product-badge dark-gray">
<div class="product-badge-content text-center">
%
</div>
</div>
</div>
</div>
</div>
<div class="swiper-slide">
<img src="http://www.placehold.it/80x130">
<div class="product-info-wrapper">
<div class="product-info">
<div class="row no-gutters">
<div class="col-8">
<strong class="text-uppercase">Basic Minerals</strong>
<span class="product-info-link">Kurzinfo</span>
</div>
<div class="col-4 text-right">
<span class="product-info-price">CHF 34.00</span>
</div>
</div>
</div>
<div class="product-badge-wrapper">
<div class="product-badge red">
<div class="product-badge-content">
new
</div>
</div>
</div>
</div>
</div>
<div class="swiper-slide">
<img src="http://www.placehold.it/80x130">
<div class="product-info-wrapper">
<div class="product-info">
<div class="row no-gutters">
<div class="col-8">
<strong class="text-uppercase">Amino Force</strong>
<span class="product-info-link">Kurzinfo</span>
</div>
<div class="col-4 text-right">
<span class="product-info-price">CHF 34.00</span>
</div>
</div>
</div>
</div>
</div>
<div class="swiper-slide">
<img src="http://www.placehold.it/80x130">
<div class="product-info-wrapper">
<div class="product-info">
<div class="row no-gutters">
<div class="col-8">
<strong class="text-uppercase">Whey Isolat CFM</strong>
<span class="product-info-link">Kurzinfo</span>
</div>
<div class="col-4 text-right">
<span class="product-info-price">CHF 34.00</span>
</div>
</div>
</div>
<div class="product-badge-wrapper">
<div class="product-badge">
<div class="product-badge-content text-small">
nicht<br>auf lager
</div>
</div>
</div>
</div>
</div>
<div class="swiper-slide">
<img src="http://www.placehold.it/80x130">
<div class="product-info-wrapper">
<div class="product-info">
<div class="row no-gutters">
<div class="col-8">
<strong class="text-uppercase">Amino Force</strong>
<span class="product-info-link">Kurzinfo</span>
</div>
<div class="col-4 text-right">
<span class="product-info-price">CHF 34.00</span>
</div>
</div>
</div>
<div class="product-badge-wrapper">
<div class="product-badge red">
<div class="product-badge-content">
new
</div>
</div>
</div>
</div>
</div>
<div class="swiper-slide">
<img src="http://www.placehold.it/80x130">
<div class="product-info-wrapper">
<div class="product-info">
<div class="row no-gutters">
<div class="col-8">
<strong class="text-uppercase">Basic Minerals</strong>
<span class="product-info-link">Kurzinfo</span>
</div>
<div class="col-4 text-right">
<span class="product-info-price">CHF 34.00</span>
</div>
</div>
</div>
</div>
</div>
<div class="swiper-slide">
<img src="http://www.placehold.it/80x130">
<div class="product-info-wrapper">
<div class="product-info">
<div class="row no-gutters">
<div class="col-8">
<strong class="text-uppercase">Amino Force</strong>
<span class="product-info-link">Kurzinfo</span>
</div>
<div class="col-4 text-right">
<span class="product-info-price">CHF 34.00</span>
</div>
</div>
</div>
</div>
</div>
<div class="swiper-slide">
<img src="http://www.placehold.it/80x130">
<div class="product-info-wrapper">
<div class="product-info">
<div class="row no-gutters">
<div class="col-8">
<strong class="text-uppercase">Whey Isolat CFM</strong>
<span class="product-info-link">Kurzinfo</span>
</div>
<div class="col-4 text-right">
<span class="product-info-price">CHF 34.00</span>
</div>
</div>
</div>
<div class="product-badge-wrapper">
<div class="product-badge">
<div class="product-badge-content text-small">
nicht<br>auf lager
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="product-focus-prev"><i class="fa fa-chevron-left"></i></div>
<div class="product-focus-next"><i class="fa fa-chevron-right"></i></div>
</div>
</div>
</div>
I hope my question was clear enough. If you need more details, please let me know!
You can add:
.swiper-slide {
padding-bottom: 30px;
}
where 30px is the value your badge should be beyond the border.
http://codepen.io/Deka87/pen/xqYXOq
I found a solution, I feel like it's a bit of a hack, however. For what it's worth, here it is:
.swiper-container {
overflow: visible;
}
$slide: ".swiper-slide";
.swiper-slide {
opacity: 0;
visibility: hidden;
transition: opacity 200ms ease-in-out, visibility 200ms ease-in-out;
&-active {
opacity: 1;
visibility: visible;
#for $i from 1 through 3 {
& + #{$slide} {
opacity: 1;
visibility: visible;
}
$slide: "#{$slide} + .swiper-slide";
}
}
}
So, what I do here is setting .swiper-container from overflow: hidden; to overflow: visible and then I tell every .swiper-slide to have opacity: 0; except for the &-active one. I then use the &-active slide as a starting point and iterate through a sass for-loop 3 times to add opacity: 1; for the next 3 .swiper-slides. This sass code produces the following pure css code (.swiper-container not included here)
.swiper-slide {
opacity: 0;
visibility: hidden;
transition: opacity 200ms ease-in-out, visibility 200ms ease-in-out;
}
.swiper-slide-active {
opacity: 1;
visibility: visible;
}
.swiper-slide-active + .swiper-slide {
opacity: 1;
visibility: visible;
}
.swiper-slide-active + .swiper-slide + .swiper-slide {
opacity: 1;
visibility: visible;
}
.swiper-slide-active + .swiper-slide + .swiper-slide + .swiper-slide {
opacity: 1;
visibility: visible;
}
This whole stuff is just to remove the overflow: hidden; from .swiper-container while still showing only the slides I need to see and hiding the others.
Now I can play around with the height of the Infobox and the effect I was looking for works.
<style>
//as we want to see details which are being cut of by default css from swiper contner we change it top overflow visible.
.swiper-container {
overflow: visible;
}
//we changed over hidden to visible all slides of the swiper slider would we visible so we need to hide them so we add below css.
.swiper-slide{
opacity: 0;
visibility: hidden;
}
// now because of the above css all the slider are set to opacity 0 , which makes them not visible, now as we want to see out active and next slide we supply below css by using their name. and set there opacity to 1.
.swiper-slide.swiper-slide-active,.swiper-slide.swiper-slide-next,.swiper-slide.swiper-slide-prev{
opacity: 1;
visibility: visible;
}
</style>
I recently had a similar problem in my react project and solved it by wrapping up the whole swiper component with a div and giving it the following properties:
.sliderContainer { position: relative; z-index: 2; height: 25rem; }
Another thing you gotta do is remove position: relative; from .swiper class like this:
.swiper { position: unset !important; }
Doing this will allow you to bypass the overflow: hidden; of .swiper class and essentially will bind child elements to the wrapper div and you'll be able to expand your div as much as you'd like without it being cropped off by the slider.
Also when defining a height for the slider, you should add it to the wrapper div you created instead of adding it to .swiper.
You can use custom padding, margin.
.swiper {
padding: 13px !important;
margin: -13px !important;
}