Flow items, adjust width of container and center items [duplicate] - css

This question already has answers here:
Place boxes inside ul in center, but align them left
(1 answer)
Making a container fit the width of its children
(1 answer)
Closed 3 months ago.
How do I ensure that items in a container are centered regardless of screen size?
I am trying to create a responsive/dynamic layout on a web-page that has a container div and some results/items (divs) inside. I would like them to flow within the available width but have uniform margin/alignment within the centered div which I am struggling to achieve. Here are three images of what I want to achieve. This could be a desktop, a tablet and a phone:
So far I've had to go with a cut-off width of e.g. 800px and two different layouts, but that's not optimal. The container should be dynamic, for example 90% width but the items inside fixed width of 200px. I can use flow:left; or display:inline-block; to flow the items inside, but they will always be left aligned, so that when one "slides" down to the next line, the remaining are sitting to the left with a gap to the right.
This is probably a common use case, and I'm happy to be referred to other answers, but I haven't been able to search correctly in order to find the answer.
EDIT: I know that I can do this with JavaScript. I could probably use getBoundingClientRect on the container and with code adjust the margin of the items, but there must be a CSS solution :)

Related

I can't make nested flex-grow elements to work as expected [duplicate]

This question already has answers here:
Why don't flex items shrink past content size?
(5 answers)
Closed 15 days ago.
Codepen: https://codepen.io/andrerpena/pen/JjBzKNg
I would like the button bar to always be visible where the blue --> is pointing, when the screen squeezes.
My document structure is like this:
div[#id='title']
div[#id='body'] <-- This should grow
div[#id='body-content'] <-- This should grow and be scrollable
div[#id='body-buttons'] <-- This should be fixed at the bottom
According to the above structure, I'd expect body-content to scroll and body-buttons to always be visible.
Why is it not? Is there any way to fix it without changing the DOM structure? If not, how would you change it?
I'm personally interested in knowing why it doesn't work, because I do CSS for more than a decade and I still get surprised by stuff like this.
Thanks.
Flex child has an initial value min-height: auto which means that it will not have height less than the content height (the texts). In this case you can add min-h-0 class to the div[#id='body'] (#body) element so that it doesn't have to have a minimum height. Here's the working codepen.

Table build with flex and divs with pinned column [duplicate]

This question already has answers here:
Pin element like position: fixed but inside its parent not the viewport
(3 answers)
Closed 4 years ago.
I'm building table that should be fully responsive (so I'm using flex on divs instead of table).
I want to be able to pin column.
Here what I've got https://codepen.io/piernik/pen/LmoBxM
What's the problem?
When You scroll left pinned column disapears.
It's probably that .row2 has width of viewport, not entire table.
You can see .row2's width on the red top border.
Can I fix it?
I want to build responsive table with pinned column that can have hsrcoll without any JS.
You used flex-basis:500px in cell that's why your table width larger than windows width and flex cover only all window width.

Indent text and images horizontally by the same amount [duplicate]

This question already has answers here:
Why does CSS float not change the width of the following div?
(3 answers)
Keep text from wrapping around floated image
(3 answers)
Closed 8 years ago.
It's kinda hard to describe what I'm trying to do, so take a look at this fiddle:
http://jsfiddle.net/GinSan/g8mmdcuw/
As you can see, the text flows around the image, but starts at the very left of the side under the image. I want the text to keep the indentation level, even if it's height excels the height of the image. The Images at the bottom should behave like that as well, so that both the the text and the images would be indented from the left side by the image width plus it's right and left margins.
Just increasing the bottom margin of the image would probably work, however this would push everything underneath it further to the bottom if the text is too short, it has to work with different text lengths.
I accomplished to keep the text indentation at one level by adding this:
p.memberlist_descr {
width:70%;
float:left;
}
However, since the text now has a defined width, it wouldn't work on smaller screens. Also, this has no effect on the smaller images below.
Is there a way to accomplish this, if both the text length and the width of the box surrounding are unknown?

Navigation column tall as Content one: maybe with calc()?

I have classical 2 columns layout, but I have constrained about NAVIGATION and CONTENT blocks are both floated left (side-by-side). Below them there is FOOTER block that spans across entire windows width and is floated left too, but below others divs.
Obviously CONTENT has an auto height based on its content, but I wish that NAVIGATION has an equal height.
I was investigating about
calc()
property that seems very promising, but.... I was not avble to reach my objective.
How to solve this?
Not enough points to comment your post…
I think your answer is here:
CSS - Equal Height Columns?

How can create a two-column layout in CSS where one column shrinks to it's content, and the other expands to fill the remaining space?

I have two <div>s on my page. I want to arrange them side-by side, so that the first (right) shrinks to fit it's contents (unknown width), and the second (left) expands to fill the remaining horizontal width.
The two columns do not need to be equal in height.
Additionally, I would like to create a 5px gap between the edges of the two boxes.
Is this layout possible without using a table?
EDIT:
Here's a table version to show you the kind of behavior I'm looking for.
I think one of my answers on another question solves this:
xHTML/CSS: How to make inner div get 100% width minus another div width
Am I understanding your question correctly?
Yes it is! You can float the first column left, and play with margins to create your gap.
http://innonesen.se/test/l-41-mod/
Ths should do it ( tested only on IE6 and Opera ).
Additional feature exist that the main container will stop expanding ,
when sidebar is less then 100px wide .
http://innonesen.se/test/l-41-mod/no-right.html
P.S. sorry , i cant past URLs .. my rep is too low.
Sure, here are two different fiddles showing how you could do it. The #float example uses a float: left and then a margin-left on the other div that equals the #float width.
The #absolute one uses one absolute column of fixed width and then the other column sets a margin-left that equals the #absolute column's width.

Resources