For some reason, the main content wont center after applying the .hidden-detail class. Here’s a picture of the result I get from applying .hidden-detail. Anyone know how I can fix this?
Hello @mkailbowdy!
I think we can get this sorted out.
Would you mind posting your CSS file?
Thanks,
Chris
I am having this issue as well, so I will post my css here rather than starting a new thread.
Here is my styles.css:
@font-face {
font-family: 'airstreamregular';
src: url('fonts/Airstream-webfont.eot');
src: url('fonts/Airstream-webfont.eot?#iefix') format('embedded-opentype'),
url('fonts/Airstream-webfont.woff') format('woff'),
url('fonts/Airstream-webfont.ttf') format('truetype'),
url('fonts/Airstream-webfont.svg#airstreamregular') format('svg');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'lakeshore';
src: url('fonts/LAKESHOR-webfont.eot');
src: url('fonts/LAKESHOR-webfont.eot?#iefix') format('embedded-opentype'),
url('fonts/LAKESHOR-webfont.woff') format('woff'),
url('fonts/LAKESHOR-webfont.ttf') format('truetype'),
url('fonts/LAKESHOR-webfont.svg#lakeshore') format('svg');
font-weight: normal;
font-style: normal;
}
html, body {
height: 100%
}
body {
display: flex;
flex-direction: column;
font-size: 10px;
background: rgb(149, 194, 215);
}
a {
text-decoration: none;
}
.main-header {
flex: 0 1 auto;
}
.main-content {
flex: 1 1 auto;
display: flex;
flex-direction: column;
}
.logo-text {
background: white;
text-align: center;
text-transform: uppercase;
font-family: lakeshore;
font-size: 37px;
}
.thumbnail-item {
min-width: 120px;
max-width: 120px;
display: inline-block;
width: 120px;
border: 1px solid rgb(100%, 100%, 100%);
border: 1px solid rgba(100%, 100%, 100%, 0.8);
}
.thumbnail-list {
flex: 0 1 auto;
order: 2;
display: flex;
justify-content: space-between;
list-style: none;
padding: 0;
white-space:nowrap;
overflow-x: auto;
}
.thumbnail-image {
display: block;
width: 100%;
}
.thumbnail-title {
display: block;
margin: 0;
padding: 4px 10px;
background: rgb(96, 125, 139);
color: rgb(202, 238, 255);
font-size: 18px;
}
.detail-image-container {
flex: 1 1 auto;
display: flex;
justify-content: center;
align-items: center;
}
.detail-image-frame {
position: relative;
text-align: center;
}
.detail-image {
width: 90%
}
.detail-image-title {
position: absolute;
bottom: -16px;
left: 4px;
font-family: airstreamregular;
color: white;
text-shadow: rgba(0, 0, 0, 0.9) 1px 2px 9px;
font-size: 40px;
}
.hidden-detail .detail-image-container {
display: none;
}
.hidden-detail .thumbnail-list {
flex-direction: column;
align-items: center;
}
.hidden-detail .thumbnail-item {
max-width: 80%;
}
@media all and (min-width: 768px) {
.main-content {
flex-direction: row;
overflow: hidden;
}
.thumbnail-list {
flex-direction: column;
order: 0;
margin-left: 20px;
}
.thumbnail-item {
max-width: 260px;
}
.thumbnail-item + .thumbnail-item {
margin-top: 20px;
}
}
I am attaching two sceenshots of the dev tools showing that the proper css styles are applied.
Correct: it works as expected on a mobile sized browser. but not when the browser is at a large width.
Hi @TitusG, it looks like you may have forgotten to remove width:120px
from .thumbnail-item
(we replaced it with min-width
and max-width
).
Hi. I add the statement as follow:
.hidden-detail .main-content {
justify-content: center;
}
and it works.
I encountered the same issue. The “justify-content: center” descendant tag worked.
Same thing I’ve had with this website here , but my team somehow resolved it. I still don’t know how. Any ideas?
I just ran into this. The justify-content
fix mostly worked (the content wasn’t quite centered), but I didn’t understand why it worked, so I wanted to figure out a flexbox-only solution. I’m sharing what I found here in case anybody’s interested.
Fix:
After a couple hours of debugging, I was able to figure out that the flex-grow
property needed to be updated (to a lesser extent the margin-left
property did too):
.hidden-detail .thumbnail-list {
flex-grow: 1; /* Allows width of .thumbnail-list to grow. */
flex-direction: column;
align-items: center;
margin-left: initial; /* Removes left margin added by the @media query. */
}
The flex-grow
property tells the browser to assign some of the remaining space to the .thumbnail-list
when there’s extra space available. The margin-left
property is being reset to its default value of 0
, overriding the 20px
value set in the @media
query. Without the margin-left
fix, the content isn’t quite visually centered – it’s slightly too far to the right.
Explanation:
When the width of the browser window was 768px or greater, the @media
query was getting triggered, changing the flex-direction
of .main-content
to row
. This lays out the .thumbnail-list
on the left and the .detail-image-container
on the right. The flex
property of .thumbnail-list
was declared earlier in styles.css
to be "0 1 auto"
. The first value, 0
, is shorthand for the flex-grow
property. A value of 0
means none of the remaining space is allocated to the element once it reaches its intrinsic size. I think this was causing all of the remaining space to be allocated to .detail-image-container
(even though it was set to display:none;
) once .thumbnail-list
reached its intrinsic size. I reproduced the issue on Chrome, Firefox, and Safari. All three browsers stopped increasing the size of the .thumbail-list
once its width reached 802px. I’m not sure how this magic number is computed but I guess this was determined be the intrinsic width of the .thumbnail-list
by all three browsers.
Anyway, that was quite a fun debugging session. Hope this helps!