I'm trying to create a layout so that when I click on "See More" to expand the text of one container, the surrounding containers remain in the same position.
There are three containers and each container has two wrappers, a top which contains the title and bottom which contains the image, text and button. I don't know what the length of the titles will be beforehand, so in order to make sure that the boxes, text and button line up, I've given each container justify-content: space-between so that the bottom wrappers always align.
The issue arises after clicking "See More", where the bottom wrapper of each container moves down to fit the height of the container.
.main-container {
display: flex;
flex-direction: row;
}
.container {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.top-wrapper {
display: flex;
flex-direction: column;
height: 100%;
}
.bottom-wrapper {
display: flex;
flex-direction: column;
justify-content: space-between;
}
<div class="main-container">
<div class="container">
<div class="top-wrapper">
<div class="title">
TITLE 1 IS LONG THAT IT GOES TO NEXT LINE
</div>
</div>
<div class="bottom-wrapper">
<div class="image-text-wrapper">
<div class="image-container">
<img class="image" src="https://dummyimage.com/200x200/000/000">
</div>
<div class=“text” id="text">
{{ text }}
//See More code
</div>
</div>
<button>
BUTTON 1
</button>
</div>
</div>
<div class="container">
//second container code
<div>
<div class="container">
//third container code
<div>
</div>
Should I be using a table or is there a simple CSS fix to this?
You can find the full code here: Plunkr
Try adding the following to your .container class:
.container {
align-self: flex-start;
}
The align-self property allows you to override the setting for align-items that is controlling your flex items' alignment.
And adding the following to the .title class:
.title {
min-height: 50px
}
You may need to play around with this setting, but it prevents the image from rendering without any space between it and your title.
Caveat: the CSS you included here in your post isn't exactly what I got when I opened your Plunkr link -- the .container didn't have display: grid; set, but I think this should work nonetheless.
Related
I have a div container like this:
<div class="list__products">
<div class="products">
{{#each rows}}
<a href="javascript:addToRow('{{id}}')" class="products__a" value="{{value}}" id="{{id}}">
<img class="products__a-img" src="../../../../resources/media/products/{{id}}.webp">
{{name}}
</a>
{{/each}}
</div>
</div>
where with each loop I generate a list of a products with handle bars, and I make it a specific size and adjust other parameters with this css:
.main__new .list__products{
display: flex;
flex-flow: row wrap;
width: 36vw;
}
.main__new .products{
display: flex;
flex-flow: row wrap;
max-height: 70vh;
overflow-y: auto;
justify-content: space-around;
align-content: space-around;
margin: 1.5vh 0;
}
and what is the problem? well, when I have a lot of products, the first ones are outside the div box and cannot be seen, I tried to fix it by changing the position but I can't find a feasible way to do it, try to change the height and overflow parameters assigning them to the list__products container but that makes it impossible to scroll to see the buttons that are outside this size, is there any other way to do it?
Sample of images:
How do you make floated elements stop floating on overflow? I'm trying to have something like this:
When the browser is fully maximized the two elements are meant to line up like this:
|span| |span|
But when the browser re-sized to the point where the elements are touching this should happen:
|span|
|span|
I've tried doing it with floating like:
<div class="border px-3">
<span>December 6th, 2020</span>
<span class="float-right">This is some example text right here</span>
</div>
But when I resize I get
|span|
|span|
This is what you want, but using flex rules. And exactly:
display: flex - sets flexibility;
justify-content: space-between - distributes blocks evenly throughout the free space;
flex-wrap: wrap - sets the transfer of blocks when narrowing the browser window.
.border {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
<div class="border px-3">
<span>December 6th, 2020</span>
<span>This is some example text right here</span>
</div>
You can use some flexbox properties,
.my-container{
display: flex;
flex-wrap: wrap;
width: 100%;
}
.first{
flex: 1 0 auto;
}
.second{
flex: 0 0 auto;
}
Corresponding HTML Code
<div class="my-container">
<span class="first">December 6th, 2020</span>
<span class="second">There is some example text here</span>
</div>
I have some weird behavior going on in my divs at the moment, each div is written like the other (they are just mirror images). The text is mimicking columns and is setting side by side instead of top to bottom like it should. The oddest thing is, it seems to be working fine on another page this particular page only contains the behavior.
The code is something like this
<div class="flex-wrap">
<div class="flex">
<h3>A title</h3>
<p>some text</p>
</div>
<div class="flex">
<h3>A title</h3>
<p>some text</p>
</div>
</div>
<style>
.flex-wrap{
display:flex;
flex-wrap:wrap;
}
.flex{
display:flex;
align-items: center;
}
</style>
I've taken this apart piece by piece in the inspector tool and I'm even more baffled as to why it works fine on one page and not at all on another. The last section uses the same css layout it just contains a different picture and text. Can anyone tell me how to fix this? BONUS POINTS IF YOU CAN TELL ME WHY.
The first thing to keep in mind is that flex layout applies only between parent and child elements. Descendants in a flex container beyond the children do not participate in flex layout.
In your "broken page", the four side-by-side paragraph elements are children of a flex container (.tours-sec-3-p2-wrap).
.tours-sec-3-p2-wrap {
padding: 2%;
align-items: center;
display: flex;
background-size: 15%;
padding-top: 0;
background-position: 0px 30%;
background-repeat: no-repeat;
}
An initial setting of a flex container is flex-direction: row, so the children (flex items) are lining up in a row. The quick and easy solution is to override the default with flex-direction: column.
In your "working fine" page, the image and paragraphs are not children of a flex container. These elements are children of a block container, and that container is the child of the flex container.
Your image and text are being aligned with float, not flex, properties.
If you want to use flex properties, add display: flex to the parent element.
Despite anyone's belief, the layouts of each section are exactly the same. They are generated with the cms, they are not static pages.
That said, the behavior was only different between the 2 because of the length of the content in each flex container. Adding the same content to the tours page created the same behavior.
The problem was indeed solved with flex-direction: column; and additionally adding justify-content: center;
If you don't want to use flex-direction: column; you can make your elements stretch to 100% width to force the wrap.
.flex-wrap{
display:flex;
flex-wrap:wrap;
}
.flex{
display:flex;
align-items: center;
flex-wrap:wrap; /* added */
}
.flex,
.flex h3,
.flex p
{
width: 100%;
}
<div class="flex-wrap">
<div class="flex">
<h3>A title</h3>
<p>some text</p>
</div>
<div class="flex">
<h3>A title</h3>
<p>some text</p>
</div>
</div>
Bonus Tip for justify-content: center and text aligning left after wrapping. (run the code snippet)
.flex-wrap{
display:flex;
flex-wrap:wrap;
flex-direction: column;
}
.flex {
display:flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.text-centered {
text-align: center;
}
<div class="flex-wrap">
<div class="flex">
<h3>Centered (but it hasn't wrapped)</h3>
<p>centered text</p>
</div>
<div class="flex">
<h3>Not Centered (after wrap)</h3>
<p>sometimes you'll want to use justify-content: center; and keep the text centered along with whatever other elements are inside the div. You'll see in the 2nd example the text aligns left after it wraps. Add text-align: center; and it will center the text.</p>
</div>
<div class="flex text-centered">
<h3>Centered</h3>
<p>sometimes you'll want to use justify-content: center; and keep the text centered along with whatever other elements are inside the div. You'll see in the 2nd example the text aligns left after it wraps. Add text-align: center; and it will center the text.</p>
</div>
</div>
So I have 2 containers in another container, aligned side by side via flexbox. Only the content of one of these containers should be fixed to the top of the page.
Mark-Up:
<div class="outer-container">
<div class="inner-container1">
Blabla, some normal content in here!
</div>
<div class="inner-container2">
<div class="fixed-box"></div>
</div>
</div>
CSS:
.outer-container {
display: flex;
flex-direction: row;
}
.fixed-box {
position: fixed;
}
But this doesn't work like I want to have it. Here the fixed-box is fixed but is displayed beside the outer-container.
What is wrong?
Thank you for your help!
Johanna
So i have a list of 30 something objects i will be loading in with ajax, as soon as i get my formatting correct i will take care of that, however i cant seem to get my flex-box css to adjust my flex items to the left side when it wraps to a new row...
http://i40.photobucket.com/albums/e240/ocfighter/Screen%20Shot%202016-01-18%20at%2012.34.51%20AM%20copy.jpg
i would like for the three bottom divs to be on the left side instead of dispersed through out the middle of the second row....
my container div for all of the divs you see displayed
#movies {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.center {
-webkit-justify-content: center;
justify-content: center;
}
html
<div id="movies" class="center">
<div class="movies_cell center">
<div class="movies_image">
<img src="img/movies/fatheroflights.jpg" alt="" style="width: 100%; height: 100%">
</div>
<div class="movies_detail">
<h1>Father of Lights</h1>
<img src="img/rating/5.png" alt="" style="margin: auto;">
</div>
</div>
</div>
Change to:
justify-content: flex-start;
Unless for some reason you want the first row to be in the center unless it's too big for the container, that would be more complicated.