I'm working on an image gallery that uses multiple section tags under the same class as links to each respective album I'm hoping to host. I'm having a problem where I'm unable to define the size of the images to fit inside of the respective sections. I'm hoping to be able to expand the page in the future and as such wouldn't like to add unnecessary lines of code where possible.
This is part of the HTML
<section class="album" style="background: url(https://images.pexels.com/photos/776390/pexels-photo-776390.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb)">
<h2 class="name">Title</h2>
<ul class="details">
<li>Shot With: </li>
<li>Location:</li>
<li>Date:</li>
</ul>
</section>
<section class="album" style="background: url(https://images.pexels.com/photos/1562/italian-landscape-mountains-nature.jpg?w=1260&h=750&auto=compress&cs=tinysrgb)">
<h2 class="name">Title</h2>
<ul class="details">
<li>Shot With: </li>
<li>Location:</li>
<li>Date:</li>
</ul>
</section>
And the CSS
.album {
display: flex;
flex-direction: column;
flex: 1 0 10em;
box-shadow: 0 0 30px #424242;
border-radius: 15px;
overflow: hidden;
padding: .9em;
color: DarkSlateGrey;
transition: flex-basis 350ms ease-in-out;
}
.album:hover {
flex-basis: 25em;
}
.album:hover .details {
opacity: 1;
}
.name {
font-size: 1.3em;
}
.details {
list-style: none;
opacity: 0;
transition: opacity 500ms ease-in-out;
}
.details li {
font-size: 1em;
line-height: 2em;
}
.album {
flex-shrink: 1;
}
I have it set for 8 sections but I made a small pen with two just to make it easier; currently the images in the pen do not fit within the bounds of their respective containers and I was hoping to both center the images and resize them to fit as such. Any help would be greatly appreciated.
If I understand correctly, you want to control the way the background-image is scaled/fitted.
Try this, note the two last lines I added:
.album {
display: flex;
flex-direction: column;
flex: 1 0 10em;
box-shadow: 0 0 30px #424242;
border-radius: 15px;
overflow: hidden;
padding: .9em;
color: DarkSlateGrey;
transition: flex-basis 350ms ease-in-out;
background-size: cover;
background-position: center;
}
There are more options for the background-size property though, you might want to check them out here.
The cover option will resize the image to cover the entire container, but it will also upscale the image if it's too small (so make sure to use images large enough) and it will also cut out some of the edges if the ratio between the image and the container is different. But in most cases it won't matter.
Here is a simple solution for this:
.album {
display: flex;
flex-direction: column;
flex: 1 0 10em;
box-shadow: 0 0 30px #424242;
border-radius: 15px;
overflow: hidden;
padding: .9em;
color: DarkSlateGrey;
transition: flex-basis 350ms ease-in-out;
}
.album:hover {
flex-basis: 25em;
}
.album:hover .details {
opacity: 1;
}
.name {
font-size: 1.3em;
}
.details {
list-style: none;
opacity: 0;
transition: opacity 500ms ease-in-out;
}
.details li {
font-size: 1em;
line-height: 2em;
}
.album {
flex-shrink: 1;
}
<section class="album" style="background: url(https://images.pexels.com/photos/776390/pexels-photo-776390.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb);background-repeat: no-repeat;background-size: 100% 100%;background-position: center; ">
<h2 class="name">Title</h2>
<ul class="details">
<li>Shot With: </li>
<li>Location:</li>
<li>Date:</li>
</ul>
</section>
<section class="album" style="background: url(https://images.pexels.com/photos/1562/italian-landscape-mountains-nature.jpg?w=1260&h=750&auto=compress&cs=tinysrgb);background-repeat: no-repeat;background-size: 100% 100%;background-position: center; ">
<h2 class="name">Title</h2>
<ul class="details">
<li>Shot With: </li>
<li>Location:</li>
<li>Date:</li>
</ul>
</section>
Related
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.
Here's how it looks on mobile devices
Here's how it looks on desktops and laptops
I'm no expert but I've been tasked with doing this, this is based on a template that I found,there is some javascript included but I really don't know where to look when it comes to javascript.
I just want them to look separated, preferably one above the other,how can I do that through css and html?
CSS and HTML
a.main-filled-button {
font-size: 13px;
border-radius: 25px;
padding: 13px 25px;
background-color: #fff;
text-transform: uppercase;
color: #000dff;
font-weight: 600;
letter-spacing: 1px;
line-height: 20px;
-webkit-transition: all 0.3s ease 0s;
-moz-transition: all 0.3s ease 0s;
-o-transition: all 0.3s ease 0s;
transition: all 0.3s ease 0s;
}
a.main-filled-button:hover {
color: #fff;
background-color: #000dff;
}
<div class="item">
<div class="img-fill">
<img src="assets/images/slide-02.jpg" alt="">
<div class="text-content">
<h3>WELCOME TO AKSM</h3>
<h5>Leading surveying company</h5>
EPAnEK 2014-2020
ΠΡΟΔΙΑΓΡΑΦΕΣ
</div>
</div>
</div>
Add margin
a.main-filled-button {
margin: 10px 0;
}
Add a media query for mobile devices in the css file
#media (max-width: 640px) {
.main-filled-button {
margin-top: 20px;
}
}
I'd be inclined to use css flex-box layout, one approach is as below with explanatory comments in the code:
/* simple CSS reset to have the browser use the same sizing calculations
for all elements across all browsers, removing default margin and
padding: */
*,
::before,
::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
/* to add visibility, a page background of white is poor contrast
against a white background for the <a> elements (adjust to taste): */
body {
background-color: lightblue;
}
/* using flex-box layout: */
div.text-content {
border: 1px solid #000;
display: flex;
/* shorthand, setting:
flex-direction: row;
flex-wrap: wrap; */
flex-flow: row wrap;
/* specifying a 1em gap between adjacent elements: */
gap: 1em;
margin: 1em;
padding: 1em;
/* setting the content vertically and horizontally centered,
shorthand for:
justify-content: center;
align-content: center; */
place-content: center;
}
h3,
h5 {
/* forcing the <h3> and <h5> elements to take 100% of
their parent element's width: */
flex-basis: 100%;
/* setting the text-alignment to center: */
text-align: center;
}
/* no changes below: */
a.main-filled-button {
font-size: 13px;
border-radius: 25px;
padding: 13px 25px;
background-color: #fff;
text-transform: uppercase;
color: #000dff;
font-weight: 600;
letter-spacing: 1px;
line-height: 20px;
transition: all 0.3s ease 0s;
}
a.main-filled-button:hover {
color: #fff;
background-color: #000dff;
}
<div class="item">
<div class="img-fill">
<img src="assets/images/slide-02.jpg" alt="">
<div class="text-content">
<h3>WELCOME TO AKSM</h3>
<h5>Leading surveying company</h5>
EPAnEK 2014-2020
ΠΡΟΔΙΑΓΡΑΦΕΣ
</div>
</div>
</div>
JS Fiddle demo.
References:
align-content.
background-color.
box-sizing.
display.
flex-basis.
flex-flow.
flex-wrap.
gap.
justify-content.
margin.
margin-block.
margin-inline.
padding.
padding-block.
padding-inline.
place-content.
text-align.
Bibliography:
"A Complete Guide to Flexbox," CSS-Tricks.
"Basic concepts of flexbox," Mozilla Developer Network.
I have a simple webpage hosted on Heroku. There are 4 images which get resized to 0x0 automatically while it shows up perfectly fine on localhost. I can't figure out what's going wrong.
What it looks like on localhost
What it looks like on heroku
The grey background is because the next section has that background which means the image's size is 0x0.
To verify, I inspected the source code through developer tools.
<div class="section2">
<div class="heading">POWERED BY</div>
<div class="logos">
<a href="https://www.jamboreeindia.com/">
<div class="sponsor-logo">
<img src="jamboree3.png" class="overlay-logo">
<img src="jamboree.png" class="original-logo">
</div>
</a>
<a href="http://www.megalogix.org/">
<div class="sponsor-logo">
<img src="mcs2.png" class="overlay-logo">
<img src="mcs.png" class="original-logo">
</div>
</a>
</div>
</div>
CSS
.section2{
width: 100vw;
padding: 5px 0 0 0;
}
.heading{
text-align: center;
font-weight: 700;
color: #9FACCC;
}
.heading2{
text-align: center;
font-weight: 700;
color: #333;
font-size: 35px;
}
.logos{
width: 100vw;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.sponsor-logo img{
width: 150px;
height: auto;
margin: 50px;
}
.original-logo {
z-index: 1;
opacity: 0;
transition: all .3s ease;
}
.overlay-logo {
position: absolute;
z-index: 3;
transition: all .3s ease;
}
.overlay-logo:hover {
opacity: 0;
transition: all .3s ease;
}
.overlay-logo:hover + .original-logo {
opacity: 1;
transition: all .3s ease;
}
Thanks!
I found out why, disable your Adblocker on that site, it's blocking the images and injecting a style to the "sponsor-logo" class
{
display: none!important;
}
I have a block called case-card which consists of a child div called case-card__wrapper that houses text.
On case-card hover, I want the case-card__wrapper to move up slightly. Not in one action, but as transition.
I feel like I have the general idea, but unsure on how to get the transition to work? At the moment, it just phases from one spot to another:
.case-card {
height: 560px;
width:600px;
color: #ededed;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
position: relative;
transform: translateY(20px);
transition: all .3s ease-in-out;
background-color: #333;
overflow: hidden;
}
.case-card__wrapper{
position: absolute;
transition: 0.5s;
/*top: 0; Don't want to add this because I want the text to be centered in the div and rather not define a number since the div heights may vary */
}
.case-card__title{
font-size: 16px;
}
.case-card:hover .case-card__wrapper {
top: 150px;
}
<div class="case-card">
<div class="case-card__wrapper">
<h4 class="case-card__title">Title</h4>
<p class="case-card__subtitle">Subtitle</p>
</div>
</div>
I'm trying to do this just via CSS. Any ideas?
If you cannot set initial value simply use transfrom. You can also remove position:absolute
.case-card {
height: 560px;
width:600px;
color: #ededed;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
position: relative;
transform: translateY(20px);
transition: all .3s ease-in-out;
background-color: #333;
overflow: hidden;
}
.case-card__wrapper{
transition: 0.5s;
}
.case-card__title{
font-size: 16px;
}
.case-card:hover .case-card__wrapper {
transform:translateY(-100%);
}
<div class="case-card">
<div class="case-card__wrapper">
<h4 class="case-card__title">Title</h4>
<p class="case-card__subtitle">Subtitle</p>
</div>
</div>
The issue I am having is with my Flexbox growing in height when I enter content inside of it. I am not 100% sure why this is happening, but I believe it has something to do with it not being in an absolute position and thus keeping its height property.
Included is the CodePen where I have the HTML and CSS setup for the Flexbox style site that I am making (Also included the Snippet below) Here is so info about it
body p {
color: white;
font-size: 30px;
margin-top: 10px !important; }
.home-wrap {
display: flex;
min-height: 100vh;
justify-content: center;
transition: background 1.5s ease-in-out; }
.home-sections {
display: flex;
flex-direction: row;
flex-wrap: wrap;
min-width: 775px;
max-width: 775px; }
.home-sections section {
border-radius: 20px;
border: 3px solid white;
overflow: hidden; }
.home-sections .flex {
display: flex;
flex-direction: row; }
.home-sections .flex--center {
justify-content: center; }
.col-1 {
text-align: center; }
.alignTop {
display: flex;
flex-direction: row;
flex-wrap: wrap;
min-width: 100%;
align-items: flex-start;
transition: opacity 1.5s ease-in-out; }
.alignCenter {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
position: relative;
width: 50%; }
.alignBottom {
display: flex;
flex-direction: row;
flex-wrap: wrap;
min-width: 100%;
align-items: flex-end;
transition: opacity 1.5s ease-in-out; }
section.about {
position: absolute;
width: 100%;
height: 220%;
left: 100%;
box-shadow: -6px 6px 8px rgba(0, 0, 0, 0.6);
z-index: 1;
transition: transform 1.5s ease-in-out;
animation: enticing-grow 2s 2;
background-color: #CB7E15; }
section.about .displayB {
display: block;
text-align: center; }
section.about .displayB h1 {
margin-top: 10px;
text-align: center;
font-size: 30px;
text-shadow: 5px 5px 8px white; }
section.about .displayB p {
font-size: 16px; }
section.about .mike-faq {
display: flex;
opacity: 0;
flex-direction: row;
justify-content: space-around;
flex-wrap: wrap;
max-width: 100%;
transition: all 1.5s ease-in-out; }
section.setup {
width: calc(55% - 6px);
height: 80%;
box-shadow: -8px 8px 8px rgba(0, 0, 0, 0.6);
background-color: #004EFF; }
section.social {
width: calc(45% - 6px);
height: 55%;
box-shadow: 8px 8px 8px rgba(0, 0, 0, 0.6);
opacity: 0.5;
transition: all 1s ease-in-out;
background-color: #585656; }
section.social:hover {
opacity: 1;
transform: scale(1.5);
z-index: 2; }
section.social .displayB {
display: block; }
section.social .displayB p {
text-align: center;
margin: 10px; }
section.social .social-wrap {
display: flex;
flex-direction: row;
max-width: 100%;
justify-content: space-around; }
section.social .social-wrap .twitter-logo {
background-image: url(/assets/img/twitter-logo.gif);
background-size: contain;
width: 55px;
height: 55px;
box-shadow: 0 5px 20px 0 #1DA1F2; }
section.social .social-wrap .email-logo {
background-image: url(/assets/img/gmail-logo.png);
background-size: contain;
width: 55px;
height: 55px;
box-shadow: 0 5px 20px 0 #E70F10; }
section.social .social-wrap .facebook-logo {
background-image: url(/assets/img/facebook-logo.png);
background-size: contain;
width: 55px;
height: 55px;
box-shadow: 0 5px 10px 5px #3C5A98; }
section.social .social-wrap .github-logo {
background-image: url(/assets/img/github-logo.png);
background-size: contain;
width: 55px;
height: 55px;
box-shadow: 0 5px 20px 0 #E04006; }
section.twitch {
width: calc(55% - 6px);
height: 80%;
box-shadow: -8px -8px 8px rgba(0, 0, 0, 0.6);
background-color: #5A3E85; }
section.twitch h1 {
margin-top: 10px;
font-size: 30px;
text-align: center; }
section.twitch p {
font-size: 16px; }
section.twitch .displayB {
display: block;
text-align: center; }
.button {
color: #5A3E85; }
section.webdesign {
width: calc(45% - 6px);
height: 53%;
box-shadow: 8px -8px 8px rgba(0, 0, 0, 0.6);
background-color: #1F843A; }
section.youtube {
position: absolute;
width: 95%;
height: 140%;
margin-right: 5px;
box-shadow: -8px 0 8px rgba(0, 0, 0, 0.6);
transition: opacity 1.5s ease-in-out;
background-color: #CC181E; }
<div class="home-wrap">
<div class="home-sections">
<div class="alignTop">
<section class="twitch">
<div class="flex flex--center displayB">
<h1>Twitch</h1>
<!-- <p>I've been livestreaming on Twitch since it's days as Justin.tv - I plan to pick it back up again once I can figure out a schedule</p> -->
</div>
</section>
<section class="webdesign">
<div class="flex flex--center">
<p>Web Design</p>
</div>
</section>
</div>
<div class="alignCenter">
<section class="youtube">
<div class="flex flex--center">
<P>YouTube</P>
</div>
</section>
<section class="about grown">
<div class="flex flex--center displayB">
<h1>What's Going on, Mike here, and Welcome to my Site!</h1>
<p>I'm your typical 26 year old nerd, who loves computers, video games, pretty much anything tech. Along with that, I have a ton of hobbies that range from playing music to stock investments. </p>
<p>I've always been interested in, and worked on my web design skills, but it wasn't until the past few months where I decided this is what I am passionate about.</p>
<p>With that said, click around the site to learn more about me. All panels are expandable clickable which will allow you to learn more about "Mike" and who I am!</p>
<div class="mike-faq">
<p>FAQ 1</p>
<p>FAQ 2 </p>
<p>FAQ 3</p>
<p>FAQ 4</p>
</div>
</div>
</section>
</div>
<div class="alignBottom">
<section class="setup">
<div class="flex flex--center">
<p>Setup</p>
</div>
</section>
<section class="social">
<div class="flex flex--center displayB">
<p>Social</p>
<div class="social-wrap">
<div class="twitter-logo"></div>
<div class="email-logo"></div>
<div class="facebook-logo"></div>
<div class="github-logo"></div>
</div>
</div>
</section>
</div>
</div>
1 - I have a wrapping div around the site content so I can control the flow and background of the back
2 - I have another wrapping div for each "Row" of Flexbox so I can have them align in different areas (Top is aligned Flex-Start, Center is aligned Flex-Center and Bottom is aligned Flex-Bottom)
3 - The 2 Center Flexboxes (YouTube and About) are set with Absolute position so I am able to have the "About" section grow out and overlap the top and bottom sections.
4 - I have all the fleboxes set with % height and width so they will scale with the window value.
5 - Inside of each FlexBox section, I have a container so that I can manipulate the content and move it around so it fits within their parent flexbox.
Now, I am not 100% sure if all the nesting and parent/child elements is the best way to handle what I am trying to do, but I haven't been able to visualize it any other way and get it work (outside of the way I am doing it).
So - to go over it again, inside of the "Twitch: panel I have a <p> section that when I uncomment, the flexbox will grow in height, rather than remain the same. However, in the "About" section, this doesn't happen. The only difference I am able to see is that the "About" section is position: absolute.
You can play around by giving alignTop, alignCenter and alignBottom heights.
http://codepen.io/anon/pen/GWEgMK : try commenting in and out what you said then find the adequates values for heights you are happy with.
.alignTop {
height:33%;}
.alignCenter {
height:25%;}
.alignBottom {
height:20%;}
Not sure that's exactly what you want but to be honnest there is way too much clutter in your codepen for us to really want to try :) Are the animations even relevant ?
rather than % heights you may want to let flexbox handle the heights for you, as in grow to the viewport as it is designed to do but then use a max-height with a vh unit rather than a % value (like max-height: 75vh instead of max-height:75%). vh uses the viewport to scale not the parent div.