why is this div shrinking ?

*{
box-sizing: border-box;
padding: 0;
margin: 0;
}

/* .parent{
background-color: #23424A;
padding: 50px;
width: 80%;
margin: 0 auto;
}

.child{
background-color: cyan;
height: 300px;
width: 750px;
} */

.container{
background-color: #23424A;
padding: .5rem;
color: yellow;
border: solid 2px black;
}

.card {
border-radius: 10px;
background-color: black;
padding: .5rem;
color: white;
width: 450px;
margin: 4rem 0rem;
}

.card > img {
border-radius: 10px;
display: block;
width: 100%;
object-fit: cover;
}
.card > p{
color: #7f7b7b;
margin: .6rem 0;
}
.card > h2 {
margin-top: 10px;
}
.card > button {
background-color: orangered;
border: none;
color: white;
padding: .5rem 0;
border-radius: 10px;
font-weight: bold;
}
*{
box-sizing: border-box;
padding: 0;
margin: 0;
}

/* .parent{
background-color: #23424A;
padding: 50px;
width: 80%;
margin: 0 auto;
}

.child{
background-color: cyan;
height: 300px;
width: 750px;
} */

.container{
background-color: #23424A;
padding: .5rem;
color: yellow;
border: solid 2px black;
}

.card {
border-radius: 10px;
background-color: black;
padding: .5rem;
color: white;
width: 450px;
margin: 4rem 0rem;
}

.card > img {
border-radius: 10px;
display: block;
width: 100%;
object-fit: cover;
}
.card > p{
color: #7f7b7b;
margin: .6rem 0;
}
.card > h2 {
margin-top: 10px;
}
.card > button {
background-color: orangered;
border: none;
color: white;
padding: .5rem 0;
border-radius: 10px;
font-weight: bold;
}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>

<body>
<div class="container">
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Facilis voluptatem qui magnam. Adipisci voluptas totam
veniam iusto voluptatum. Similique commodi officia ratione rerum, repudiandae, inventore, eum accusamus vero
impedit qui necessitatibus fuga minus tenetur? Eum ipsam deleniti tempore ut placeat ducimus neque, dolor,
pariatur, doloremque ipsa corporis. Exercitationem, nemo distinctio!
</div>

<div class="card">
<img src="./luffy.jpg" alt="">
<h2>Anime Guess Quest</h2>
<p>Shown a series of anime character, pick the correct name of each character</p>
</div>

</body>

</html>
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>

<body>
<div class="container">
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Facilis voluptatem qui magnam. Adipisci voluptas totam
veniam iusto voluptatum. Similique commodi officia ratione rerum, repudiandae, inventore, eum accusamus vero
impedit qui necessitatibus fuga minus tenetur? Eum ipsam deleniti tempore ut placeat ducimus neque, dolor,
pariatur, doloremque ipsa corporis. Exercitationem, nemo distinctio!
</div>

<div class="card">
<img src="./luffy.jpg" alt="">
<h2>Anime Guess Quest</h2>
<p>Shown a series of anime character, pick the correct name of each character</p>
</div>

</body>

</html>
No description
78 Replies
Bismuth
BismuthOPā€¢12mo ago
Why my text div is shrinking ? if I remove my card div it's responsive and works fine.
Bismuth
BismuthOPā€¢12mo ago
No description
Mannix
Mannixā€¢12mo ago
can't recreate your issue with provided code https://codepen.io/MannixMD/pen/oNVxyyw
MarkBoots
MarkBootsā€¢12mo ago
i think it is because of the 450px width of the card with a screen 342px. the card is overflowing the width. the div is only 100%
Mannix
Mannixā€¢12mo ago
but that shouldn't impact the div above the card will just overflow
MarkBoots
MarkBootsā€¢12mo ago
the screen is scrolled horizontally i think
Bismuth
BismuthOPā€¢12mo ago
width of card ?
Mannix
Mannixā€¢12mo ago
try changing width to max-width
Bismuth
BismuthOPā€¢12mo ago
but the above div doesn't have any width
Mannix
Mannixā€¢12mo ago
in the card
Bismuth
BismuthOPā€¢12mo ago
why card is affecting above div ?
MarkBoots
MarkBootsā€¢12mo ago
it isn't. the div is 100% = 342px. but the card is larger
Bismuth
BismuthOPā€¢12mo ago
then why div is shrinking ? šŸ˜­
MarkBoots
MarkBootsā€¢12mo ago
it is not shrinking
Pi, a future fluent jp speaker
The problem. Is the ".card" thing because it uses a quite large fixed width Try changing it to min(400px, 100%)
Bismuth
BismuthOPā€¢12mo ago
its shrinking
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
the card is set to 450px the div is set to 100% mobile phones try to make shitty websites usable so, they show the entire viewport by default
MarkBoots
MarkBootsā€¢12mo ago
No description
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
at anything smaller than 450px, the div will "shrink"
MarkBoots
MarkBootsā€¢12mo ago
the emulation of the mobile view is a bit strange. think you manualy dragged it
Bismuth
BismuthOPā€¢12mo ago
yes
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
on an android phone will show the same
Bismuth
BismuthOPā€¢12mo ago
No description
Bismuth
BismuthOPā€¢12mo ago
still same
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
just set a max-width to 100dvw on the .card
Bismuth
BismuthOPā€¢12mo ago
it worked but how ? im struggling with css so hard šŸ˜­ .
MarkBoots
MarkBootsā€¢12mo ago
because 450 is larger than 390
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
because it is no longer 450px on a 320px viewport
Mannix
Mannixā€¢12mo ago
setting fixed width kills responsiveness
Bismuth
BismuthOPā€¢12mo ago
if i don't do that image will kill it
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
then you set a max width or use grid/float for a proper layout
Mannix
Mannixā€¢12mo ago
that's why you do the reset img{max-width: 100%; display:block;}
Bismuth
BismuthOPā€¢12mo ago
No description
Bismuth
BismuthOPā€¢12mo ago
i have width:100% and its workes fine but when i remove width:100% it breaks
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
just do what i said
Bismuth
BismuthOPā€¢12mo ago
also i have a doubt if my image breaks image should only overflow why is above div affected by it ? i did it worked but i wanna understand
MarkBoots
MarkBootsā€¢12mo ago
if you set (max)width in percentage it is relative to the container/window. without it, it will take the orginal size of the image
Bismuth
BismuthOPā€¢12mo ago
yes in this case image should overflow why is the above div shrinking ?
Pi, a future fluent jp speaker
When you set it a width in px, it will always be that width If you set it to a relative unit like %, it'll scale with the parents size
Bismuth
BismuthOPā€¢12mo ago
but the above div doesn't have any width
MarkBoots
MarkBootsā€¢12mo ago
it is not shrinking. it has the 100% width.
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
https://discord.com/channels/436251713830125568/1193598297760333954/1193601489038475416 read that it is working perfectly fine it isn't shrinking
Bismuth
BismuthOPā€¢12mo ago
oh yes i understood now, but if my device width is less then 450px then how card is trying to get that 450px ?
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
you set it manually .card { border-radius: 10px; background-color: black; padding: .5rem; color: white; width: 450px; margin: 4rem 0rem; }
Bismuth
BismuthOPā€¢12mo ago
yes yes I understood now, thank you so much!
MarkBoots
MarkBootsā€¢12mo ago
No description
Bismuth
BismuthOPā€¢12mo ago
what are some bad partices according to you which can break responsiveness ? and when should i use what unit ?
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
setting fixed widths except for borders and stuff, that tends to break stuff
Bismuth
BismuthOPā€¢12mo ago
so when working with width i should always go with relative uint ?
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
setting a width on things also sometimes breaks stuff well, yes and no
MarkBoots
MarkBootsā€¢12mo ago
restrict the size by setting a maximum width is okay
Bismuth
BismuthOPā€¢12mo ago
i have one more question to ask
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
this can be combatted by having a proper layout using grid or float
MarkBoots
MarkBootsā€¢12mo ago
absoluetely
Bismuth
BismuthOPā€¢12mo ago
No description
Bismuth
BismuthOPā€¢12mo ago
Waitlyst - Free Waitlist Template for Framer
Waitlyst is a visually appealing and sleek Framer Template tailored to expedite the process of establishing a Waitlist and generating leads.
Bismuth
BismuthOPā€¢12mo ago
here in this website the Joint the waitlist text is always splitted in two parts, i mean Join the WaitList for \n Framerlt Today but when i try to implement it, i shrinked the width until framerlt Today went down
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
probably a <wbr>
Bismuth
BismuthOPā€¢12mo ago
i mean next line
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
you can check how it's done in the browser just right-click > inspect element
Bismuth
BismuthOPā€¢12mo ago
I'm so poor with css, how can i improve it ?
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
practicing
Bismuth
BismuthOPā€¢12mo ago
I mostly work with backend but when it comes to my side project i need to work on both frontend and backend and working with css makes things lot harder
MarkBoots
MarkBootsā€¢12mo ago
on that website it is going to the new line just because it has a normal wrap. there isn't enough space for it on 1 line
Bismuth
BismuthOPā€¢12mo ago
also how do you approach responsiveness ? create whole page and work on responsiveness or component by component ?
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
me? i use an existing platform
Bismuth
BismuthOPā€¢12mo ago
existing platform ?
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
why do all the work if there's something that already exists that has it done by default?
Bismuth
BismuthOPā€¢12mo ago
what do you mean by existing platform ? templates ?
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
but if i had to do it from scratch, i would design it on figma yes and no there's stuff like 960grid
Bismuth
BismuthOPā€¢12mo ago
do you buy templates
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
no, i can make my own, but i bough a few for work
Bismuth
BismuthOPā€¢12mo ago
what is 960 grid ?
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
an old css start point for responsivity all i need to worry about is everything else, and not the layout
Bismuth
BismuthOPā€¢12mo ago
do you use any css framework ? like tailwind,bootstrap
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
depends on the situation, i use bootstrap but learn the basics first
Bismuth
BismuthOPā€¢12mo ago
I've been doing web development for the past 2-3 years, but when I have to work with CSS, I find myself struggling and feeling overwhelmed
į¼”ĻĻ‰Ļ‚
į¼”ĻĻ‰Ļ‚ā€¢12mo ago
practice more
Want results from more Discord servers?
Add your server