Trying to make a grid with flex - css

In my attempts to understand flex i decided i want to make a grid. Here's a general layout image for that:
The idea is that there's
a) a sidebar
b) a sticky header under which the main containers crolls
c) a main container that holds the main data
d) items that are sized depending on their content placed on a grid
To implement the sticky header i created did the following:
<div>
<div class="stickyHeader"></div>
<div class="contentscroll"></div>
</div>
Where
.stickyHeader{
position:absolute;
width:100%;
top:0px;
left:0px;
height:200px;
background-color:rgba(128, 128, 128, 0.178);
}
and
.contentscroll{
overflow: scroll;
height:100%;
display:flex;
box-sizing: border-box;
/* justify-content: flex-start; */
flex-flow:row wrap;
}
The issue is that the flex elements are trying to fill the 100% of the main container and therefore the page looks very different if i've got one item element vs 6 ( meaning that the space between the item elements and the sticky header seems variable when i really want it to be a specific distance.
Thanks a lot, you can find the entire code here:
https://jsbin.com/wivudiqisa/edit?html,css,output

I am not sure, what you mean with "sticky header seems variable" but you can distribute the flex Elements like this:
.contentscroll{
...
justify-content: space-between;
...
}
.contentitemcontainer {
...
width:20%;
...
}
I found this guide helpful: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

The support for Css Grid has greatly improved and you don't need to hack you way into building a grid! It has more than 90% browser support, so let's start using Grids
I have put together an article that covers precisely that and where to use grid and when to use flex here if you want to know more info

Related

Flex no-wrap pushing content out of other non-flex elements

I am lost on this one. I'm trying to set up a Javascript scroller where the content in the container needs to be inline, so it can be scrolled. If I use flex and flex-wrap:nowrap, it pushes the content out as it should, and I can scroll, but then the content in other areas of the form also follow suit by going out of their container. I only want the content in the flex container to overflow out of the element. How can I achieve this without bothering the rest of the content?
Here is the code I'm using:
#scroll-years {
width: 80%;
max-width:75em;
display: flex;
flex-direction: row;
justify-content:flex-start;
flex-wrap:wrap;
overflow:hidden;
margin:auto;
}
<div id="scroll-years">
<span>2009</span>
<span>•</span>
<span>2010</span>
<span>•</span>
<span>2011</span>
<span>•</span>
<span>2012</span>
<span>•</span>
<span>2013</span>
<span>•</span>
<span>2014</span>
</div>
EDIT:
I just noticed that if I use overflow:hidden on the parent container of #scroll-years, everything looks good. I'm not an expert with CSS so I have to ask, can this be right?
Edit
#ap-container {
max-width:75rem;
width:95%;
overflow:hidden; <-----Adding this pushes all the content back into place
}
Is this correct behavior or is this more of a hack? My objective is to learn how to code CSS better than I have been, so that's my concern.

Margin is not working in Specific div content

Hello I am new in designing and I I want to set the div sequence But When I give margin to the specific div it apply to all div I used unique class but problem is same
here is link of site
I want align special offers like express shipping
You can add another property (display: flex;) in your css for .footer-top-inner.container-width (DIV containing your blocks)
<div class="footer-top-inner container-width">
//your footerblocks
</div>
CSS:
.footer-top-inner.container-width{
display: flex;
//if that doesn't work, you might want to use display: flex !important;
}
But the best way would be to add another class to this container, just to prevent our override messing your website :)
EDIT: To keep your website looking good, you can add another property within display: flex;
justify-content: space-between;
This should automatically align your footerblocks

Sliding-rightward input box with CSS

Is there any way to make an input box span the distance between the right edge of its parent and go as far left as it needs to?
What I mean is, suppose I have
<div>
<span>a</span>
<span>b</span>
...
<input />
</div>
I'd like to make the input change width, so that if there were no spans, the input would stretch across the whole div, but if there are spans it would contract from the left? I'd be adding the spans from javascript.
Is it possible to do this in pure CSS?
Yes, technically.
To do it with CSS only, you will need to use the new flexbox model.
However, support is not great.
div {
width: 30em;
display: -webkit-flex;
display: flex;
input {
width: 100%;
flex: 1;
}
Try this demo in Chrome.
For support in other browsers that don't support the candidate recommendation, a little bit of Javascript to add percentage based widths based on the number of spans is your best bet.

How can I center an element on a Windows 8 [HTML5/JS/CSS3] using flexible layouts

I am building a Windows 8 App in HTML5 and I am trying to center my app menu right in the middle of the screen. I know there are new CSS3 to apply this functionality, by using flexible boxes, however I am not able to recreate that. Here is my HTML
<body>
<div id="playControl">
<button>Back</button>
<button>Play</button>
<button>Forward</button>
</div>
</body>
There is some information here, but looks like isn't working properly (I guess they changed the property names)
Thanks
Here's how I do that. I use a grid instead of a flexbox at all. Let's say your div is inside a div called "parent". I would use...
#parent {
display:-ms-grid;
-ms-grid-columns:1fr;
-ms-grid-rows:1fr;
height:100%;
}
And then on your div I would use...
#yourDiv {
-ms-grid-column-align: center;
-ms-grid-row-align: center;
}
Notice that you need to give the parent div a single row and column and a height of 100%. Then you need to set the alignment for the child div (the initial value is 'stretch').
Hope that helps.
Brute force example... use css styles in real implementation...
You can fill the page with a flexbox like this... (note I used the default ms-flexbox css style to get things started and overrode with inline styling to get what I wanted)
<div class="ms-flexbox" style="width: 100%; height: 100%; -ms-flex-direction: column; -ms-flex-align: center; -ms-flex-pack: center;">
<button>Back</button>
<button>Play</button>
<button>Forward</button>
</div>
or your could create a 3x3 grid and put a smaller flexbox inside the middle cell.

CSS to Make 2 Column Content Areas

I'm trying to stray away from using tables to form the layout of my content, and I can think of two alternatives that I'd like to better learn: (1) styling list items to be side-by-side, and (2) using div blocks that float onto the same line. Both of these would have their own uses for what I'm working on.
I'm already using div tags to form the entire layout of my three-column template, but what I need to do now is a bit different. In case it helps, my project can be found here.
In short, here's my question; how would I style a div so that the width of it is 50% of the width of the area it occupies, rather than 50% of the width of the page?
As for my other question, what would be the best approach to styling list items so that they are side-by-side? I'm working on a registration script now, and instead of using a table with "Username" on the left and the input text on the right, I can use two list items.
It's late and I've been working on this project of mine for about 8 hours straight now, so I apologize if I'm asking anything confusing. Feel free to ask me any questions about what I'm trying to do.
Thanks, friends. :)
When you use percentage units for widths and heights, it is relative to the first ancestor element which has defined a width or height. Therefore, all you need to do is set up a div which is as wide as two columns:
<div class="columnContainer">
<div class="column">
Column 1
</div>
<div class="column">
Column 2
</div>
</div>
.columnContainer {
width: 800px;
}
.column {
float: left;
width: 50%;
}
There's a lot more fiddling about required than just the code above, but that's the basics. As Gabriel said, you might get a lot of value out of using a CSS framework like 960.gs
ok, so to help you out best I am going to point you to http://960.gs this is a great tool for prototyping this sort of scenario and getting solid reliable code. On to your actual issue, you probably want to set:
width: 50%;
float: left;
display: block;
on the elements you want split. Good luck.
For the width, any relative sizing is relative to the parent, so put it as a child inside the element you want to be half of. For the list items... use display: inline; or float: left;
Inline list are simple but have some drawbacks, you cant set height or width for example.
ul li {
display:inline;
}
If you need block elements you need to float list items and floats can be tedious sometimes, for example you need to take care of clearing [uod]l element.
ul {
overflow:hidden;
}
ul li {
float:left;
display:block;
}
You probably want to remove margins and paddings on list itself in both cases.
ul {
margin:0;
padding:0;
}

Resources