Flexbox column wrap is not equal width - html

I've created a simple masonry layout using flexbox column wrap, however I've noticed that the column with "Film/TV" and "Pop" is significantly smaller than the others.
How can I force each column to have approximately the same width?
Here's my CSS code:
& .masonry-layout {
display: -webkit-box;
display: flex;
flex-flow: column wrap;
width: 100%;
height: 730px;
& .item {
background-repeat: no-repeat;
background-size: cover;
box-sizing: border-box;
border-radius: var(--theme-border-radius);
display: flex;
flex-direction: column;
padding: 10px;
margin: 0 5px;
margin-bottom: 10px;
& .item__content {
align-self: flex-end;
flex-direction: row;
width: 100%;
box-sizing: border-box;
color: var(--theme-color-white);
font-size: calc(var(--teft-typography-base) * 0.75);
font-weight: bold;
text-transform: uppercase;
}
& .svg {
display: flex;
flex-direction: row;
flex-grow: 2;
justify-content: center;
width: 100%;
}
}
}
Here's the HTML:
<div class="masonry-layout">
<div class="item" style="background-image:url('<?php echo esc_url( get_stylesheet_directory_uri() ); ?>/assets/images/landing-page/browse-library/>
<div class="svg">
<?php if (!empty ( $item->svg ) ) { echo ( $item->svg ); } ?>
</div>
<div class="item__content">
<span><?php echo esc_html( $item->text ); ?></span>
</div>
</div>
</div>

When I removed the span element, everything was sized as expected.

set a minimum width ( or / and ) maximum width to keep them similar or the same size.

Related

Css flex layout not aligning aligning items as desired

I am trying to position Author designation under Author name, i tried few thing since theme is using flex i find it hard to make it work.
This them is using flex all over the place and if change one thing it breaks other thing.
How can i place Author Designation under the Author Name with minimal css changes
https://codepen.io/KGuide/pen/OJJBzmp
.article-container .article-thumbnail-wrapper {
height: 480px;
height: auto;
}
.article-thumbnail-info {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
position: absolute;
width: 100%;
left: 0;
bottom: 20px;
padding: 0 15px;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-align-items: flex-start;
-ms-flex-align: start;
align-items: flex-start;
-webkit-justify-content: flex-start;
-ms-flex-pack: start;
justify-content: flex-start;
}
.article-author {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
text-decoration: none !important;
}
.article-author figure {
margin: 0;
width: 50px;
height: 50px;
margin-right: 18px;
}
.article-author figure img {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 50%;
}
Just wrapped two spans to div and aligned it to column with flex property:
https://codepen.io/Nevados/pen/mddzpYw
If the width of the image is static you can consider some margin trick. The 68px I am using is the width+margin for the image.
I removed some CSS to keep only the relevant one
.article-author {
display: flex;
flex-wrap: wrap; /* added */
/*align-items:center; removed */
text-decoration: none !important;
}
.article-author figure {
margin: 0;
width: 50px;
height: 50px;
margin-right: 18px;
}
.article-author figure img {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 50%;
}
/* Added */
.blog-detail-author {
flex-basis: calc(100% - 68px);
margin-top: 5px;
}
.blog-detail-designation {
margin-left: 68px;
margin-top: -25px; /* This one is a bit hacky, you may need to change it based on the font or other CSS*/
}
<div class="article-thumbnail-wrapper blog-thumbnail-wrapper text-center">
<div class="article-author">
<figure class="article-author-avatar"><img alt="" src="http://themeflex.com/strucflex/en/structures/assets/img/avatar_2.jpg"></figure>
<span class="blog-detail-author">Author Name</span>
<span class="blog-detail-designation">Author Designation</span>
</div>
</div>
Try With this :
HTML
<div class="article-thumbnail-wrapper blog-thumbnail-wrapper text-center">
<div class="article-author">
<figure class="article-author-avatar"><img alt="" src="http://themeflex.com/strucflex/en/structures/assets/img/avatar_2.jpg"></figure>
<span>
<span class="blog-detail-author">Author Name</span>
<span class="blog-detail-designation">Author Designation</span>
</span>
</div>
</div>
CSS:
figure + span {
display:flex; flex-direction:column;
}

max-width of image not working in flexbox for IE 11 but works on google chrome

I'm creating a 2 by 2 grid layout using flexbox where the first column items are merged together as shown below:
This works in Google Chrome without a problem. The image can grow until the maximum remaining width allocated by the flexbox. However, it does not work in IE11. The image stretches its container box and I've been googling and trying different solutions to no avail. It seems like my case is a little different from other similar questions.
Here is what it looks like in IE:
Can you help me spot the problem? I've provided a plunker where you can try your solutions.
CSS:
body {
width: 100%;
}
.element {
display: flex;
flex-direction: row;
width: 100%;
}
.name {
display: flex;
align-items: center;
justify-content: center;
flex: 0 0 100px;
font-weight: bolder;
}
.detail-wrapper {
display: flex;
flex-direction: column;
flex: 1 0 0;
width: 100%;
}
.detail {
display: flex;
flex: 1 0 0;
align-items: center;
justify-content: center;
flex-wrap: wrap;
}
.detail img {
max-width: 100%;
}
.name, .detail {
border: 1px solid;
margin: 8px;
padding: 8px;
text-align: center;
word-break: break-word;
}
HTML:
<div class="element">
<div class="name">name</div>
<div class="detail-wrapper">
<div class="detail">
<img src="https://miro.medium.com/max/1200/1*y6C4nSvy2Woe0m7bWEn4BA.png" />
</div>
<div class="detail">
url
</div>
</div>
</div>
https://plnkr.co/edit/q6Xme6ETvW20Gw57CIWQ?p=preview
IE browser has some issues with Flex. It is not able to calculate the values properly with flex.
(1) I suggest you replace max-width with width in .detail img class.
(2) I suggest you replace flex: 1 0 0; with flex: 0 0 auto; in .detail class.
Edit:-
Added img tag inside one extra div solved the issue as informed by #Xegara. It also worked with max-width For IE 11 browser.
Modified code:
<!DOCTYPE html>
<html>
<head>
<script src="script.js"></script>
<style>
body {
width: 100%;
}
.extra_div{
width: 100%;
}
.element {
display: flex;
flex-direction: row;
width: 100%;
}
.name {
display: flex;
align-items: center;
justify-content: center;
flex: 0 0 100px;
font-weight: bolder;
}
.detail-wrapper {
display: flex;
flex-direction: column;
/*flex: 0 0 auto;*/
width: 100%;
}
.detail {
display: flex;
/*flex: 1 0 0;*/
flex: 0 0 auto; /*-------------------------made change here */
align-items: center;
justify-content: center;
flex-wrap: wrap;
}
.detail img {
max-width: 100%; /*-------------------------made change here */
}
.name, .detail {
border: 1px solid;
margin: 8px;
padding: 8px;
text-align: center;
word-break: break-word;
}
</style>
</head>
<body>
<div class="element">
<div class="name">name</div>
<div class="detail-wrapper">
<div class="detail">
<div class="extra_div">
<img src="https://miro.medium.com/max/1200/1*y6C4nSvy2Woe0m7bWEn4BA.png" />
</div>
</div>
<div class="detail">
url
</div>
</div>
</div>
</body>
</html>
Output in IE 11:

Flex Child Height not Stretching to Full Height of Parent (using align-self stretch)

.appShopSummaryContainer {
display: flex;
flex-flow: column wrap;
}
.appShopSummaryContainer .appShopSummaryProductWrap {
flex-basis: 100%;
background: pink;
height: 100%;
width: 100%;
display: flex;
flex-flow: row nowrap;
align-items: center;
}
.appShopSummaryContainer .appShopSummaryImg {
flex: 0 0 40%;
height: auto;
padding-bottom: 26.667%;
background: green;
background-size: cover !important;
background-position: center center !important;
}
.appShopSummaryContainer .appShopSummaryInfo {
flex: 0 0 60%;
background: orange;
display: flex;
flex-flow: column wrap;
align-items: flex-start;
height: 100%; /* not working */
/* doesn't work: align-self: stretch; */
}
.appShopSummaryContainer .appShopSummaryMoreInfoBtn {
cursor: pointer;
background: #214291;
color: #fff;
padding: 10px;
border-radius: 5px;
}
<div class="appShopSummaryContainer">
<!-- FOR EACH THING DO THIS -->
<div class="appShopSummaryProductWrap">
<div class="appShopSummaryInfo">
<h3>Title</h3>
More Information
</div>
</div>
<!-- ENDFOREACH -->
</div>
I've had a look at some other stackoverflow answers to similar questions, but none work in this situation. Not sure why, but cannot get the orange div to expand to the full height of it's parent.
Setting a height to 100% obviously won't work since the parent doesn't have a fixed height, but aligning itself as stretch also fails to stretch the height.
If anyone can solve this, can someone explain why the align stretch won't work, and why their solution does? Thanks for any help here.
Do you mean something like this ?
you have to add align-items: stretch; to the parent not the item itself
check out this css flex guide
add align-items: stretch; to .appShopSummaryContainer .appShopSummaryProductWrap and remove height: 100%; from .appShopSummaryContainer .appShopSummaryInfo and add justify-content: center; to .appShopSummaryContainer .appShopSummaryInfo
.appShopSummaryContainer {
display: flex;
flex-flow: column wrap;
}
.appShopSummaryContainer .appShopSummaryProductWrap {
flex-basis: 100%;
background: pink;
height: 100%;
width: 100%;
display: flex;
flex-flow: row nowrap;
align-items: stretch;
}
.appShopSummaryContainer .appShopSummaryImg {
flex: 0 0 40%;
height: auto;
padding-bottom: 26.667%;
background: green;
background-size: cover !important;
background-position: center center !important;
}
.appShopSummaryContainer .appShopSummaryInfo {
flex: 0 0 60%;
background: orange;
display: flex;
flex-flow: column wrap;
align-items: flex-start;
justify-content: center;
}
.appShopSummaryContainer .appShopSummaryMoreInfoBtn {
cursor: pointer;
background: #214291;
color: #fff;
padding: 10px;
border-radius: 5px;
}
<div class="appShopSummaryContainer">
<!-- FOR EACH THING DO THIS -->
<div class="appShopSummaryProductWrap">
<div class="appShopSummaryInfo">
<h3>Title</h3>
More Information
</div>
</div>
<!-- ENDFOREACH -->
</div>

Background img width controlled by text inside. Height stays static

I'm trying to make a div with the background img of a bubble that have the count of comments on a post inside it. I want the width to be controlled by the text inside while the height of the div should stay static so I can keep the text inside centered verticaly.
What I have now is the code under here. It looks ok when the value inside is a 3 digit number, but if I change it to a 2 digit number or anything other then a 3 digit number the bubble moves verticaly and horizontaly so the text is not centered anymore.
#wrapper {
display: flex;
flex-wrap: nowrap;
flex-direction: row;
min-width: 100%;
align-items: baseline;
}
#comment_text {
display: flex;
font-weight: bold;
}
#comment_img {
display: flex;
background: url('https://rajohan.no/img/icons/picons_basic_1/SVG/basic1-021_chat_comment_bubble.svg');
background-repeat: no-repeat;
background-size: 100%;
padding: 21px;
margin-left: 10px;
}
#comment_count {
display: flex;
font-weight: bold;
}
<div id="wrapper">
<div id="comment_text">
COMMENTS
</div>
<div id="comment_img">
<div id="comment_count">
160
</div>
</div>
</div>
Try adding background-position:center - this centers the background image horizontally as the element changes width. I think that's what you're trying to achieve.
#wrapper {
display: flex;
flex-wrap: nowrap;
flex-direction: row;
min-width: 100%;
align-items: baseline;
}
#comment_text {
display: flex;
font-weight: bold;
}
.comment_img {
display: flex;
background: url('https://rajohan.no/img/icons/picons_basic_1/SVG/basic1-021_chat_comment_bubble.svg');
background-repeat: no-repeat;
background-position: center;
padding: 21px;
margin-left: 10px;
}
.comment_count {
display: flex;
font-weight: bold;
}
<div id="wrapper">
<div id="comment_text">
COMMENTS
</div>
<div class="comment_img">
<div class="comment_count">
16
</div>
</div>
<div class="comment_img">
<div class="comment_count">
160
</div>
</div>
</div>
I have added some code in your #comment_count.
#wrapper {
display: flex;
flex-wrap: nowrap;
flex-direction: row;
min-width: 100%;
align-items: baseline;
}
#comment_text {
display: flex;
font-weight: bold;
}
#comment_img {
display: flex;
background: url('https://rajohan.no/img/icons/picons_basic_1/SVG/basic1-021_chat_comment_bubble.svg');
background-repeat: no-repeat;
background-size: 100%;
padding: 21px;
margin-left: 10px;
}
#comment_count {
display: flex;
font-weight: bold;
min-height: 20px;
min-width: 25px;
justify-content: center;
}
<div id="wrapper">
<div id="comment_text">
COMMENTS
</div>
<div id="comment_img">
<div id="comment_count">
160
</div>
</div>
</div>
<div id="wrapper">
<div id="comment_text">
COMMENTS
</div>
<div id="comment_img">
<div id="comment_count">
22
</div>
</div>
</div>

Why is my div not taking up 100% height of its parent container?

Bit confused here. I am quite tired, so I'm sure I'm making a silly mistake but here's my HTML/CSS:
.CAContainer {
display: flex;
flex-flow: row nowrap;
justify-content: flex-start;
align-items: center;
margin: 0;
padding: 0;
}
.CASideBorder {
height: 100%;
background: #000;
width: 8px;
}
.CAMiddleContainer {
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
}
.CATopBorder {
height: 8px;
background: #000;
width: 100%;
}
.CAMiddleTextContainer {
padding: 40px 80px 40px 80px;
font-size: 4em;
color: #000;
}
.CABottomBorderContainer {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
width: 100%;
height: 8px;
}
.CABottomBorderLeft,
.CABottomBorderRight {
flex: 1;
height: 100%;
background: #000;
}
<div class="CAContainer">
<div class="CASideBorder" id="CALeftBorder"></div>
<div class="CAMiddleContainer">
<div class="CATopBorder"></div>
<div class="CAMiddleTextContainer">
text
</div>
<div class="CABottomBorderContainer">
<div class="CABottomBorderLeft"></div>
<div class="CABottomBorderRight"></div>
</div>
</div>
<div class="CASideBorder" id="CARightBorder"></div>
</div>
And the fiddle.
Shouldn't CASideBorder be taking up 100% of its parent container, which has its height calculated by the text size and padding of CAMiddleTextContainer? Am I missing something really obvious here? Any help is appreciated.
That is because you have align-items: center for the flexbox in which case it will default to the content height.
What you need to do is to remove that (let align-items: stretch come into play as it is the default) and also remove the height:100% from CASideBorder.
See demo below:
.CAContainer {
display: flex;
flex-flow: row nowrap;
justify-content: flex-start;
margin: 0;
padding: 0;
}
.CASideBorder {
background: #000;
width: 8px;
}
.CAMiddleContainer {
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
}
.CATopBorder {
height: 8px;
background: #000;
width: 100%;
}
.CAMiddleTextContainer {
padding: 40px 80px 40px 80px;
font-size: 4em;
color: #000;
}
.CABottomBorderContainer {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
width: 100%;
height: 8px;
}
.CABottomBorderLeft, .CABottomBorderRight {
flex: 1;
height: 100%;
background: #000;
}
<div class="CAContainer">
<div class="CASideBorder" id="CALeftBorder"></div>
<div class="CAMiddleContainer">
<div class="CATopBorder"></div>
<div class="CAMiddleTextContainer">
text
</div>
<div class="CABottomBorderContainer">
<div class="CABottomBorderLeft"></div>
<div class="CABottomBorderRight"></div>
</div>
</div>
<div class="CASideBorder" id="CARightBorder"></div>
</div>