I want to create a card (that is an image and an overlay). The card should be with border-radius. Unfortunately, when I add it in conjunction with overflow-y: hidden, it creates some white pixels on the corners.
I have the following HTML structure and CSS code:
.container {
max-width: 80rem;
padding: 1em;
margin-inline: auto;
}
.works__column {
display: flex;
flex-direction: column;
gap: 2rem;
}
.size {
--size: 0;
width: var(--size);
height: var(--size);
}
.work {
display: grid;
overflow-y: hidden;
border-radius: .5rem;
}
.work__preview,
.work__overlay {
grid-area: 1 / 2;
}
.work__preview img {
--size: 100%;
object-fit: cover;
aspect-ratio: 2 / 1.4;
}
.work__overlay {
align-self: end;
padding-right: 1rem;
display: flex;
gap: 2rem;
justify-content: space-between;
}
.work__title {
font-weight: 600;
line-height: 1.6;
color: var(--white);
padding: .5rem 1rem;
border-start-end-radius: .5rem;
background-color: var(--steel-gray);
}
.work__icon {
flex-shrink: 0;
align-self: center;
margin-bottom: .125rem;
}
<section class="works">
<div class="container">
<div class="works__column">
<div class="works__work work">
<div class="work__preview">
<img class="size" alt="Sports Elements" src="images/works/1.jpg" />
</div>
<div class="work__overlay">
<h3 class="work__title">
Portier - The ultimate templates & components library.
</h3>
<div class="work__icon icon">0</div>
</div>
</div>
<div class="works__work work">
<div class="work__preview">
<img class="size" alt="The Coporate" src="images/works/2.jpg" />
</div>
<div class="work__overlay">
<h3 class="work__title">
The Coporate - Card for Indian Startups
</h3>
<div class="work__icon icon">1</div>
</div>
</div>
<div class="works__work work">
<div class="work__preview">
<img class="size" alt="App Interface" src="images/works/3.jpg" />
</div>
<div class="work__overlay">
<h3 class="work__title">
Components Web App Interface
</h3>
<div class="work__icon icon">2</div>
</div>
</div>
</div>
</div>
</section>
You can see the problem in these images:
However, the last card works as expected. I don't know the reason.
I think the problem is that I applied aspect-ratio with height: 100% on work__preview img. This is required because the parent has a greater hight and the overlay starts to hang from the image.
Related
I'm a bit new to front end and doing my best to figure things out. I have been building a relatively simple landing page and all looking great except when I try to use a css grid. The text (people's names) is changing the size of the images so that none of them are the same size (see the attached image). It seems that the images directly above and below each other grow together if the text is changed for one. While the images next to each other left and right change inversely. Removing all text makes them the same size.
Here is a fiddle for a runnable copy.
I would really like to set the grid to take up a percentage of the container it's in if it's possible. For the life of me I can't find what I am missing. Is there some way that I can set all images to stay the same size as one another?
I will try to include the relevant pieces of CSS.
.team {
padding: 66px 0 80px 0;
background-image: url("assets/pattern-team.png");
background-repeat: no-repeat;
background-size: contain;
background-position: center center;
width: 100%;
}
.team .container {
display: flex;
}
.team-heading {
width: 30%;
margin-right: 80px;
}
.team-heading p {
margin-top: 17px;
}
.team-members {
width: 70%;
display: grid;
grid-template-areas: "name1." "name2 name3";
gap: 30px;
row-gap: 30px;
}
.name1 {
grid-area: name1;
}
.name2 {
grid-area: name2;
}
.name3 {
grid-area: name3;
}
enter code here .team-member {
cursor: pointer;
}
.team-member .team-img {
box-shadow: 10px 10px #7CE04E;
border: 2px solid black;
}
.team-member h4 {
margin: 15px 0 5px 0;
}
.team img {
display: block;
}
<!-- Our team -->
<section class="team">
<div class="container">
<div class="team-heading">
<h2>Our team</h2>
<p>Meet the cats behind the magic.</p>
</div>
<div class="team-members">
<!-- Griff -->
<div class="team-member griff">
<div>
<img class="team-img" src="https://upload.wikimedia.org/wikipedia/commons/6/62/Solid_red.svg" />
</div>
<h4>Griff</h4>
<p>description</p>
</div>
<!-- Brenden -->
<div class="team-member brenden">
<div>
<img class="team-img" src="https://upload.wikimedia.org/wikipedia/commons/6/62/Solid_red.svg" />
</div>
<h4>Brenden</h4>
<p>description</p>
</div>
<!-- Thu -->
<div class="team-member thu">
<div>
<img class="team-img" src="https://upload.wikimedia.org/wikipedia/commons/6/62/Solid_red.svg" />
</div>
<h4>Thu</h4>
<p>description</p>
</div>
</div>
</div>
</section>
Thanks in advance for any pointers or even a suggestion of where to start searching!
Simply add column templates:
grid-template-columns: 1fr 1fr;
h4 {
font-size: 33px;
line-height: 43px;
}
.team {
padding: 66px 0 80px 0;
background-image: url("assets/pattern-team.png");
background-repeat: no-repeat;
background-size: contain;
background-position: center center;
width: 100%;
}
.team .container {
display: flex;
}
.team-heading {
width: 30%;
margin-right: 80px;
}
.team-heading p {
margin-top: 17px;
}
.team-members {
width: 70%;
display: grid;
/*Set 2 eqaul columns*/
grid-template-columns: 1fr 1fr;
grid-template-areas: "griff ." "brenden thu";
gap: 30px;
row-gap: 30px;
}
.griff {
grid-area: griff;
}
.brenden {
grid-area: brenden;
}
.thu {
grid-area: thu;
}
.team-member .team-img {
box-shadow: 10px 10px #7CE04E;
border: 2px solid black;
}
.team-member h4 {
margin: 15px 0 5px 0;
}
.team img {
display: block;
}
<!-- Our team -->
<section class="team">
<div class="container">
<div class="team-heading">
<h2>Our team</h2>
<p>Meet the cats behind the magic.</p>
</div>
<div class="team-members">
<!-- Griff -->
<div class="team-member griff">
<div>
<img
class="team-img"
src="https://upload.wikimedia.org/wikipedia/commons/6/62/Solid_red.svg"
/>
</div>
<h4>Griff</h4>
<p>description</p>
</div>
<!-- Brenden -->
<div class="team-member brenden">
<div>
<img
class="team-img"
src="https://upload.wikimedia.org/wikipedia/commons/6/62/Solid_red.svg"
/>
</div>
<h4>Brenden</h4>
<p>description</p>
</div>
<!-- Thu -->
<div class="team-member thu">
<div>
<img class="team-img" src="https://upload.wikimedia.org/wikipedia/commons/6/62/Solid_red.svg"/>
</div>
<h4>Thu</h4>
<p>description</p>
</div>
</div>
</div>
</section>
I created a cards-based horizontal scroller. And the cards are nicely scrolling inside the wrapper. The issue I'm having is that even after I applied the z-index to our member-owner-card-image, the photos still go under the card when I want to put them on the top of each card.
Is there any solution so that I can add the image on top of the card? I'm trying to fix it, but no solution has been found.
.scrolling-wrapper {
-webkit-overflow-scrolling: touch;
height: 331px;
width: 100%;
padding-inline: 40px;
position: relative;
display: flex;
flex-wrap: nowrap;
overflow-x: auto;
z-index: 0;
}
.scrolling-wrapper::-webkit-scrollbar {
display: none;
}
.card {
width: 100%;
flex: 0 0 auto;
background-color: green;
border-radius: 20px;
position: relative;
margin-right: 10px;
}
.our-member-owner-card-image {
position: absolute;
top: -30px;
z-index: 10;
}
.card-content {
position: absolute;
padding-top: 38px;
}
.member-detail {
padding-top: 55px;
line-height: 1.7;
}
.member-detail h3 {
text-align: center;
color: #263244;
font-weight: 700;
font-family: 'Lato';
}
.member-detail p {
text-align: center;
color: #737C89;
}
.member-description {
padding-inline: 20px;
color: #263244;
line-height: 1.6;
padding-top: 9px;
font-weight: 500;
font-size: 17px;
}
.member-description span {
color: red;
text-decoration: underline;
}
<div class="scrolling-wrapper">
<div class="card">
<div class="our-member-owner-card-image">
<img width="220px" src="https://images.unsplash.com/photo-1661961110144-12ac85918e40?ixlib=rb-4.0.3&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80" />
</div>
<div class="card-content">
<div class="member-detail">
<h3>Sohaib</h3>
<p>Chairman</p>
</div>
<div class="member-description">
Sohaib Ashraf has extensive work experience during his career
of more than 25 years in the financial services sector.<span
>Read more</span
>
</div>
</div>
</div>
<div class="card">
<div class="our-member-owner-card-image">
<img width="220px" src="https://images.unsplash.com/photo-1661961110144-12ac85918e40?ixlib=rb-4.0.3&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80" />
</div>
<div class="card-content">
<div class="member-detail">
<h3>Sohaib Ashraf</h3>
<p>Chairman</p>
</div>
<div class="member-description">
Sohaib Ashraf has extensive work experience during his career
of more than 25 years in the financial services sector.<span
>Read more</span
>
</div>
</div>
</div>
</div>
You could add the image as a background-image to the card. I added few examples how you can use background-image:
.card{
width: 400px;
height: 300px;
margin: 10px;
border-radius: 6px;
background-color: gray;
}
.card-1, .card-2 .image, .card-3 .image{
/* Here, we use background-image to set the image */
background-image: url("https://images.unsplash.com/photo-1661961110144-12ac85918e40?ixlib=rb-4.0.3&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80");
/* The background should be a cover photo,
so it fills the whole card: */
background-size: cover;
/* We don't want the image to repeat itself */
background-repeat: no-repeat;
/* When the ratio of the image changes, it will zoom into
this point, which we want to happen in the center of the image */
background-position: center;
}
.card-2, .card-3{
display: grid;
grid-template-rows: 1fr 1fr;
}
.card-2 .image{
border-radius: 6px 6px 0px 0px;
}
.card-3{
padding: 10px;
}
/* This is to demonstrate: */
h2{
color: white;
display: flex;
justify-content: center;
font-family: sans-serif;
}
<div class="card-1 card">
<h2>Test title</h2>
</div>
<div class="card-2 card">
<div class="image"></div>
<div class="content">
<h2> Test title</h2>
</div>
</div>
<div class="card-3 card">
<div class="image"></div>
<div class="content">
<h2> Test title</h2>
</div>
</div>
Hello Im not sure why but for some reason flexbox is not working.
I have 4 images on one section. I added flexbox wrap on the container and I also assigned flex 1
on the children images but for some reason flexbox is not working.
If anyone could help and let me know what I am doing wrong I would really appreciate it.
https://codepen.io/rubenjr005/pen/rNexOZp?editors=0100
HTML CODE
<div id="capabilities" class="bg-dark-02 py-2 angle-top-bottom-right">
<div class="capabilities-title">
<h4 class="section-title text-center">CAPABILITIES</h4>
<h3 class="lead text-center">I DO THINGS LIKE</h3>
</div>
<div class="capabilities-container">
<div class="category">
<div class="content">
<img src="img/graphic-design-icon_03.png" alt="Graphic Design" />
<div class="text-animation">
<h3 class="text-center">GRAPHIC DESIGN</h3>
</div>
</div>
</div>
<div class="category">
<div class="content">
<img src="img/Web-Design-icon_01.jpg" alt="Web Design" />
<div class="text-animation">
<h3 class="text-center">Web Design</h3>
</div>
</div>
</div>
<div class="category">
<div class="content">
<img src="img/web-development-01.png" alt="web Development" />
<div class="text-animation">
<h3 class="text-center">Web Development</h3>
</div>
</div>
</div>
<div class="category category4">
<div class="content">
<img src="img/email-development.png" alt="Email Development" />
<div class="text-animation">
<h3 class="text-center">Email Development</h3>
</div>
</div>
</div>
</div>
</div>
SCSS
#capabilities {
height: 100%;
margin-bottom: 4.5rem;
.capabilities-container {
display: flex;
flex-wrap: wrap;
// min-width: 20%;
.category {
display: flex;
// flex-direction: column;
flex: 1;
padding: 1rem;
align-items: center;
justify-content: center;
min-width: 10rem;
// width: 10rem;
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
img {
position: absolute;
top: 30%;
height: 12rem;
width: auto;
display: block;
// margin: auto;
margin-bottom: 4rem;
opacity: 0.4;
transition: 0.75s;
// padding-bottom: 4rem;
}
.text-animation {
// position: absolute;
text-align: center;
padding-top: 15rem;
transition-duration: 0.75s;
text-align: center;
left: 0;
right: 0;
// background: red;
// margin: auto;
h3 {
color: white;
text-transform: uppercase;
// margin: auto;
}
}
}
}
.category:hover .content img {
opacity: 1;
margin-bottom: 1rem;
// padding-bottom: 0rem;
// padding-bottom: 0rem;
}
.category:hover .content .text-animation {
// opacity: 1.0;
padding-top: 10rem;
}
}
}
You have to get rid of absolute positioning on your img and you'll have to use media queries.
Starting from there, you'll see the flex-wrap: wrap working.
Here is a fork : https://codepen.io/hisato/pen/vYGLLNY?editors=0100
Also, if I may add, as a general advice avoid to transition margin/padding/top/left etc. You should always look for a way to transition the transform property, it will have the best performance.
I have two columns using flexbox but does not have to use flexbox. just using it at the moment but am open to other options. The left side is content with a width of 450px and the right column I have an image that needs to behave as a background image but not use css background property. Is there a way to set the image size / image column and have it overflow out of containers and not push the left column content?
setting container widths and using relative positioning but not scaling or behaving as I would like
.row--flex {
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
width: 100%;
margin: 0;
}
.content-col--450 {
max-width: 450px;
}
.content-col {
margin-bottom: auto;
margin-top: 97px;
padding-bottom: 20px;
}
.image-col {
padding-left: 10px;
}
}
.image {
width: 100%;
height: auto;
}
<div class="container container--outer">
<div class="row--flex">
<!--content-->
<div class="content-col content-col--450">
<div class="title-row">
<h2>
testing h2
</h2>
</div>
<div class="content-row">
<p class="p-margin-bottom">
testing P
</p>
<p class="lead">
download test
</p>
<button class="button--arrow">
<span class="button--text">download now</span>
</button>
</div>
</div>
<!--end content-->
<!--image-->
<div class="image-col">
<img src="/img/right-image.png" alt="right column image" class="image-test">
</div>
<!--end image-->
</div>
column 450 stay in place and image overflow out of containers and behave as BG image
You need something like this?
.row--flex {
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
width: 100%;
margin: 0;
}
.content-col--450 {
/* max-width: 450px; */
flex-basis: 450px;
}
.content-col {
margin-bottom: auto;
margin-top: 97px;
padding-bottom: 20px;
}
.image-col {
position: relative;
flex-basis: 450px;
align-self: stretch;
padding-left: 10px;
}
.image-test {
position: absolute;
top: 0;
left: 0;
z-index: -1;
width: 100%;
height: 100%;
object-fit: cover;
}
.image {
width: 100%;
height: auto;
}
<div class="container container--outer">
<div class="row--flex">
<div class="content-col content-col--450">
<div class="title-row">
<h2>
testing h2
</h2>
</div>
<div class="content-row">
<p class="p-margin-bottom">
testing P
</p>
<p class="lead">
download test
</p>
<button class="button--arrow">
<span class="button--text">download now</span>
</button>
</div>
</div>
<div class="image-col">
<img class="image-test" src="https://picsum.photos/536/354" alt="right column image">
</div>
</div>
</div>
This should be fairly simple, however I am stumped as to why it is not working. The div (logo-and-text) inside the container (logo-wrapper) does not want to work with position absolute and the parent as position relative. If I do the individual image inside the div or the text it works.
I've tried setting the height of the container, setting margins to zero, checked in chrome dev tools.
<section id="contact-me-section">
<div id="contact-me-section-wrapper">
<div id="have-a-question-wrapper">
<h2 class="contact-h2">HAVE A QUESTION?</h2>
<div class="connect-with-me-image-wrapper">
<img class="contact-img" src="images/location.png" alt="">
<p class="contact-p">Dayton, Ohio</p>
</div>
<div class="connect-with-me-image-wrapper">
<img class="contact-img" src="images/phone.png" alt="">
<p class="contact-p">( 937 ) 336-9359</p>
</div>
<div class="connect-with-me-image-wrapper">
<img class="contact-img" src="images/email.png" alt="">
<p class="contact-p">contact#ryanjthacker.com</p>
</div>
</div>
<div id="logo-wrapper">
<div id="logo-and-text">
<img src="images/logo.png" alt="">
<p>Copyright © 2019 Ryan Thacker - All rights reserved</p>
</div>
</div>
<div id="connect-with-me-wrapper">
<h2 class="contact-h2">CONNECT WITH ME</h2>
<div class="connect-with-me-image-wrapper">
<img class="contact-img" src="images/facebook_white.png" alt="">
<p class="contact-p">Facebook</p>
</div>
<div class="connect-with-me-image-wrapper">
<img class="contact-img" src="images/linkedin_white.png" alt="">
<p class="contact-p">LinkedIn</p>
</div>
<div class="connect-with-me-image-wrapper">
<img class="contact-img" src="images/github_white.png" alt="">
<p class="contact-p">GitHub</p>
</div>
</div>
</div>
</section>
#contact-me-section {
color: white;
background-color: black;
height: auto;
width:100%;
}
#contact-me-section-wrapper {
display: flex;
text-align: center;
justify-content: center;
}
#have-a-question-wrapper {
display: flex;
flex-direction: column;
margin-bottom: 100px;
}
#logo-wrapper {
margin-left: 150px;
margin-right: 150px;
position: relative;
height: 100%;
}
#logo-and-text {
position: absolute;
bottom: 0;
}
#logo-wrapper img {
width: 116px;
margin: 10px;
}
#connect-with-me-wrapper {
display: flex;
flex-direction: column;
margin-bottom: 100px;
}
.contact-h2 {
font-size: 17px;
margin: 20px;
padding-top: 60px;
padding-bottom: 30px;
text-align: left;
}
.contact-p {
color: #989898;
margin-top:auto;
margin-bottom:auto;
font-size: 15px;
}
.contact-img {
width: 60px;
margin: 20px;
}
.connect-with-me-image-wrapper {
display: flex;
flex-direction: row;
}
I believe I have solved it, its due to using flex box. The solution is a much easier and flexible way to do it.
Instead I just used align-self: flex-end; to the container.