Fill a grid column with a image? - html

I have a css grid container I use to have a image slider and some text on the right. I have everything working except for getting the image to actually stretch across the whole container.
How I have it set up is (trunicated):
<div class="slideshowGrid">
<div class="slideshow-container">
<div class="mySlides fade">
<img src="{{ module.slide.slide_image.src }}" alt="{{ module.slide.slide_image.alt }}" {{ loadingAttr }} {{ sizeAttrs }}>
</div>
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
<div class="textboxes">
<div class="text">
<h3 class="headerText">{% inline_text field="slide.heading_text" value="{{ module.slide.heading_text }}" %}</h3>
<div class="bodyText">
{% inline_rich_text field="slide.body_text" value="{{ module.slide.body_text }}" %}
</div>
</div>
<div class="linkBox">
<div class="linkingText">
Book Now
</div>
</div>
</div>
</div>
I guess my question is; is there anyway to stretch the image div to fill the available column in the grid without forcing the image to be a background image? I know background image is a way to do it, but I feel like it would require some significant code changes to do that. Here's my css:
code:
* {box-sizing:border-box}
.slideshowGrid{
display: grid;
grid-template-columns: 75% 25%;
justify-content: center;
align-content: center;
justify-items: stretch;
}
.textboxes{
display: grid;
justify-items: center;
}
.linkBox{
align-self: flex-end;
justify-self: center;
}
/* Slideshow container */
.slideshow-container {
max-width: 100%;
height: 500px;
position: relative;
margin: auto;
}
.slideshow-container img{
height: 500px !important;
width: 1200px !important;
object-fit: cover !important;
}
/* Hide the images by default */
.mySlides {
display: none;
}
/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
/* Caption text */
.text {
color: black;
font-size: 15px;
padding: 8px 12px
width: 100%;
align-self: center;
justify-self: center;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* Fading animation */
.fade {
animation-name: fade;
animation-duration: 1.5s;
}
#keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
/* On smaller screens, decrease text size */
#media only screen and (max-width: 300px) {
.prev, .next,.text {font-size: 11px}
}
Thanks!

Okay, I see what you're doing. You've explicitly defined the height of the container for the images and then applied attributes to the images inside of that container. So, the easiest fix is to just apply the same height to your images, give them a width of 100% so they fill the container horizontally, and use object-fit: cover; to crop them into the container and maintain their aspect ratio. https://jsfiddle.net/astombaugh/ad4kb2v5/46/ You may need to tweak the results in the context of your entire project but this should at least get your image container moving in the right direction.
let slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
let i;
let slides = document.getElementsByClassName("mySlides");
let dots = document.getElementsByClassName("dot");
let headers = document.getElementsByClassName("headerText");
let bodies = document.getElementsByClassName("bodyText");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slides[slideIndex-1].style.display = "block";
}
* {
box-sizing: border-box;
}
body {
background-color: grey;
}
.slideshowGrid {
display: grid;
grid-template-columns: 75% 25%;
justify-content: center;
align-content: center;
justify-items: stretch;
}
.textboxes {
display: grid;
justify-items: center;
}
.linkBox {
align-self: flex-end;
justify-self: center;
}
/* Slideshow container */
.slideshow-container {
height: 500px;
position: relative;
}
.slideshow-container img {
height: 500px;
width: 100%;
object-fit: cover;
}
/* Hide the images by default */
.mySlides {
display: none;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
}
/* Caption text */
.text {
color: black;
font-size: 15px;
padding: 8px 12px;
width: 100%;
align-self: center;
justify-self: center;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active,
.dot:hover {
background-color: #717171;
}
/* Fading animation */
.fade {
animation-name: fade;
animation-duration: 1.5s;
}
#keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
/* On smaller screens, decrease text size */
#media only screen and (max-width: 300px) {
.prev,
.next,
.text {
font-size: 11px
}
}
<div class="slideshowGrid">
<div class="slideshow-container">
<div class="mySlides fade">
<img src="https://2822935.fs1.hubspotusercontent-na1.net/hubfs/2822935/rw_phaseII.jpg">
</div>
<div class="mySlides fade">
<img src="https://2822935.fs1.hubspotusercontent-na1.net/hubfs/2822935/Riverwalk_Day-View_CYMK-web.jpg">
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
<div class="textboxes">
<div class="text">
<h3 class="headerText">TEST</h3>
<div class="bodyText">
adsfasdfasfadsfds
</div>
<h3 class="headerText">
Test 2
</h3>
<div class="bodyText">
werrererewrwereewrwer
</div>
</div>
<div class="linkBox">
<div class="linkingText">
TEST
</div>
</div>
</div>
</div>

Related

Why is my image not scaled correctly when hovered?

I'm building a website for a side project and I need to have 2 cards, presenting someone with an image on the left and some text + another image on the right.
I want that card to be 1.1 times scaled when hovered or focused but when I do the usual method (as in the snippet), somehow the image on the right shifts a bit to the top.
/* GÉNÉRAL */
:root {
--color-accent: #4e6eff;
--color-accent-dark: #3a56d3;
--color-black: #252728;
--color-white: #fdfdff;
--color-blacker: #0c0d0d;
}
html {
scroll-behavior: smooth;
scroll-padding-top: 0;
}
body::-webkit-scrollbar {
display: none;
}
* {
font-family: Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
}
*::selection {
background-color: #4e6effba;
}
body {
background-color: var(--color-black);
color: var(--color-white);
}
/* COMMON STYLE */
.bg-accent {
background-color: var(--color-accent);
color: var(--color-white);
}
a {
color: var(--color-white);
text-decoration: none;
}
img {
width: 100%;
}
/* */
.select-membres__row--2 {
display: flex;
justify-content: space-evenly;
}
.membre-carte {
display: flex;
padding: 1em;
width: 400px;
height: 200px;
gap: 8%;
border-radius: 25px;
background-color: var(--color-blacker);
text-align: center;
scale: 1;
transition: scale 100ms ease-out;
}
.membre-carte:hover {
scale: 1.1;
transition: scale 150ms cubic-bezier(0.22, 0.47, 0.35, 0.92);
border: 3px solid var(--color-accent);
}
.membre-carte>* {
width: 50%;
}
.membre-carte .carte-pp {
border-radius: calc(25px - 0.5em);
}
.perso-cont {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.carte__nom {
font-size: 1.2rem;
}
.perso-cont .img-cont {
width: 120px;
margin-inline: auto;
display: flex;
}
<div class="select-membres__row--2">
<a href="#">
<div class="membre-carte">
<img src="https://source.unsplash.com/random/50x50" class="carte-pp">
<div class="perso-cont">
<h4 class="carte__nom">image 1</h4>
<p class="carte__surnom">lorem</p>
<div class="img-cont">
<img src="https://source.unsplash.com/random/40x40">
</div>
</div>
</div>
</a>
<a href="#">
<div class="membre-carte">
<img src="https://source.unsplash.com/random/50x50" class="carte-pp">
<div class="perso-cont">
<div>
<h4 class="carte__nom">image 2</h4>
<p class="carte__surnom">lorem</p>
</div>
<div class="img-cont">
<img src="https://source.unsplash.com/random/40x40">
</div>
</div>
</div>
</a>
</div>
The border in .membre-carte:hover consumes an extra 6px (top 3px and bottom 3px) from the total height of the cart leaving less room for the content to fit in.
Add a transparent border like .membre-carte { border: 3px solid transparent } to you CSS and the movement will disappear, because now both the unhovered vs. hovered state consume the same amount of space again.
Be aware that you will lose 6px of the carts spaces for their content to fit in.

How to adjust the size of my figure here?

I am new to HTML and CSS and I am working on a Page here for school.
I don't know how i can adjust the size of my figures Schutzklasse 1-3 with their Text. If you Zoom the text gets smaller but the basic picture not.
You dont need everything in the CSS because i have more pages. I just need help on my main page.
I tried things like width or margin and text align but it didn't work. I don't know what to do then.
I hope u can help me.
figure,
figcaption {
margin: 0;
padding: 0;
}
.gallery {
display: block;
text-align: center;
}
#gallery {
display: grid;
grid-template-columns: repeat(3, minmax(7em, 1fr));
gap: 10%;
text-align: center;
margin-left: 10%;
margin-right: 10%;
}
#gallery figure {
position: relative;
color: black;
background: white;
}
figure img {
width: 100%;
position: relative;
display: block;
}
#gallery>figure>figcaption {
position: absolute;
bottom: 0em;
width: 100%;
line-height: 2.1em;
color: white;
background: rgba(0, 0, 0, 0.7);
}
#gallery>figcaption {
grid-column: 1 / -1;
}
#gallery>figure>figcaption {
opacity: 0.4;
bottom: -3em;
transition: all 0.1s ease;
}
#gallery>figure:hover>figcaption {
opacity: 1;
bottom: -2em;
}
.m1 {
border: 3px solid #4CAF50;
padding: 5px;
margin-left: 15%;
margin-right: 15%;
margin-top: 5%;
margin-bottom: 5%;
}
.img1 {
float: right;
}
.m1::after {
content: "";
clear: both;
display: table;
}
.img1 {
height: 30%;
width: 300px;
margin-top: 2%;
margin-bottom: 4%;
margin-left: 4%;
}
.ans1 {
display: inline-block;
width: 320px;
padding: 20px;
border: 5px solid gray;
margin: 10px;
}
.a1 {
margin-left: 15%;
margin-right: 15%;
}
h2 {
margin-left: 3%;
}
ul {
margin-left: 5%;
margin-top: 8%;
}
body {
color: rgba(50, 50, 50, 1.0);
background: rgba(200, 200, 200, 0.825);
}
h1 {
text-decoration: underline;
text-decoration-color: blueviolet;
text-align: center;
margin-bottom: 2em;
}
b {
text-decoration: underline;
}
h3 {
text-shadow: 2px 2px rgb(255, 255, 255);
text-align: center;
margin-bottom: 2em;
}
h4 {
text-decoration: underline;
text-align: center;
margin-bottom: 2em;
}
<h1>Der VDE Guide</h1>
<p> </p>
<h3>Bitte wählen Sie eine der Schutzklassen:</h3>
<div class="gallery">
<figure id="gallery">
<figure>
<a href="messungSK1.1.html">
<img id="sk1" src="schutzklasse1.png">
</a>
<figcaption>Schutzklasse 1</figcaption>
</figure>
<figure>
<a href="messungSK2.1.html">
<img id="sk2" src="schutzklasse2.png">
</a>
<figcaption>Schutzklasse 2</figcaption>
</figure>
<figure>
<a href="messungSK3.1.html">
<img id="sk3" src="schutzklasse3.png">
</a>
<figcaption>Schutzklasse 3</figcaption>
</figure>
</figure>
</div>
[Ctrl-MouseScroll] or [Ctrl+]/[Ctrl-] (browser functionality) act differently compared to resizing the browser. Using the [Ctrl] zooming functions, the browser will act as if it is a different (larger/smaller) device, while resizing the the browser window just changes the available space on the given device (for now, I'm assuming your development desktop PC). This means that when you deeply zoom-in you are essentially looking at a very large smartphone.
With your CSS img {...width: 100%... } you want to scale the images to fill the maximum of the available space (on a very large smartphone), while you want the zooming to literally resize them. I don't know the technical specifics behind this, but you simply cannot have both.
So you need to choose either resize to fit and discard the zooming, or enable zooming and leave out the img {...width: 100%... } and replace it with:
figure img {
display: block; /* removes unwanted space below (default 'inline') */
object-fit: cover; /* resize and clip when too large (change to your needs) */
max-width: 100%; /* dont' go outside parent ('overflow: hidden' won't work) */
margin: 0 auto /* center horzontally in parent */
}
I have created a snippet with your code in which I added my solution, but also changed/simplified a few things:
for clarity removed unused CSS
also for clarity, moved EYE-CANDY only properties to their own section. Less optimized, but more clear CSS for the demo.
heavily commented CSS where applicable
you used <figure>s inside a <figure>, while totally legal, it unnecessarily complicated the structure of .gallery. I removed the extra layer.
changed the original grid-template-columns 3 to auto-fit so the grid nicely wraps when the viewport becomes too narrow.
corrected the gap error to grid-gap
changed the .gallery margins to padding and used margin to horizontally center .gallery
changed background to background-color where applicable. While background is legal, it is also a shortcut property for various background settings. This becomes particularly important when you want to blend/mix background-color with background-image. In specific cases background overrides one of them (depending on how you defined the CSS) obfuscating a nice little bug that could keep you busy for a while. Just get used to using background-color.
Do try out <body outlines="1"> as you will learn from the output that you have overlapping elements issues that might need to be addressed!
And the zooming now works as you want...
The snippet
/* for debugging */
[outlines="1"] * { outline: 1px dotted }
figure,figcaption { margin: 0; padding: 0 }
figure img {
display: block; /* removes unwanted space below (default 'inline') */
object-fit: cover; /* resize and clip when too large (change to your needs) */
max-width: 100%; /* dont' go outside parent */
margin: 0 auto /* center horzontally in parent */
}
.gallery {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(7em, 1fr)); /* changed 3 to 'auto-fit' */
/* original 7em, now in pct of 1920 (average desktop) => 7 * 16 / 19.2 */
grid-gap: 10%; /* MOD, was 'gap' */
text-align: center;
padding: 0 10%; /* 10% L/R space */
margin: 0 auto /* center in parent */
}
.gallery figure {
position: relative;
/* some spacing after wrap */
margin-bottom: 2em; /* modify to your needs */
}
.gallery>figure>figcaption {
position: absolute;
width: 100%;
line-height: 2.1em;
color: white;
background: rgba(0, 0, 0, 0.7);
bottom: -3em; opacity: 0.4;
transition: all 0.1s ease;
}
.gallery>figure:hover>figcaption {
bottom: -2em; opacity: 1;
}
/******************/
/* EYE-CANDY only */
/******************/
.gallery figure {
color: black; background-color: white;
}
.gallery>figure>figcaption {
color: white; background-color: rgba(0, 0, 0, 0.7);
}
body {
color: rgba(50, 50, 50, 1.0); background-color: rgba(200, 200, 200, 0.825);
}
h1 {
text-decoration: underline;
text-decoration-color: blueviolet;
text-align: center;
margin-bottom: 2em;
}
h3 {
text-shadow: 2px 2px rgb(255, 255, 255);
text-align: center;
margin-bottom: 2em;
}
<body outlines="0">
<h1>Der VDE Guide</h1>
<p> </p>
<h3>Bitte wählen Sie eine der Schutzklassen:</h3>
<div class="gallery">
<figure>
<a rel="noopener" target="_blank" href="messungSK1.1.html">
<img id="sk1" src="https://via.placeholder.com/200/DC143C/FFF8DC?text=schutzklasse1">
</a>
<figcaption>Schutzklasse 1</figcaption>
</figure>
<figure>
<a rel="noopener" target="_blank" href="messungSK2.1.html">
<img id="sk2" src="https://via.placeholder.com/200/7CFC00/000000?text=schutzklasse2">
</a>
<figcaption>Schutzklasse 2</figcaption>
</figure>
<figure>
<a rel="noopener" target="_blank" href="messungSK3.1.html">
<img id="sk3" src="https://via.placeholder.com/200/6495ED/FFF8DC?text=schutzklasse3">
</a>
<figcaption>Schutzklasse 3</figcaption>
</figure>
</div>
</body>

unable to set the exact css for login page

i want to create a login page like this : https://i.stack.imgur.com/smEWd.jpg
but what i get is :
https://i.stack.imgur.com/DvpEL.jpg
import React, { useState } from "react";
import Header from "./Header";
// import { Button, FormGroup, input, label } from "react-bootstrap";
import "./Login.css";
export default function Login1(props) {
// const [email, setEmail] = useState("");
// const [password, setPassword] = useState("");
const [user, setUser] = useState({email : "", password : ""})
function validateForm() {
return user.email.length > 0 && user.password.length > 0;
}
function handleSubmit(event) {
event.preventDefault();
}
return (
<div className="Login">
<Header person = {user}/>
<form className="modal-content animate" onSubmit={handleSubmit}>
<div><h3 align='center'>Login</h3>
</div>
<div className="Container">
<input type="text"
autoFocus
placeholder="Username"
value={user.email}
onChange={e => setUser({...user,email : e.target.value})}
/>
{/* {console.log(user)} */}
<br/>
<input type="password" placeholder="Password"
value={user.password}
onChange={e => setUser({...user,password : e.target.value})}
/>
<br/><button disabled={!validateForm()}type="submit">
Login
</button>
</div>
<div id="footer">
<button className="submit1" disabled="true" type="submit">
Sign up
</button>
<br/><button className ="submit1" disabled="true" type="submit">
Forgot Password?
</button>
</div>
</form>
</div>
);
}
#media all and (min-width: 480px) {
.Login {
padding: 120px 0;
}
.Login form {
margin: 0 auto;
max-width: 480px;
}
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 80%; /* Full width */
height: 80%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
padding-top: 100px;
}
/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 10px auto; /* 15% from the top and centered */
border: 1px solid #888;
border-radius: 15px;
width: 120%; /* Could be more or less, depending on screen size */
}
.footer {
background-color: #9fa9a3;
margin: 10px auto; /* 15% from the top and centered */
border: 1px solid #888;
border-radius: 15px;
width: 80%; /* Could be more or less, depending on screen size */
}
input[type=text], input[type=password] {
width: 100%;
padding: 10px 10px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
.container {
padding: 30px;
}
/* Set a style for all buttons */
button {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
}
h3{
font-family:"Arial Black", Gadget, sans-serif;
font-size: 30px;
}
/* Add Zoom Animation */
.animate {
-webkit-animation: animatezoom 0.0s;
animation: animatezoom 0.0s
}
#-webkit-keyframes animatezoom {
from {-webkit-transform: scale(0)}
to {-webkit-transform: scale(1)}
}
#keyframes animatezoom {
from {transform: scale(0)}
to {transform: scale(1)}
} */
form {
border: 3px solid #f0f0f0;
}
}
I tried changing the width and CSS of the code. but still i couldn't get the exact login page design. could someone help me with this?
I have added the code snippet. I am doing this using react. I have done this html code in login.js and i have attached the CSS along with.
I added a className to Login button - submit0
<button className="submit0" disabled={!validateForm()} type="submit">
Login
</button>
You've given id footer but you were using .footer in .css file, instead you've to use #footer.
Added css for background-image
.Login {
background-image: url(https://i1.wp.com/512pixels.net/downloads/macos-wallpapers-thumbs/10-12--thumb.jpg?zoom=1.25&w=640);
background-repeat: no-repeat;
background-size: cover;
padding: 120px 0;
}
Opacity to Login Form
.Login form {
margin: 0 auto;
max-width: 480px;
opacity: 0.9;
}
Removed border from .modal-content
.modal-content {
background-color: #fefefe;
margin: 10px auto; /* 15% from the top and centered */
/* border: 1px solid #888; */
border-radius: 15px;
width: 120%; /* Could be more or less, depending on screen size */
}
Footer css -
#footer {
/*background-color: #9fa9a3;
margin: 10px auto; /* 15% from the top and centered */
/* border: 1px solid #888;
border-radius: 15px; */
/*width: 100%; Could be more or less, depending on screen size */
background-color: #666;
margin-top: 10px;
border-bottom-left-radius: 11px;
border-bottom-right-radius: 11px;
}
For input field and login button, added left, right margin, border-radius and changed the width to 90%
input[type="text"],
input[type="password"] {
width: 90%;
padding: 10px 10px;
margin: 8px 24px;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
border-radius: 11px;
}
Buttons css -
.submit0 {
width: 90%;
margin: 8px 24px;
border-radius: 11px;
}
.submit1 {
background-color: inherit;
}
CodeSandbox Link
for testing is css file classes read correctly try put some custom inline styling in page and see this is work correctly if this work ok then you should check css class in main file and with inspect element check is Login.css loading on page
for inline styling : https://codeburst.io/4-four-ways-to-style-react-components-ac6f323da822

How to make this image lightbox work for both horizontal and vertical images?

I need to create an image lightbox. I basically started from this example from w3school, https://www.w3schools.com/howto/howto_js_lightbox.asp
However, it doesn't work for portrait oriented images. Eg. a landscape image is 1200x800 and a portrait can be 800x1200.
I need the images to resize responsive and work for both horizontal and vertical images.
It needs to work for all modern browsers, ios, android and also IE11.
you'll see I've added "max-width: 1200px;" to lightbox-content, which does the trick for horizontal images... but since a vertical image is 800 wide, it enlarges and the height exceeds.
<div class="lightbox">
<span class="close" onclick="closeLightbox()">×</span>
<div class="lightboxTitle">My Title</div>
<div class="lightbox-content">
<div class="slide"><img src="img1.jpg"></div>
<div class="slide"><img src="img2.jpg"></div>
<div class="slide"><img src="img2.jpg"></div>
<!-- Next/previous controls -->
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
/* The Modal (background) */
.lightbox {
display: none;
position: fixed;
z-index: 99999999;
padding-top: 60px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
}
/* Modal Content */
.lightbox-content {
position: relative;
margin: auto;
padding: 0;
width: 100%;
max-width: 1200px;
}
.lightboxTitle {
position: absolute;
top: 20px;
left: 25px;
font-size: 20px;
}
/* The Close Button */
.close {
color: white;
position: absolute;
top: 10px;
right: 25px;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #FF8511;
text-decoration: none;
cursor: pointer;
}
/* Hide the slides by default */
.slide {
display: none;
}
.slide img {
width: 100%;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
.prev {
left: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
color: #FF8511;
}
I had the same issue in one of my past projects. I solved it with this js library https://imagesloaded.desandro.com/,
It allows you to process the images after they are loaded, and you can then assign a css class to it according to the aspect ratio.
$('#container').imagesLoaded( function() {
// images have loaded
// check image height/width > 1, portrait
// check image heidht/width <= 1, square or landscape
// assign different classes for each case to handle
});
css:
.img-container {
//do whatever you need on the container
}
// keep the image classes like this
.img-container img.portrait {
height: 100%;
width: auto;
}
.img-container img.landscape {
width: 100%;
height: auto;
}

Unable to make a circle with border-radius and align it vertically with next element

Here is the outcome
What I want to achieve are
A gray circle surrounding the '<' with the letter in the center
It and 'untitled' aligns vertically to the center
However despite setting the width and height to the same size, the 'circle' still ends up in an oval shape.
The use of flex's align-items: center; also fails to achieve the alignment.
How can I fix the css? Here is a link to the sample code
html
<div class='flex-container'>
<div class='arrow-container'>
<a class='btn-icon' href='#'>
<span class='square-btn icon icon-back'></span>
</a>
</div>
<div class=title>
<a href='#'>Untitled
</a>
</div>
</div>
css
.flex-container {
display: flex;
align-items: center;
}
.icon {
font-size: 50px;
}
.icon-back::before {
content: '<';
}
.title {
margin-left: 5px;
font-size: 50px;
}
.square-btn {
height: 50px;
width: 50px;
}
.btn-icon {
padding: 5px;
border-radius: 50%;
background-color: gray;
text-decoration: none;
}
This seems to work. No changes to HTML.
.flex-container {
display: flex;
align-items: center;
}
.icon {
font-size: 50px;
}
.icon-back::before {
content: '<';
}
.title {
margin-left: 5px;
font-size: 50px;
}
.square-btn {
height: 50px;
width: 50px;
border-radius: 50%; /* new */
background-color: gray; /* new */
display: flex; /* new */
align-items: center; /* new; align arrow vertically */
justify-content: center; /* new; align arrow horizontally */
}
.btn-icon {
/* padding: 5px; <-- remove */
/* border-radius: 50%; <-- remove */
/* background-color: gray; <-- remove */
text-decoration: none;
}
<div class='flex-container'>
<div class='arrow-container'>
<a class='btn-icon' href='#'>
<span class='square-btn icon icon-back'></span>
</a>
</div>
<div class=title>
<a href='#'>Untitled
</a>
</div>
</div>
jsFiddle
This can be done with a single html element and pseude-elements. One neat advantage of making everything depend on the font-size is, that the icon scales proportionally with the font size of the link.
.link {
font-size: 50px;
margin-left: 1.1em;
}
.icon {
position: relative;
}
.icon-back::before {
content: '<';
position: absolute;
left: -.9em;
display: inline-block;
z-index: 2;
}
.icon-back::after {
content: '';
border-radius: 50%;
background-color: gray;
width: 1em;
height: 1em;
position: absolute;
top: 50%;
left: -1.1em;
/* Use translateX() and translateY()
if you care about old browsers */
transform: translate3d(0, -45%, 0);
}
<a class="link icon icon-back" href="#">Untitled</a>
Grouping classes makes things harder, also, use unicode in css content when it's not alpha-numerical text, try this:
<div class="flex-container">
<div class="arrow-container">
<a class="btn-icon" href="#">
<span class="icon-back"></span>
</a>
</div>
<div class="title">
<a href="#">Untitled
</a>
</div>
</div>
<style type="text/css">
.flex-container {
display: flex;
align-items: center;
}
.btn-icon {
font-size: 50px;
text-decoration: none;
}
.icon-back::before {
content: "\003c";
border-radius: 50%;
background-color: gray;
font-size: 40px;
height:40px;
width:40px;
vertical-align:middle;
display:inline-block;
margin-bottom:5px;
text-align:center;
}
.title {
margin-left: 5px;
font-size: 50px;
}
</style>