Keep fixed position image always in center of viewport - html

I'm looking for a way to keep my fixed position images, which are placed in the background of the page via z-index, always in the center.
Right now they are in the center, but when I start scrolling, they don't move down the page and are therefore no longer centered.
I've tried setting the image container to fixed positioning with top and left 50%. I've also tried using 50vh and 50vw, and have tested other vh and vw values.
* { padding: 0; margin: 0; box-sizing: border-box; }
body {
padding: 30px;
}
li.track {
display: block;
font-size: 5rem;
margin-bottom: 15px;
}
li.track:hover {
color: transparent;
-webkit-text-stroke-color: #18181b;
-webkit-text-stroke-width: 3px;
}
li.track:hover .album-art {
display: block;
}
.album-art {
z-index: -10;
position: fixed;
left: 47vw;
top: 12vh;
width: 90%;
height: 50%;
max-height: 450px;
display: none;
opacity: 0.5;
overflow: hidden;
transform: translateX(-50%);
}
.album-art img {
width: 100%;
}
a {
text-decoration: none;
color: inherit;
}
<div class="tracks">
<ol>
<li class="track">
<a href="#" class="nav">
<div class="album-art"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1774776/michael-nau.jpg"></div>
<p class="track-name">King Princess - 'Cheap Queen'</p>
</a>
</li>
<li class="track">
<a href="#" class="nav">
<div class="album-art"><img src="hhttps://s3-us-west-2.amazonaws.com/s.cdpn.io/1774776/louie-short.jpg"></div>
<p class="track-name">Charly Bliss - 'Capacity'</p>
</a>
</li>
<li class="track">
<a href="#" class="nav">
<div class="album-art"><img src="/https://s3-us-west-2.amazonaws.com/s.cdpn.io/1774776/P4K-Tom-Waits-Jim-Jarmusch_PitchHeader.jpg"></div>
<p class="track-name">Julia Jacklin - 'Good Guy'</p>
</a>
</li>
<li class="track">
<a href="#" class="nav">
<div class="album-art"><img src="/img/kevin-abstract.png"></div>
<p class="track-name">Kevin Abstract - 'Georgia'</p>
</a>
</li>
<li class="track">
<a href="#" class="nav">
<div class="album-art"><img src="/img/okey-dokey.jpg"></div>
<p class="track-name">Okey Dokey - 'Wag Your Tail'</p>
</a>
</li>
<li class="track">
<a href="#" class="nav">
<div class="album-art"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1774776/fruit-bats.jpg"></div>
<p class="track-name">Devendra Banhart - 'Kantori Ongaku'</p>
</a>
</li>
<li class="track">
<a href="#" class="nav">
<div class="album-art"><img src="/img/michael-nau.jpg"></div>
<p class="track-name">Michael Nau - 'Rides Through The Morning'</p>
</a>
</li>
<li class="track">
<a href="#" class="nav">
<div class="album-art"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1774776/fruit-bats.jpg"></div>
<p class="track-name">Hop Along - 'Prior Things'</p>
</a>
</li>
<ol>
</div>
I want the images that appear when hovered to always be in the center of the page (scrolled or not).

try this css:
body {
padding: 30px;
}
li.track {
display: block;
font-size: 5rem;
margin-bottom: 15px;
}
li.track:hover {
color: transparent;
-webkit-text-stroke-color: #18181b;
-webkit-text-stroke-width: 3px;
}
li.track:hover .album-art {
display: block;
}
.album-art {
z-index: -10;
position: fixed;
left: 50%;
top: 50%;
width: 90%;
height: 50%;
max-height: 450px;
display: none;
opacity: 0.5;
overflow: hidden;
transform: translate(-50%,-50%);
}
.album-art img {
width: 100%;
}
a {
text-decoration: none;
color: inherit;
}
thank you

Related

How to apply rounded border radius in opposite direction on hover on menu item in menubar [duplicate]

This question already has an answer here:
CSS transparent curved shape with two rounded sides
(1 answer)
Closed 6 months ago.
How to apply rounded border radius in opposite direction on hover on menu item in menubar
I want this effect on menu item hover
Currently my menubar looks like this
This is my css code
sidebar-menu .dropdown-toggle:hover, .sidebar-menu .show>.dropdown-toggle {
background: #f8f9fa;
color: #2daab8;
border-top-left-radius: 50px;
border-bottom-left-radius: 50px;
border-bottom-right-radius: 70px;
border-top-right-radius: 70px;
width: 250px;
}
HTML Code:
<div class="left-side-bar lftsideBar">
<div class="brand-logo">
<a href="{% url 'home' %}">
<img src="{% static 'website/vendors/images/Rectangle_33.png' %}" alt="" />
</a>
</div>
<div class="close-sidebar" data-toggle="left-sidebar-close">
<i class="ion-close-round"></i>
</div>
<div class="menu-block customscroll">
<div class="sidebar-menu">
<ul id="accordion-menu menucls" style="margin-left: 25px !important;margin-bottom:250px;">
<li>
<a href="{% url 'home' %}" class="dropdown-toggle no-arrow">
<span class="micon dw dw-house-1"></span><span class="mtext">Home</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle no-arrow">
<span class="micon dw dw-add-user"></span><span class="mtext">Client</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle no-arrow">
<span class="micon dw dw-add-user"></span><span class="mtext">Medical</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle no-arrow">
<span class="micon dw dw-add-user"></span><span class="mtext">Social</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle no-arrow">
<span class="micon dw dw-add-user"></span><span class="mtext">Transportation</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle no-arrow">
<span class="micon dw dw-add-user"></span><span class="mtext">Activity</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle no-arrow">
<span class="micon dw dw-add-user"></span><span class="mtext">Food</span>
</a>
</li>
<li>
<a href="#" class="dropdown-toggle no-arrow">
<span class="micon dw dw-add-user"></span><span class="mtext">Reports</span>
</a>
</li>
</ul>
</div>
</div>
Can you please suggest me to what css make changes so I can make exactly same design as per screenshot-1 on each and every item of menubar?
You'll need imagination to be able to create the inverted radius. We could use a circle and use it to mask a square, but CSS mask is not very well supported still. But we can extend on this strategy and use borders to fill the part of a square not occupied by the circle.
In my example below, I've used a holder with overflow:hidden to hide any overflowing border. The size of the holder also determines the size of the final curve since the div inside spans to 100%. Instead of using a full circle, I've used just the 1/4 of it that was needed by rounding just the interesting corner to 100%. The color of the border determines the color of the curve.
.holder{
width:100px;
height:100px;
overflow:hidden;
}
.holder div{
width:100%;
height:100%;
border-bottom-right-radius:100%;
border:99999px solid black;
border-left:none;
border-top:none;
}
<div class="holder">
<div></div>
</div>
Now, armed with that knowledge, you can easily do the same for the bottom part by rounding a different corner. You'll need to add the markup to each menu element tough, and play with the display property. You could try to reduce as much as possible by using the ::before and/or ::after elements but I doupt you'd be able to save much (just maybe get to replace the inner div maybe?)
source code from there
const initNavBar = () => {
const menusEl = document.querySelectorAll('.side-bar ul li')
menusEl.forEach(menu => menu.addEventListener('click', ()=> {
const menuActiveEl = document.querySelector('.side-bar ul li.active')
menuActiveEl.classList.remove('active')
menu.classList.add('active')
}))
}
initNavBar()
:root {
--color-primary: #1380b8;
--color-secondary: #33ace3;
}
aside.side-bar-wrap {
--radius-size: 25px;
height: 98vh;
position: fixed;
top: 1vh;
left: 1vh;
overflow-y: scroll;
overflow-x: hidden;
border-radius: var(--radius-size);
padding-right: 2px;
}
aside.side-bar-wrap::-webkit-scrollbar {
width: 10px;
}
aside.side-bar-wrap::-webkit-scrollbar-track {
background-color: transparent;
}
aside.side-bar-wrap::-webkit-scrollbar-thumb {
border-radius: var(--radius-size);
background-color: var(--color-primary);
}
nav.side-bar {
min-height: 100%;
background-color: var(--color-primary);
display: inline-block;
border-left: var(--radius-size) solid var(--color-secondary);
border-right: var(--radius-size) solid var(--color-primary);
border-radius: var(--radius-size);
}
nav.side-bar .logo-area {
--curve-size: calc(2 * var(--radius-size));
position: relative;
display: flex;
justify-content: center;
align-items: center;
padding: 10px;
min-height: var(--curve-size);
background-color: var(--color-secondary);
border-radius: 0 var(--radius-size) var(--radius-size) 0;
box-shadow: var(--radius-size) 0 var(--color-secondary);
}
nav.side-bar .logo-area::after {
content: '';
width: var(--curve-size);
height: var(--curve-size);
background-color: var(--color-primary);
border-radius: 50%;
position: absolute;
bottom: calc(-1 * var(--curve-size));
left: 0;
box-shadow: calc(-1 * var(--curve-size) * 0.5) calc(-1 * var(--curve-size) * 0.5) var(--color-secondary);
}
nav.side-bar .logo-area img {
position: absolute;
max-height: 75%;
transition-duration: 1s;
}
aside.side-bar-wrap:hover nav.side-bar .logo-area img.min {
max-height: 0;
opacity: 0;
}
nav.side-bar .logo-area img.max {
max-width: 0;
opacity: 0;
transition-duration: 1s;
}
aside.side-bar-wrap:hover nav.side-bar .logo-area img.max {
max-width: 90%;
opacity: 1;
}
nav.side-bar ul {
padding: 0;
margin: calc(2 * var(--radius-size)) 0;
display: flex;
flex-direction: column;
}
nav.side-bar ul li {
height: 50px;
padding: 10px var(--radius-size);
list-style: none;
border-radius: var(--radius-size);
margin-bottom: var(--radius-size);
z-index: 1;
}
nav.side-bar ul li:not(.active) {
z-index: 2;
}
nav.side-bar ul li:not(.active):hover {
backdrop-filter: brightness(0.85);
}
nav.side-bar ul li.active {
position: relative;
background-color: var(--color-secondary);
border-radius: 0 var(--radius-size) var(--radius-size) 0;
}
nav.side-bar ul li.active::before,
nav.side-bar ul li.active::after {
--curve-size: calc(2 * var(--radius-size));
content: '';
width: var(--curve-size);
height: var(--curve-size);
background-color: var(--color-primary);
border-radius: 50%;
position: absolute;
}
nav.side-bar ul li.active::before {
top: calc(-1 * var(--curve-size));
left: 0;
box-shadow: calc(-1 * var(--curve-size) * 0.5) calc(var(--curve-size) * 0.5) var(--color-secondary);
}
nav.side-bar ul li.active::after {
bottom: calc(-1 * var(--curve-size));
left: 0;
box-shadow: calc(-1 * var(--curve-size) * 0.5) calc(-1 * var(--curve-size) * 0.5) var(--color-secondary);
}
nav.side-bar ul li a{
color: white;
font-size: 16pt;
width: 100%;
height: 100%;
display: flex;
gap: 0;
align-items: center;
text-decoration: none;
transition: 1s;
}
aside:hover nav.side-bar ul li a{
gap: 10px;
}
nav.side-bar ul li a span {
display: flex;
transition: 0.75s cubic-bezier(0.39, 0.58, 0.57, 1);
}
nav.side-bar ul li a span.icon {
font-size: 24pt;
}
nav.side-bar ul li a span.title {
max-width: 0;
opacity: 0;
}
aside:hover nav.side-bar ul li a span.title {
width: auto;
max-width: 10rem;
opacity: 1;
}
<aside class="side-bar-wrap">
<nav class="side-bar">
<div class="logo-area">
<img class="min" src="images/min-logo.png" alt="logo">
<img class="max" src="images/max-logo.png" alt="logo">
</div>
<ul>
<li class="active">
<a href="#">
<span class="title">Home</span>
</a>
</li>
<li>
<a href="#">
<span class="title">News</span>
</a>
</li>
<li>
<a href="#">
<span class="title">Jobs</span>
</a>
</li>
<li>
<a href="#">
<span class="title">Contact</span>
</a>
</li>
<li>
<a href="#">
<span class="title">About</span>
</a>
</li>
</ul>
</nav>
</aside>

HTML UL jumping up when new element is added

I have tried to re-produce an example. I have a button when it is hovered it displays UL element. But the problem I have is If you were to try to add more li elements to UL it jumps up or if deleted any li element from existing list it jumps down. I can't figure out what's causing this. Any help appreciated.
.icon-box {
display: inline-block;
top: 50%;
left: 50%;
transform: translate(-50%, -170%);
position: relative;
text-align: center;
font-size: 24px;
margin-top: 100px;
}
.btn {
text-decoration: none;
color: black;
background-color: #a05344;
padding: 15px;
}
.container {
display: flex;
}
#nav-like {
position: absolute;
top: 51.5%;
left: 50%;
transform: translate(-82%, -40%);
width: 250px;
background-color: #C05555;
margin-top: 20px;
padding: 10px 30px;
visibility: hidden;
}
.movie-img {
height: 100px;
margin-right: 30px;
}
.like-name,
.like-release-date {
color: #BBBFCA;
font: 14px Arial, sans-serif font-weight:400;
}
.like-release-date {
margin-left: 5px;
}
.icon-box:hover+#nav-like {
visibility: visible;
}
<div class="icon-box">
click me
</div>
<ul id="nav-like">
<li class="container">
<div class="like-img">
<img src="https://github.com/saedsq/MovieLibrary/blob/master/src/img/nat-1.jpg?raw=true" class="movie-img" alt="rambo">
</div>
<div class="like-name">
<h3>Rambo</h3>
</div>
<div class="like-release-date">
<h3>( 2006 )</h3>
</div>
</li>
<li class="container">
<div class="like-img">
<img src="https://github.com/saedsq/MovieLibrary/blob/master/src/img/nat-1.jpg?raw=true" class="movie-img" alt="rambo">
</div>
<div class="like-name">
<h3>Rambo</h3>
</div>
<div class="like-release-date">
<h3>( 2006 )</h3>
</div>
</li>
<li class="container">
<div class="like-img">
<img src="https://github.com/saedsq/MovieLibrary/blob/master/src/img/nat-1.jpg?raw=true" class="movie-img" alt="rambo">
</div>
<div class="like-name">
<h3>Rambo</h3>
</div>
<div class="like-release-date">
<h3>( 2006 )</h3>
</div>
</li>
<li class="container">
<div class="like-img">
<img src="https://github.com/saedsq/MovieLibrary/blob/master/src/img/nat-1.jpg?raw=true" class="movie-img" alt="rambo">
</div>
<div class="like-name">
<h3>Rambo</h3>
</div>
<div class="like-release-date">
<h3>( 2006 )</h3>
</div>
</li>
</ul>

How do I make p appear on hover ONTOP of an image?

I know the question of overlapping has been answered multiple times, however, I'm trying to place the text on top of the image centred once hovered.
I tried z-index, I tried relative and absolute, decided I'd ask for help.
.flex-container {
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
margin: 0;
padding-left: 7%;
padding-right: 7%;
padding-top: 25px;
padding-bottom: 50px;
justify-content: center;
}
.flex-container div {
margin: 0;
position: relative;
margin-bottom: -5px;
font-size: medium;
text-align: center;
z-index: 0;
}
.flex-container div:hover {
filter: brightness(50%);
}
.flex-container div p {
display: none;
}
.flex-container div:hover p {
position: absolute;
color: black;
z-index: 1;
text-align: center;
}
<div>
<a href="Printing/menus.html">
<img src="../Images/menus-01.png" alt="Printing" style="width:100%; height:auto;"/>
</a>
<p>Menus</p>
</div>
You should have set the text CSS first and just then get the hover to show the styles, also, you forgot to set the container styles on your code.
See if that's what you want :
HTML :
<div class="container">
<img src="../Images/menus-01.png" alt="Image" style="width:100%;">
<div class="topTxt">Text on Center/div>
</div>
CSS :
.container {
position: relative;
text-align: center;
}
.topTxt {
position: absolute;
display: none;
top: 0;
left: 50%;
transform: translate(-50%, 0%);
}
.container:hover .topTxt {
display: block;
}
OR use JavaScript :
document.getElementsByClass("container").addEventListener("mouseover", function() {
document.getElementsByClass("topTxt").style.display = "block";
});
Get the following snippet to better view of what you requested :
#container {
max-width: 900px;
margin: 0 auto;
padding: 5px;
font-size: 0;
list-style: none;
background-color: #444;
}
#container li {
display: inline-block;
width: 25%;
vertical-align: middle;
box-sizing: border-box;
margin: 0;
padding: 0;
}
.container-cells {
margin: 5px;
box-shadow: 0 0 6px rgba(0, 0, 0, 0.3);
display: block;
position: relative;
overflow: hidden;
}
.imgs {
display: block;
width: 100%;
height: auto;
border: none;
filter: brightness(100%);
transition: all 0.3s;
}
#container li:hover .imgs {
filter: brightness(50%);
}
.overlay {
position: absolute;
display: block;
top: 0;
left: 0;
width: 100%;
height: 0px;
margin: auto;
background: #000;
background-size: 50px 50px;
transition: all 0.3s;
}
#container li:hover .overlay {
height: 30px;
}
.title {
display: block;
padding: 5px 30px;
box-sizing: border-box;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 40px;
text-align: center;
font-size: 18px;
color: white;
opacity: 0;
transform: translateY(-20px);
transition: all .3s;
}
#container li:hover .title {
transform: translateY(0px);
opacity: 0.9;
}
#media (max-width: 9000px) {
#container li {
width: 25%;
}
}
#media (max-width: 700px) {
#container li {
width: 33.33%;
}
}
#media (max-width: 550px) {
#container li {
width: 50%;
}
}
<ul id="container">
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
</ul>
You just need to put the text before the image, as the image will be the background either way, just add the the text before, then the image and the text will be siblings, not parent and child, so the effect of hover won't affect the child, therefore, the text color will remain without having the filter applied to it.
Maybe the below is what you're looking for?
How to put text over images in html?
The answer suggests using a "div" tag rather than an "img" tag. Here is an example:
.image {
width:400px;
height:400px;
background-image: url(http://lorempixel.com/output/cats-q-c-640-480-4.jpg);
background-size:cover;
}
<div class="image">Text on top of image</div>

How to resize image when there is less height, while respecting the container below?

The img tag resizes automatically.
However, I'm making a lightbox that when you click, the image appears in the middle, and at the bottom you have all images showing.
The bottom bar with images, should be always at the bottom, and the image should be proportionated in the center of the screen, especting the bar at the bottom.
So when we resize the screen from the bottom e.g. open the dev tools, the image should shrink and the bar at the bottom should go up.
Here is the codepen: https://codepen.io/Aurelian/pen/eKEQMP?editors=0100
Here is the HTML:
<div class="container">
<ul class="gallery__list">
<li class="gallery__item">
<a class="gallery__link" href="https://farm5.staticflickr.com/4357/36172707494_53c0f25d98_h_d.jpg">
<img src="https://farm5.staticflickr.com/4357/36172707494_53c0f25d98_h_d.jpg">
</a>
</li>
<li class="gallery__item">
<a class="gallery__link" href="https://ritzcarlton-h.assetsadobe.com/is/image/content/dam/the-ritz-carlton/hotels/asia-pacific/japan/tokyo/guest-rooms/RCTOKYO_00451.jpg?$XlargeViewport100pct$">
<img src="https://ritzcarlton-h.assetsadobe.com/is/image/content/dam/the-ritz-carlton/hotels/asia-pacific/japan/tokyo/guest-rooms/RCTOKYO_00451.jpg?$XlargeViewport100pct$">
</a>
</li>
<li class="gallery__item">
<a class="gallery__link" href="https://thewallpaper.co/wp-content/uploads/2016/09/hd-place-wallpaper-high-definition-cool-images-cities-desktop-images-view-point-hd-Exotic-Places-1920x1200.jpg">
<img src="https://thewallpaper.co/wp-content/uploads/2016/09/hd-place-wallpaper-high-definition-cool-images-cities-desktop-images-view-point-hd-Exotic-Places-1920x1200.jpg">
</a>
</li>
<li class="gallery__item">
<a class="gallery__link" href="https://thewallpaper.co/wp-content/uploads/2016/09/landscapes-cool-images-cities-best-place-ever-backgrounds-view-point-world-Exotic-Places-1920x1200-768x480.jpg">
<img src="https://thewallpaper.co/wp-content/uploads/2016/09/landscapes-cool-images-cities-best-place-ever-backgrounds-view-point-world-Exotic-Places-1920x1200-768x480.jpg">
</a>
</li>
<li class="gallery__item">
<a class="gallery__link" href="http://hotelslike.com/wp-content/uploads/2016/09/117725.jpg">
<img src="http://hotelslike.com/wp-content/uploads/2016/09/117725.jpg">
</a>
</li>
<li class="gallery__item">
<a class="gallery__link" href="https://s-media-cache-ak0.pinimg.com/originals/62/e1/35/62e135d63fef91cdc2d058a8542507d3.jpg">
<img src="https://s-media-cache-ak0.pinimg.com/originals/62/e1/35/62e135d63fef91cdc2d058a8542507d3.jpg">
</a>
</li>
<li class="gallery__item">
<a class="gallery__link" href="https://blog.eurail.com/wp-content/uploads/2016/08/La-Rambla-at-night.jpg">
<img src="https://blog.eurail.com/wp-content/uploads/2016/08/La-Rambla-at-night.jpg">
</a>
</li>
<li class="gallery__item">
<a class="gallery__link" href="http://www.hopper.com/cms-assets/images/Destinations/Europe/Ireland/Dublin_shutterstock_111481523_800x.jpg">
<img src="http://www.hopper.com/cms-assets/images/Destinations/Europe/Ireland/Dublin_shutterstock_111481523_800x.jpg">
</a>
</li>
</ul>
</div>
<div class="modal-gallery">
<div class="modal-gallery__main">
<div class="modal-gallery__main--outer">
<!-- Tool Bar -->
<ul class="modal-gallery__tool-bar">
<span class="modal-gallery__close"><i class="fa fa-times" aria-hidden="true"></i></span>
<a class="modal-gallery__downolad" href=""><i class="fa fa-download" aria-hidden="true"></i></a>
<span class="modal-gallery__fullscreen"><i class="fa fa-arrows-alt" aria-hidden="true"></i></span>
<span class="modal-gallery__autoplay"><i class="fa fa-play-circle-o" aria-hidden="true"></i></span>
<div class="modal-gallery__counter">
<span class="modal-gallery__counter--current">1</span>
<span>/</span>
<span class="modal-gallery__counter--all">5</span>
</div>
</ul>
<!-- Main Section -->
<div class="modal-gallery__main-image-wrap">
<img class="modal-gallery__main-image" src="https://s-media-cache-ak0.pinimg.com/originals/62/e1/35/62e135d63fef91cdc2d058a8542507d3.jpg">
<div class="modal-gallery__arrow-wrap">
<button class="modal-gallery__arrow-prev"></button>
<button class="modal-gallery__arrow-next"></button>
</div>
</div>
<div class="modal-gallery__pic-list">
<ul class="modal-gallery__pic-list-wrap">
<li class="modal-gallery__item">
<a class="modal-gallery__link" href="https://s-media-cache-ak0.pinimg.com/originals/62/e1/35/62e135d63fef91cdc2d058a8542507d3.jpg">
<img src="https://s-media-cache-ak0.pinimg.com/originals/62/e1/35/62e135d63fef91cdc2d058a8542507d3.jpg">
</a>
</li>
<li class="modal-gallery__item">
<a class="modal-gallery__link" href="https://s-media-cache-ak0.pinimg.com/originals/62/e1/35/62e135d63fef91cdc2d058a8542507d3.jpg">
<img src="https://s-media-cache-ak0.pinimg.com/originals/62/e1/35/62e135d63fef91cdc2d058a8542507d3.jpg">
</a>
</li>
<li class="modal-gallery__item">
<a class="modal-gallery__link" href="https://s-media-cache-ak0.pinimg.com/originals/62/e1/35/62e135d63fef91cdc2d058a8542507d3.jpg">
<img src="https://s-media-cache-ak0.pinimg.com/originals/62/e1/35/62e135d63fef91cdc2d058a8542507d3.jpg">
</a>
</li>
<li class="modal-gallery__item">
<a class="modal-gallery__link" href="https://s-media-cache-ak0.pinimg.com/originals/62/e1/35/62e135d63fef91cdc2d058a8542507d3.jpg">
<img src="https://s-media-cache-ak0.pinimg.com/originals/62/e1/35/62e135d63fef91cdc2d058a8542507d3.jpg">
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
Here's the CSS:
*, *:before, *:after {
box-sizing: border-box;
}
.container {
max-width: 960px;
margin: 50px auto;
}
img {
max-width: 100%;
max-height: 100%;
display: block;
height: auto;
}
// Gallery List
.gallery {
&__item {
width: calc(25%);
float: left;
height: 220px;
& img {
height: 220px;
object-fit: cover;
}
}
}
// Gallery Modal
.modal-gallery {
position: fixed;
z-index: 9999999;
width: 100%;
height: 100%;
top: 0;
left: 0;
transition: opacity 0.15s ease 0s;
background-color: #0e0e0e;
// opacity: .95;
&__main {
height: auto;
position: relative;
&--outer {
height: auto;
position: relative;
top: 15px;
}
}
&__main-image-wrap {
position: relative;
height: auto;
width: 100%;
}
&__main-image {
width: auto;
// max-width: 100%;
height: auto;
margin: 0 auto;
display: block;
position: relative;
z-index: 1;
}
&__arrow-wrap {
position: absolute;
left: 0;
right: 0;
top: 50%;
bottom: 0;
z-index: 20;
}
&__tool-bar {
color: #acabab;
z-index: 10;
left: 0;
position: absolute;
top: 0;
padding: 15px;
width: 100%;
background-color: rgba(0, 0, 0, 0.45);
}
&__counter {
display: inline-block;
}
&__pic-list {
width: 100%;
background: red;
bottom: 0;
}
&__pic-list-wrap {
width: 100%;
padding: 25px 0;
border: 1px solid #313131;
border-left: 0;
border-right: 0;
position: relative;
text-align: center;
overflow: hidden;
}
&__item {
width: 10%;
float: left;
padding: 15px;
margin-right: 15px;
& img {
height: 50px;
width: 100%;
object-fit: cover;
}
}
}
Wrap both the slideshow element and the bottom bar with images in a container.
Give each one an explicit height (i.e. slideshow height: 80%, bottom bar height: 20%).
Then apply height: 100% to the image containers (i.e. a and or li).
Then apply height: 100%; width: auto; to each image. This will make the images responsive while maintaining their aspect ratio. However, it's important that the image container is dynamic (i.e. height/width % or vh or w/e). You could also do width: 100%; height: auto; for instance.

In HTML + CSS: Force text to max two rows, increase the width

I have a horizontal timeline made with list (li) elements that has display:flex; at it's parent attribute. That make the list horizontal. But I want the texts to be maximum two rows in the boxes.
So for example, I want this:
The first
asphalt is
delivered.
To become this:
The first asphalt
is delivered.
I want that to be a rule and the width can become as wide as it need to be.
And I have seen a lot of examples where the solution is to work with overflow:hidden. But that's not what I looking for. I wanna know if there is a way to get a dynamic width so all the text is visible.
Edit:
Here is the snippet:
.left-arrow,.right-arrow {
float:left;
width: 0;
height: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
margin-top:20px;
cursor:pointer;
}
.left-arrow {
border-right:20px solid black;
padding-left: 5px;
}
.right-arrow {
border-left:20px solid black;
padding-right: 5px;
}
.timeline {
list-style-type: none;
display: flex;
justify-content: left;
margin: 0 5px;
padding: 0;
float: left;
width: calc(100% - 60px);
overflow-x: scroll;
vertical-align: top;
}
.timeline li {
width: 300px;
vertical-align: top;
}
.timeline li a {
color: #000;
}
.timestamp {
margin-bottom: 10px;
padding: 10px 10px 0;
display: flex;
flex-direction: column;
align-items: center;
white-space: nowrap;
font-weight: 600;
}
.status {
padding: 10px 5px 10px;
display: flex;
justify-content: center;
border-top: 3px solid #000;
position: relative;
font-size: 1.1rem;
}
.status:before {
content: "";
width: 4px;
height: 8px;
background-color: black;
position: absolute;
top: -10px;
left: calc(50% - (4px / 2));
}
<ul class="timeline" id="timeline">
<li>
<a href="#pop-1910-20">
<div class="timestamp">1910-20</div>
<div class="status">The founder buys land.</div>
</a>
</li>
<li>
<a href="#pop-1928">
<div class="timestamp">1928</div>
<div class="status">The refinery goes into operation.</div>
</a>
</li>
<li>
<a href="#pop-1929">
<div class="timestamp">1929</div>
<div class="status">The first asphalt is delivered.</div>
</a>
</li>
<li>
<a href="#pop-1931">
<div class="timestamp">1931</div>
<div class="status">New cracker.</div>
</a>
</li>
<li>
<a href="#pop-1939-45">
<div class="timestamp">1939-45</div>
<div class="status">Central role for the national sales</div>
</a>
</li>
<li>
<a href="#pop-1950s">
<div class="timestamp">1950-talet</div>
<div class="status">The network of petrol stations is being expanded</div>
</a>
</li>
<li>
<a href="#pop-1956">
<div class="timestamp">1956</div>
<div class="status">The second refinery is finished</div>
</a>
</li>
<li>
<a href="#pop-1958">
<div class="timestamp">1958</div>
<div class="status">The founder dies.</div>
</a>
</li>
<li>
<a href="#pop-1960">
<div class="timestamp">1960</div>
<div class="status">Risky sales strategy</div>
</a>
</li>
<li>
<a href="#pop-1967-69">
<div class="timestamp">1967-69</div>
<div class="status">Increased capacity of bitumen</div>
</a>
</li>
<li>
<a href="#pop-1974">
<div class="timestamp">1974</div>
<div class="status">The energy crisis leads to financial crisis</div>
</a>
</li>
</ul>
We can also fix the two lines for li elements by fixing the height and and line-height by halve of it. So two lines only can come but width can be maximum. So that there will be two lines but it would expand on x side. It will be something like this link below.
.twolines{
height: 50px;
line-height: 25px;
width: 100%;
overflow-y: hidden;
}
<ul>
<li class="twolines">Hello World. If it has two lines but have max width it can to be produced so that it will not expanded. Some extra text will be truncated when even two lines exceeded</li>
<li class="twolines">Hello World. If it has two lines but have max width it can to be produced so that it will not expanded.</li>
</ul>
Taken your code snippet and used the same logic of height and line-height. Along with that used box-sizing border box as there was some alignment (like padding and boader) so the width will be controlled including those also.Now only two lines and taken width accrodingly.
.left-arrow,.right-arrow {
float:left;
width: 0;
height: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
margin-top:20px;
cursor:pointer;
}
.left-arrow {
border-right:20px solid black;
padding-left: 5px;
}
.right-arrow {
border-left:20px solid black;
padding-right: 5px;
}
.timeline {
list-style-type: none;
display: flex;
justify-content: left;
margin: 0 5px;
padding: 0;
float: left;
width: calc(100% - 60px);
overflow-x: scroll;
vertical-align: top;
}
.timeline li {
width: 300px;
vertical-align: top;
}
.timeline li a {
color: #000;
}
.timestamp {
margin-bottom: 10px;
padding: 10px 10px 0;
display: flex;
flex-direction: column;
align-items: center;
white-space: nowrap;
font-weight: 600;
}
.status {
padding: 10px 5px 10px;
display: flex;
justify-content: center;
border-top: 3px solid #000;
position: relative;
font-size: 1.1rem;
box-sizing: border-box;
height: 43px;
line-height: 15px;
width: 213px;
}
.status:before {
content: "";
width: 4px;
height: 8px;
background-color: black;
position: absolute;
top: -10px;
left: calc(50% - (4px / 2));
}
<ul class="timeline" id="timeline">
<li>
<a href="#pop-1910-20">
<div class="timestamp">1910-20</div>
<div class="status">The founder buys land.</div>
</a>
</li>
<li>
<a href="#pop-1928">
<div class="timestamp">1928</div>
<div class="status">The refinery goes into operation.</div>
</a>
</li>
<li>
<a href="#pop-1929">
<div class="timestamp">1929</div>
<div class="status">The first asphalt is delivered.</div>
</a>
</li>
<li>
<a href="#pop-1931">
<div class="timestamp">1931</div>
<div class="status">New cracker.</div>
</a>
</li>
<li>
<a href="#pop-1939-45">
<div class="timestamp">1939-45</div>
<div class="status">Central role for the national sales</div>
</a>
</li>
<li>
<a href="#pop-1950s">
<div class="timestamp">1950-talet</div>
<div class="status">The network of petrol stations is being expanded</div>
</a>
</li>
<li>
<a href="#pop-1956">
<div class="timestamp">1956</div>
<div class="status">The second refinery is finished</div>
</a>
</li>
<li>
<a href="#pop-1958">
<div class="timestamp">1958</div>
<div class="status">The founder dies.</div>
</a>
</li>
<li>
<a href="#pop-1960">
<div class="timestamp">1960</div>
<div class="status">Risky sales strategy</div>
</a>
</li>
<li>
<a href="#pop-1967-69">
<div class="timestamp">1967-69</div>
<div class="status">Increased capacity of bitumen</div>
</a>
</li>
<li>
<a href="#pop-1974">
<div class="timestamp">1974</div>
<div class="status">The energy crisis leads to financial crisis</div>
</a>
</li>
</ul>