I'm currently working on my code where i tried making a responsive image gallery with a hover effect. At my first code I created, the effects are working great. However, it is not responsive as it stays in 4 rows always. Please see this Codepen 1
When I tried to change some of the contents of my style.css using flexbox, i was able to make it responsive and change its size depending on the window size. However, whenever you hover to the image, the hover box does not align with the container itself. Please see this Codepen2
The codes are written on the codepen itself. The only code i changed in the 1st code to the 2nd one is this (I commented the previous code instead of removing it to remember which part i changed:
.container
{
/*width: 1280px;
margin: 70px auto 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;*/
margin: .5vw;
font-size: 0;
display: -ms-flexbox;
-ms-flexbox-wrap : wrap;
-ms-flexbox-direction: column;
-webkit-flex-flow: row wrap;
flex-flow: row wrap;
display: -webkit-box;
display: flex;
}
.container .box
{
/*position: relative;
width: 300px;
height: 300px;
background: #ff0;
margin: 10px;
box-sizing: border-box;
display: inline-block;*/
-webkit-box-flex: auto;
-ms-flex: auto;
flex: auto;
width: 300px;
margin: .5vw;
}
.container .box .imgBox img
{
/*max-width: 100%;*/
width: 100%;
height: auto; /*added this*/
transition: transform 2s;
}
Please do help me figure out why the hover position is not working. Thanks
You could modify the width's of the container so that it size is defined by relative positioning, this will solve your issue.
The only change that is to be made is to the div with class container, shown below.
.container {
width: 80%;
margin: 0px auto;
display: flex;
flex-direction: row;
justify-content: center;
flex-wrap: wrap;
}
Please check the below example.
body {
margin: 0;
padding: 0;
background: #262626;
font-family: sans-serif
}
.container {
width: 80%;
margin: 0px auto;
display: flex;
flex-direction: row;
justify-content: center;
flex-wrap: wrap;
}
.container .box {
position: relative;
width: 300px;
height: 300px;
background: #ff0;
margin: 10px;
box-sizing: border-box;
display: inline-block;
}
.container .box .imgBox {
position: relative;
overflow: hidden;
}
.container .box .imgBox img {
max-width: 100%;
transition: transform 2s;
}
.container .box:hover .imgBox img {
transform: scale(1.2);
}
.container .box .details {
position: absolute;
top: 10px;
left: 10px;
bottom: 10px;
right: 10px;
background: rgba(0, 0, 0, .8);
transform: scaleY(0);
transition: transform .5s;
}
.container .box:hover .details {
transform: scaleY(1);
}
.container .box .details .content {
position: absolute;
top: 50%;
transform: translateY(-50%);
text-align: center;
padding: 15p;
color: #fff;
}
.container .box .details .content h1 {
margin: 0;
padding: 0;
font-size: 20px;
color: #ff0;
}
.container .box .details .content p {
margin: 10px 0 0;
padding: 0;
}
<div class="container">
<div class="box">
<div class="imgBox">
<img src="http://www.gstatic.com/webp/gallery/1.jpg">
</div>
<div class="details">
<div class="content">
<h1> Snow Queen Elsa </h1>
<p>Elsa is the daughter of Agnarr and Iduna, older sister of Anna, and queen of Arendelle. Elsa was born with the powers to manipulate ice and snow and used them to entertain her sister. </p>
</div>
</div>
</div>
<div class="box">
<div class="imgBox">
<img src="http://www.gstatic.com/webp/gallery/2.jpg">
</div>
<div class="details">
<div class="content">
<h1> The Little Mermaid Ariel </h1>
<p>Ariel as she appears in her mermaid form in Disney's The Little Mermaid. Ariel is a fictional character and the title character of Walt Disney Pictures' 28th animated film The Little Mermaid (1989). She is often rebellious, and in the first film,
she longs to be a part of the human world. </p>
</div>
</div>
</div>
<div class="box">
<div class="imgBox">
<img src="http://www.gstatic.com/webp/gallery/3.jpg">
</div>
<div class="details">
<div class="content">
<h1> Sleeping Beauty Aurora </h1>
<p>Princess Aurora, also known as Sleeping Beauty or Briar Rose, is a fictional character who appears in Walt Disney Pictures' animated feature film Sleeping Beauty (1959). Originally voiced by singer Mary Costa, Aurora is the only daughter of King
Stefan and Queen Leah. </p>
</div>
</div>
</div>
<div class="box">
<div class="imgBox">
<img src="http://www.gstatic.com/webp/gallery/4.jpg">
</div>
<div class="details">
<div class="content">
<h1> Aladdin's Jasmine </h1>
<p>Princess Jasmine is the deuteragonist of Disney's 1992 animated feature film, Aladdin. She is from the Middle Eastern kingdom of Agrabah where her father, the Sultan, rules. Jasmine was born into a role and society that treats her as an object
and a tool, rather than a person </p>
</div>
</div>
</div>
<div class="box">
<div class="imgBox">
<img src="http://www.gstatic.com/webp/gallery/5.jpg">
</div>
<div class="details">
<div class="content">
<h1> Rupunzel </h1>
<p>Princess Rapunzel (voiced by Mandy Moore) is more assertive in character, and was born a princess. Her long blonde hair has magical healing and restoration powers. A woman named Mother Gothel (voiced by Donna Murphy) kidnaps Rapunzel for her magical
hair which would help maintain her youth. </p>
</div>
</div>
</div>
<div class="box">
<div class="imgBox">
<img src="http://www.gstatic.com/webp/gallery/5.jpg">
</div>
<div class="details">
<div class="content">
<h1> Megara </h1>
<p>In Greek mythology, Megara was the oldest daughter of Creon, king of Thebes. Megara was offered by her father to Hercules because he defended Thebes. She had two children, a boy and a girl, but was killed with both of them by Hercules in excess
of madness caused by Hera. </p>
</div>
</div>
</div>
<div class="box">
<div class="imgBox">
<img src="c">
</div>
<div class="details">
<div class="content">
<h1> Belle The Beauty </h1>
<p>Belle is a fictional character who appears in Walt Disney Pictures' animated feature film Beauty and the Beast (1991). Originally voiced by American actress and singer Paige O'Hara, Belle is the non-conforming daughter of an inventor who yearns
to abandon her predictable village life in return for adventure. </p>
</div>
</div>
</div>
<div class="box">
<div class="imgBox">
<img src="http://www.gstatic.com/webp/gallery/1.jpg">
</div>
<div class="details">
<div class="content">
<h1> Mulan The Great Warrior Of China </h1>
<p>Mulan (full name Fa Mulan) is a character, inspired by an actual historic figure, who appears in Walt Disney Pictures' animated feature film Mulan (1998), as well as its sequel Mulan II (2004). </p>
</div>
</div>
</div>
</div>
Related
I will put here some code for better understanding my need.
.wrap{
display:flex;
flex-direction:row;
align-items: center;
justify-content: flex-start;
width: 100%;
}
.img{
width: 30px;
height: 20px;
background: red;
}
.img1{
width:40px;
}
<div class='wrap'>
<div class='img img1'>
</div>
<p>
Xxxxxxxxxxxxx
</p>
</div>
<div class='wrap'>
<div class='img'>
</div>
<p>
yyyyyyyyy
</p>
</div>
<div class='wrap'>
<div class='img'>
</div>
<p>
zzzzzz
</p>
</div>
So as u can see, we have 3 div & p elements. I want to separate this elements with identical gap between them. I want separate red div from text. As u notice, first element is longer than rest. I wouldn't like to use static margin or padding value. Exist better solution?
You need a container that defines the width of all children. Then, you can set justify-content: space-between on .wrap, so the text and the red rectangle will get away from each other.
Then, add a gap property to .wrap, so you'll have a basic gap between the elements to start with.
Here's your snippet with the new adjustments:
.container {
display: flex;
flex-direction: column;
max-width: fit-content;
}
.wrap {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
gap: 1em;
width: 100%;
}
.img {
width: 30px;
height: 20px;
background: red;
}
.img1 {
width: 40px;
}
<div class="container">
<div class='wrap'>
<div class='img img1'>
</div>
<p>
Xxxxxxxxxxxxx
</p>
</div>
<div class='wrap'>
<div class='img'>
</div>
<p>
yyyyyyyyy
</p>
</div>
<div class='wrap'>
<div class='img'>
</div>
<p>
zzzzzz
</p>
</div>
</div>
So I create a container div, then I create a top and bottom div, in the bottom I create 2 more divs, to put separeted items, but, in the middle of them it's a border that a didn't put there, I tried the same code only with divs (whitout text) to see, and it didn't has the border in the middle of them, so, anyone knows why?
Here's my code:
<div class="container">
<div class="top-text">
<h1>Join our community</h1>
<h3>30-day, hassle-free money back guarantee</h3>
<p>Gain access to our full library of tutorials along with expert code reviews. Perfect for any developers who are serious about honing their skills.</p>
</div>
<div class="bottom-text">
<div class="month-sub">
<h3 class="month-sub-title">Monthly Subscription</h3>
<p class="p-dollar"><span class="dollar">$29</span> per month</p>
<p>Full access for less than $1 a day</p>
<button class="btn-sign">Sign Up</button>
</div>
<div class="why-us">
<h3 class="why-us-title">Why Us</h3>
<ul class="specs">
<li>Tutorials by industry experts</li>
<li>Peer & expert code review</li>
<li>Coding exercises</li>
<li>Access to our GitHub repos</li>
<li>Community forum</li>
<li>Flashcard decks</li>
<li>New videos every week</li>
</ul>
</div>
</div>
</div>
.container{
width: 44%;
display: flex;
flex-direction: column;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
overflow: hidden;
border-radius: 10px;
}
.top-text{
background-color: #ffffff;
padding: 35px;
color: var(--cyan);
}
.bottom-text{
display: flex;
justify-content: center;
width: 100%;
color: #ffffff;
}
.month-sub{
width: 50%;
padding: 35px;
background-color: var(--cyan);
}
.why-us{
width: 50%;
padding: 35px;
background-color: var(--grayishBlue);
}
The border
The div I create with the same things, but didn't have the border
I guess it can be due to wrong use of flexbox. If you use display: flex; you shoul use flex: 0 1 50%; in child to benefit from it.
.parent{
display: flex;
}
.child{
//this
flex: 0 1 50$;
//is equivalent of this
flex-grow: 0
flex-shrink: 1;
flex-basis: 50%;
}
My second guess it's box-sizing or some styles are being inherited...
Anyway maybe it'll help you
https://codepen.io/jerrykck/pen/eYZbpGN
I know how to wrap items (in theory) but I must be doing something wrong. These are refusing.
I just want two profiles, side by side, that stack into a column when the window width shrinks. At the moment, they sort of squish together and overlap.
#profile-container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-content: center;
padding-bottom: 5%;
}
.profile-desc {
width: 35%;
margin: 5% 5%;
text-align: center;
}
#profileM {
height: 230px;
width: 219px;
}
#profileF {
height: 230px;
width: 219px;
}
<div id="profile-container">
<div class="profile-desc" style="float:left;width:35%;padding: 5px;">
<img src="images/male.jpg" id="profileM">
<h3 style="color:white;background-color:rgb(244,212,69);">
Name
</h3>
<h4 style="color: rgb(244,212,69);">
Occupation
</h4>
<p>
Description
</p>
</div>
<div class="profile-desc" style="float:right;width:35%; padding: 5px;">
<img src="images/female.jpg" id="profileF">
<h3 style="color:white;background-color:rgb(244,212,69);">
Name
</h3>
<h4 style="color: rgb(244,212,69);">
Occupation
</h4>
<p>
Description
</p>
</div>
</div>
What you are looking for is CSS media queries, it allows you to apply CSS when some conditions about the device (width or orientation for example) are met.
I tweaked your code adding a media query line (also I removed some not needed flex properties and removed some redundant inline styling on .profile-desc)
#profile-container {
padding-bottom: 5%;
}
.profile-desc {
float: left;
width: 35%;
margin: 5% 5%;
text-align: center;
}
#profileM {
height: 230px;
width: 219px;
}
#profileF {
height: 230px;
width: 219px;
}
#media(max-width: 580px) {
.profile-desc {
width: 100%;
margin: 0;
}
}
<div id="profile-container">
<div class="profile-desc">
<img src="images/male.jpg" id="profileM">
<h3 style="color:white;background-color:rgb(244,212,69);">
Name
</h3>
<h4 style="color: rgb(244,212,69);">
Occupation
</h4>
<p>
Description
</p>
</div>
<div class="profile-desc">
<img src="images/female.jpg" id="profileF">
<h3 style="color:white;background-color:rgb(244,212,69);">
Name
</h3>
<h4 style="color: rgb(244,212,69);">
Occupation
</h4>
<p>
Description
</p>
</div>
</div>
You could avoid the media query and rely on flexbox adaptability by telling it the size of the content. flex-basis: content achieves the same result but it is not widely supported.
The relevant change is:
.profile-desc {
flex-basis: 35%;
}
This question already has answers here:
Equal height children of flex items
(2 answers)
Closed 3 years ago.
I'm trying to achieve a flexbox, where the row will have the titles all lined up. Requirements:
The images won't always be the same height
The description won't always be the same height
The title could be 1 row, or 3 (depending on the length)
Here is a simple fiddle:
https://jsfiddle.net/youradds/r56j4uLe/6/
As you can see this is what you get:
This is more what I'm after:
My SCSS is:
#item-wrapper {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
.item-block {
background: yellow;
flex-grow: 0;
width: 350px;
margin: 2rem 1rem;
display: flex;
flex-direction: column;
justify-content: space-between;
align-content: center;
align-items: center;
.what-logo {
img {
max-height: 100%;
}
}
.text-info {
flex-grow: 1;
.desc {
padding: 1rem;
}
h2 {
flex-grow: 0;
}
}
.action-button {
margin: 0 auto;
}
}
}
.pure-img {
max-width: 100%;
height: auto;
display: block;
}
..and test HTML:
<div id="item-wrapper">
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/3/3-1562951826-3.png" class="pure-img">
</div>
<div class="text-info">
<h2>Zydrunas Savickas Seminar</h2>
<div class="desc">Bodywise Gym and Studios are proud to announce we are bringing the greatest strongman Zydrunas Savickas (Big Z) to Horsham for a seminar.</div>
</div>
Find out more »
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/7/7-1562936970-7.jpg" class="pure-img">
</div>
<div class="text-info">
<h2>Class for mums</h2>
<div class="desc">Join Quick HIIT</div>
</div>
Find out more »
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/6/6-1562936464-6.png" class="pure-img">
</div>
<div class="text-info">
<h2>Gratitude Day</h2>
<div class="desc">To spread the positivity you can bring a training partner along to workout with you or to attend one of our classes.</div>
</div>
Find out more »
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/4/4-1562951950-4.jpg" class="pure-img">
</div>
<div class="text-info">
<h2>The experience of non-duality</h2>
<div class="desc">Yoga & meditation workshop with Indian Spiritual Master Acharya Shree Shankar </div>
</div>
Find out more »
</div>
</div>
Important note: This is a responsive design, so I can't set a height on the image div (i.e min-height 600px) because while this kind of sorts it on wider screens:
...but then on smaller screens, it scales down to 1 element per row - and this then means we have a silly amount of padding between the image and the title on the entries with smaller images:
you could look for a visual compromise.
flex children do not align with flex children from another flex parent.
You may try centering tex-info and what-logo and add an average min-height on .desc
Demo below, play it in full page to test behavior and visual.
#item-wrapper {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
}
#item-wrapper .item-block {
background: yellow;
max-width: 350px;
margin: 2rem 1rem;
padding:2px;/* see me */
display: flex;
flex-direction: column;
align-items: center;
}
#item-wrapper .item-block .what-logo img {
max-height: 100%;
}
#item-wrapper .item-block .text-info,
#item-wrapper .item-block .what-logo {/* update */
margin-top: auto;
}
#item-wrapper .item-block .text-info .desc {
padding: 1rem;
min-height: 4em;/* 3 lines , average */
}
#item-wrapper .item-block .text-info h2 {text-align:center}
#item-wrapper .item-block .action-button {
margin: 0 auto;
}
.pure-img {
max-width: 100%;
height: auto;
display: block;
}
<div id="item-wrapper">
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/3/3-1562951826-3.png" class="pure-img">
</div>
<div class="text-info">
<h2>Zydrunas Savickas Seminar</h2>
<div class="desc">Bodywise Gym and Studios are proud to announce we are bringing the greatest strongman Zydrunas Savickas (Big Z) to Horsham for a seminar.</div>
</div>
Find out more »
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/7/7-1562936970-7.jpg" class="pure-img">
</div>
<div class="text-info">
<h2>Class for mums</h2>
<div class="desc">Join Quick HIIT</div>
</div>
Find out more »
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/6/6-1562936464-6.png" class="pure-img">
</div>
<div class="text-info">
<h2>Gratitude Day</h2>
<div class="desc">To spread the positivity you can bring a training partner along to workout with you or to attend one of our classes.</div>
</div>
Find out more »
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/4/4-1562951950-4.jpg" class="pure-img">
</div>
<div class="text-info">
<h2>The experience of non-duality</h2>
<div class="desc">Yoga & meditation workshop with Indian Spiritual Master Acharya Shree Shankar </div>
</div>
Find out more »
</div>
</div>
forked fiddle
I have a paragraph element. This paragraph has a column-count css property to it. I am attempting to make my columns from my paragraph element and also expand the width of its parent container.
You can see a demo of the problem here: https://codepen.io/Fallenstedt/pen/JJvyxe
The parent container, the pink box, does not expand in width. The paragraph content is falling out of the pink box.
Is there a way to communicate the width of the paragraph element to the parent container, the pink box?
This preview is best viewed on full screen.
html {
background-color: black;
color: white;
}
.green {
border: 2px solid green;
}
.red {
border: 5px dashed red;
padding: 10px;
}
.pink {
border: 2px solid pink;
pardding: 2px;
}
.blue {
border: 2px solid blue;
}
.container {
height: 250px;
width: 90%;
}
.scrolling-container {
height: inherit;
width: 100%;
overflow-x: scroll;
/* overflow-y: hidden; */
display: flex;
}
.item-container {
display: flex;
height: 210px;
flex-direction: row;
align-items: flex-start;
flex-wrap: wrap;
margin: auto;
}
.vertical-lr {
writing-mode: vertical-lr;
}
.item {
writing-mode: initial;
height: 60px;
width: 250px;
}
.story-container {
height: inherit;
}
.story {
height: 100px;
font-size: 14px;
width: 100%;
column-count: 2;
column-width: 200px;
}
<div class="container red">
<div class="scrolling-container blue">
<div class="item-container vertical-lr pink">
<div class="item green"></div>
<div class="item green"></div>
<div class="item green"></div>
<div class="item green"></div>
<div class="item green"></div>
<div class="item green"></div>
<div class="item green"></div>
</div>
<div class="item-container pink">
<div class="story-container">
<h1>Cool Story</h1>
<p class="story">
Leave it to Run the Jewels to find the connection between psychedelic drugs and systemic disorder. The new video for "Legend Has It," the first from the duo's third LP RTJ3, finds Killer Mike and El-P tripping on acid in a police lineup alongside a rotating cast of unusual suspects: a nun, an "innocent" little girl, a fireman, even a clown-faced police officer.
Directed by Brian Beletic, the treatment intentionally "plays with the theme of guilty until proven innocent," he says. "We live in a world where the stronger the truth the greater the opposition. In this story EL-P and Killer Mike are in a police lineup and the cards are stacked heavily against them. But why is that?"
Leave it to Run the Jewels to find the connection between psychedelic drugs and systemic disorder. The new video for "Legend Has It," the first from the duo's third LP RTJ3, finds Killer Mike and El-P tripping on acid in a police lineup alongside a rotating cast of unusual suspects: a nun, an "innocent" little girl, a fireman, even a clown-faced police officer.
</p>
</div>
</div>
</div>
</div>