Wondering--does anyone know of any good articles explaining the CSS technique allowing multiple instances of a class to flow down the page relative to the items above it. Not explaining it that well.
Veerle' Pierter's does it on this page: http://veerle.duoh.com/belgiangraphicdesign Although I'm not sure I want to use a technique like her's that requires entering of the height per element via her EE installation.
I made a little graphic of what I am trying to acheive;
The key is I need a robust technique for doing it. Something where the markup could be as simple as;
<div class="box">
Number 1
</div>
<div class="box">
Number 2
</div>
<div class="box">
Number 3
</div>
<div class="box">
Number 4
</div>
<div class="box">
Number 5
</div>
...
Would love any pointers in the right direction.
As the others have pointed out, using only CSS you could group the boxes into columns. Unfortunately this will not look good if your content is dynamic and you don't know the heights of all the boxes (your columns could end up drastically different lengths). If you want to calculate the heights of boxes in order to arrange them nicely, you are going to have to use Javascript. There's certainly nothing wrong with using Javascript - it's the right tool for this job!
As for the implementation, the logic would go something like this: start by adding the first 4 boxes, one at the top of each column. Then keep track of the total height of each column using Javascript's clientHeight property, and for each new box you want to add; simply append it to the end of the shortest column with appendChild().
If you decide to go with jQuery, I can recommend a plugin called jQuery Masonry.
She isn't setting a height for those boxes.
Jquery is dynamically positioning each box and as far as I know that's the only way to achieve that effect with the markup you describe in your post.
If you don't want to use a javascript solution the only way to do it is to have wrapper columns, but that would change your markup dramatically.
<div class="container">
<div class="box">number 1</div>
<div class="box">number 2</div>
<div class="box">number 3</div>
</div>
<div class="container">
<div class="box">number 4</div>
<div class="box">number 5</div>
<div class="box">number 6</div>
</div>
<div class="container">
<div class="box">number 7</div>
<div class="box">number 8</div>
<div class="box">number 9</div>
</div>
She achieves it positioning the boxes absolutely.
But you can achieve it with very simple css, assuming you can control the order by which the items appear.
You have to group them in columns (and not in rows as is usual), but it works like a charm.
Use HTML like this:
<span class="column">
<div class="box">number 1<br />with two lines</div>
<div class="box">number 4</div>
<div class="box">number 7<br />with two lines</div>
</span>
<span class="column">
<div class="box">number 2</div>
<div class="box">number 5<br />with two lines<br />or even three<br />or four!</div>
<div class="box">number 8</div>
</span>
<span class="column">
<div class="box">number 3</div>
<div class="box">number 6</div>
<div class="box">number 9</div>
</span>
And CSS like this:
.column {
clear: left;
width: 25%;
display: inline-block;
vertical-align: top;
}
.box {
border: solid 1px blue;
}
Test it on JSFiddle.net.
Use span for the columns, because IE7 does not accept display: inline-block; for elements that are naturally block elements. (Meh.)
Related
I am having trouble with my css. I am trying to have my contact information, the quote, and my contact form to be in the same row but different columns. And also why is it that my html doesn't all fit on one page, I can scroll to the rigth and there's just empty white space. I figure its because I added -1.23em in my navbars margin; However, I only did this because my navbar was not filling the whole page. Here is a link to my gist and bitballon. Thank you in advance.
https://gist.github.com/bklynbest/a19565b1b5289f045919e76d657848ea
http://sad-goodall-e4f115.bitballoon.com
You have a .row div in the nested directly under the body on line 103 that is causing the page to spread past 100% width
Bootstrap requires a containing element to wrap site contents and
house our grid system. You may choose one of two containers to use in
your projects. Note that, due to padding and more, neither container
is nestable. bootstrap containers
Regarding the contact info your nesting and class names are not correct, you currently have the following:
<div class="container-fluid" id="contact">
<div class="row">
<div class="column">
<div class="col-xs-12 col-md-12">
<div id="quote">...</div>
</div>
<div class="col-lg-4 col-md-4">
<div class="contact">...</div>
</div>
</div>
</div>
</div>
<form>
you will need to change this to follow bootstrap3 grid conventions, something like the following:
<div class="container">
<div class="row" id="contact">
<div class="col-sm-4">
<div id="quote">...</div>
</div>
<div class="col-sm-4">
<div class="contact">...</div>
</div>
<div class="col-sm-4">
<form>
</div>
</div>
</div>
I'm trying to use the column-count to make a kind of week calendar to user tasks.
The main div of the week has the property of column-count to 7 and ALWAYS there will 7 childs. The seven days of this week.
Inside this days there are the tasks, but the number of tasks is variable and it break the column-count logic.
Why column-count not consider just the first childs inside it?
Here's an example of what I'm saying: https://jsfiddle.net/nby5ctb2/
On the second list, I wanted the tasks 1, 1.1 and 1.2 on top of each other, and when there are no childs just skip these day.
The css I used was just this:
.week {
-moz-column-count: 7;
-webkit-column-count: 7;
column-count: 7;
}
Thanks advanced
You seem to have misunderstood the purpose of column-count and are therefore misusing it.
It's purpose is to take some content and divide it into the given number of columns with as close to equal amounts of content as possible. The only tool you have is break-inside:avoid to keep "block-like" content together.
But if you do use it to make one column taller than the rest, your are making all columns the same height, because that's what CSS columns does. So, for example, using break-inside:avoid on .day. will cause other shorter .days to pile up in the same column. It would only work if days in your week had equal amounts of content, which is clearly not the case.
First question that comes in mind is: why not use flex? Since you probably want your day's widths equal, you need to add width to the children. By default display:flex children have flex: 0 1 auto, which makes them flexible, depending on contents.
.week {
display: flex;
}
.week > * {
width: calc(100% / 7)
}
Fiddle.
CSS Column is not the best solution to accomplish that. It strives to flow the content column wise, from left to right, and what you ask is to fight against it.
I recommend you use i.e. Flexbox, which does that very simple, and with better browser support.
.week {
display: flex;
flex-wrap: wrap;
}
.week .day {
flex-basis: calc(100% / 7);
word-break: break-all;
overflow: hidden;
}
This works
<div class='week'>
<div class="day">
<div class="task" >Task 1</div>
</div>
<div class="day">
<div class="task" >Task 2</div>
</div>
<div class="day">
<div class="task" >Task 3</div>
</div>
<div class="day">
<div class="task" >Task 4</div>
</div>
<div class="day">
<div class="task" >Task 5</div>
</div>
<div class="day">
<div class="task" >Task 6</div>
</div>
<div class="day">
<div class="task" >Task 7</div>
</div>
</div>
<br />
<br />
This <strike>doesn't</strike> work too, now
<div class='week'>
<div class="day">
<div class="task" >Task 1</div>
<div class="task" >Task 1.1</div>
<div class="task" >Task 1.2</div>
</div>
<div class="day">
<div class="task" >Task 2</div>
</div>
<div class="day">
</div>
<div class="day">
</div>
<div class="day">
<div class="task" >Task 5</div>
<div class="task" >Task 5.1</div>
</div>
<div class="day">
</div>
<div class="day">
</div>
</div>
This is the HTML that I am working within. (PLEASE NOTE: I cannot change the HTML, only the styling).
<div class="table">
<div class="table-row">
<div class="table-row-1">
<div class="table-row-2">
<div class="table-col">Column 1</div>
<div class="table-col">Column 2</div>
</div>
</div>
<div class="table-row-1">
<div class="table-row-2">
<div class="table-col">Column 1</div>
<div class="table-col">Column 2</div>
</div>
</div>
</div>
<div class="table-row">
<div class="table-row-1a">
<div class="table-row-2">
<div class="table-col">Column 1</div>
<div class="table-col">Column 2</div>
</div>
</div>
<div class="table-row-1b">
<div class="table-row-2">
<div class="table-col">Column 1</div>
<div class="table-col">Column 2</div>
</div>
</div>
</div>
</div>
As you can see, there are multiple rows containing the actual cells. I am applying display:table to the main div, display:table-row to the first parent row, and then display:table-cell to the column cells.
I am unable to use an actual table as I cannot change the HTML.
I am unsure what to apply to the extra row containers to ensure that they aren't affecting the structure of the table.
This code is being used to make a flexbox grid which is more structured on larger screens, meaning that the cells within the same column are the same width. If you could suggest another solution other than the table displays, please do, but I have been unable to find another option.
I am working with less.
i have 3 col in medium view in bootstrap shown in above image ie.
i want to achieve this type of view in small view is col-sm-*
my code is
<div class="col-md-8">
<div class="col-md-12">A</div>
<div class="col-md-12">C</div>
</div>
<div class="col-md-4">
<div class="col-md-12">B</div>
</div>
IN THIS way i can achieve my target in medium view but cant achieve in small view.how can i achieve the both view as well as in medium and small view as shown in image.
I suggest reading bootstrap css doc also this
But try this:
<div class="row">
<div class="all a col-sm-12 col-md-6">A</div>
<div class="all b col-sm-12 col-md-6">B</div>
<div class="clearfix"></div>
<div class="all c col-sm-12 col-md-6">C</div>
</div>
You can remove the <div class="clearfix"></div> if you don't care about the height mismatch
Here's a working jsfiddle
It's a bit of a stretch, but you could try this:-
<div class="col-md-8">
<div class="col-md-12">A</div>
<div class="col-md-12 visible-sm visible-xs">B</div>
<div class="col-md-12">C</div>
</div>
<div class="col-md-4 hidden-sm hidden-xs">
<div class="col-md-12">B</div>
</div>
Frankly, I can't think of any other solution using just HTML and CSS. Although, if scripts were involved, it would be a different case.
First of all, you shouldn't assign columns without rows, so you should have something like:
<div class="row">
<div class="col-md-8 col-xs-12">A</div>
<div class="col-md-4 pull-right col-xs-12">B</div>
<div class="col-md-8 col-xs-12">C</div>
</div>
So you pull right your B Div (therefore not clearing the next div, and spacing it out). And with col-xs-12 you assure that float won't be present in mobile.
Heres a pen
Now, if you want to remain with your code, I guess Shan answer is the best one.
Well, you could have the height of B and work with margins so the positioning go right, but that isn't considered best practices and could cause some bugs.
I have the following structure:
<div id='container'>
<div id='cont1' style='width:150px'>Content 1</div>
<div id='cont2' style='width:150px'>Content 2</div>
<div id='cont3' style='width:150px'>Content 3</div>
<div id='cont4' style='width:150px'>Content 4</div>
<div id='cont5' style='width:150px'>Content 5</div>
</div>
I want div container to horizontally scroll. I want cont1 until cont5 to stay inside container. I want to be able to horizontally scroll these 5 divs and, possibly, I want to simply put one contx div next to the other exactly as I showed in the code.
The problem is that I cannot achieve this solution. For example consider:
<div id='container'>
<div id='internalcontainer' style='width:750px'>
<div id='cont1' style='width:150px'>Content 1</div>
<div id='cont2' style='width:150px'>Content 2</div>
<div id='cont3' style='width:150px'>Content 3</div>
<div id='cont4' style='width:150px'>Content 4</div>
<div id='cont5' style='width:150px'>Content 5</div>
</div>
</div>
What seemed to me quite complicated to do is to obtain the horizontal scroll by simply putting one div next to the other (contant divs). So I tried to put them inside a fixed width container which is placed inside the div that should perform the horizontal scroll. Even this code does not work when i try to style it. My questions are:
Is it possible to obtain the horizontal scroll with the first structure?
Is it possible to obtain the horizontal scroll with the second structure?
I tried a lot with css overflow, but did not get anything...
Thanks
You can apply the style overflow-x:scroll to your container div if the event onmouseover is triggered and reset it to overflow-x:hidden if onmouseout is triggered.
edit
here's what you need to add to your container divs:
<div id='container' onmouseover='this.style["overflowX"]="scroll";' onmouseout='this.style["overflowX"]="visible";'>
...
</div>
try it yourself: http://jsfiddle.net/bukfixart/qX8Cx/
Yes is possible with both structures. I'll illustrate the first one since it is less verbose. I'll use flex box CSS3 feature:
#container {
display: inline-flex;
flex-direction: row;
}
<div id='container'>
<div id='cont1' style='width:150px'>Content 1</div>
<div id='cont2' style='width:150px'>Content 2</div>
<div id='cont3' style='width:150px'>Content 3</div>
<div id='cont4' style='width:150px'>Content 4</div>
<div id='cont5' style='width:150px'>Content 5</div>
</div>
If you want a scroll bar in the container itself you can add:
#container {
overflow-x: scroll;
}