I am having an issue with displaying divs correctly.
I am displaying information about 10 books, and I would like to do so by having 3 rows of 3 and one row for the last book. This is what my first row looks like:
desired
This is the problem I am facing: wrong
I have a template that iterates over 10 books that I get from a search result and then the outer template displays 10 templates that belong to each book.
This is my template code for each book card:
<div class="col-sm-4">
<div class="profile-card text-center">
<img class="img-responsive" src="https://images.unsplash.com/photo-1454678904372-2ca94103eca4?crop=entropy&fit=crop&fm=jpg&h=975&ixjsv=2.1.0&ixlib=rb-0.3.5&q=80&w=1925">
<!-- <img class="img-responsive img-border center-block" src="{{imageFormatterOne}}{{getLargeImage LargeImage}}" alt=""> -->
<div class="profile-info">
<img class="profile-pic" src="https://pbs.twimg.com/profile_images/711000557742395396/jzm8hqwW.jpg">
<h2 class="hvr-underline-from-center">{{getTitle ItemAttributes}}<span>{{getAuthor ItemAttributes}}</span></h2>
<div>Publisher - {{getPublisher ItemAttributes}}<br>
Edition - {{getEdition ItemAttributes}}<br>
ISBN - {{getISBN ItemAttributes}}<br>
Publication Date - {{getPublicationDate ItemAttributes}}<br>
Media- {{getProductGroup ItemAttributes}}<br><br></div>
{{#if isVerifiedUser}}
</div>
</div>
</div>
In the outer template that calls each card template, I have wrapped each card template in a container:
<div class="container">
{{#each getSearchResults}}
{{>searchResult}}
{{/each}}
</div>
I tried doing the negative margin trick, which is why all the cards are attached vertically, but if I remove the code for that, then I face another problem which is that the div changes size to match the amount of text each card has.
To summarize I have two problems:
1) How can I display 3 cards in 3 rows and 1 row with 1 card? Edit: In addition, how could I make this responsive to larger screens? Ex: 4 per row, etc...
2) How can I set every div to a set size so every div is the same size?
Thank you very much.
1) How can I display 3 cards in 3 rows and 1 row with 1 card?
If you are pulling books from an array or list of some kind I would suggest using an loop that displays 3 books per row with an condition that checks if the length variable compared to the current index. If the index is greater less than or equal to the length then the book will be posted if not then it doesn't exit and nothing should be done. This way is you later add a book to the array you will not have to edit the HTML
or if you want it hard coded
use 4 rows
<div class="row">
<div class="col-md-4">book 1</div>
<div class="col-md-4">book 2</div>
<div class="col-md-4">book 3</div>
</div>
<div class="row">
<div class="col-md-4">book 4</div>
<div class="col-md-4">book 5</div>
<div class="col-md-4">book 6</div>
</div>
<div class="row">
<div class="col-md-4">book 7</div>
<div class="col-md-4">book 8</div>
<div class="col-md-4">book 9</div>
</div>
<div class="row">
<div class="col-md-4">book 10</div>
<div class="col-md-8"></div>
</div>
2) How can I set every div to a set size so every div is the same size?
If you want to create a style that ever book should follow
I would suggest Putting an outer around your current template for each book and give that div a class name
<div class="book">
<!-- you template -->
</div>
Now you can style this section uniformly using css
.book {
height: <what you want>;
width: <what you want>;
}
try to separate the 4 divs so each is on its own row:
<code>
div1 id=card1, id=card2, id=card3 />
div2 3 cards />
div3 3 cards />
div4 1 card />
then set style rules.
#card1 {
margin: x x x x;
}
#div1 {
margin-bottom: x x x x;
}
</code>
should work ok!
You can split the array in chunk of 3 and loop trough this chunks creating the div row container and displaying the 3 books in the col-*-4 columns.
Related
This question already has answers here:
Where to place bootstrap row class
(4 answers)
Closed 4 years ago.
Let's say I have to nest three bootstrap col classes and the last one will be col-md-12 so it goes 100%. My question is, Is that ok to nest col-md-12 in one row like first example or do I need to create another row for col-md-12 ?
Eg 1
<div class="row">
<div class="col-md-6">
1
</div>
<div class="col-md-6">
2
</div>
<div class="col-md-12">
3
</div>
</div>
or
Eg 2
<div class="row">
<div class="col-md-6">
1
</div>
<div class="col-md-6">
2
</div>
</div>
<div class="row">
<div class="col-md-12">
3
</div>
</div>
It is absolutely fine to have more columns in a row than will fit in it. They will wrap.
What's more, this is essential to Bootstrap's approach to responsive design.
You might have something like:
<div class="row">
<div class="col-sm-6 col-lg-3">…</div>
<div class="col-sm-6 col-lg-3">…</div>
<div class="col-sm-6 col-lg-3">…</div>
<div class="col-sm-6 col-lg-3">…</div>
</div>
For a 4x1 layout on a large window and a 2x2 layout on a small window.
If you had to add a new .row container for each row, this would be impossible.
if you need the contents to be in the same Row then you can follow your example 1,
else you may proceed to following example 2 of your post.
Both are correct,depends on your requirement which one you want to use.
First example will put your columns inside same row but second example will create a seperate row for your col-md-12
Hope that helps
I'm new to Bootstrap and I came across this issue.
<div class="container row">
<div id="page" class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div id="header"></div>
<div id="article"></div>
<div id="footer"></div>
</div>
<div class="col-lg-2 col-md-1"></div>
In boostrap documentation it shows that I dont have to use the last div.
doc: <div class="row">
<div class="col-md-6 col-md-offset-3">.col-md-6 .col-md-offset-3</div>
</div>
6 + 3 = 9. There are 3 col missing. I just want to make sure I understood this well before progressing into more details.
IF there are col missing inside a row will row automatically add them?
Or will I have some sort of a surprise bug at the long run.
I was using the 1200px grid system before. and I always had to add the the cols in correct order and correct numbers.
6+3= 9 & The remaining columns/grids i.e 3 columns space will remain empty, it won't give any bug, it just center align the DIV having class col-md-offset-3 by moving it 3 columns from left and 3 columns on right are empty so the DIV will be center aligned.
Hope this will bring some clarity, thanks.
First: Don't put class container and row in the same div.
Answer: If you start a new row it will start counting from zero again.
You could put all your sections in separate containers.
<div class='container'><!--this is your container-->
<div class='row'><!--this is your row-->
<div class='col-md-4 col-md-offset-3'><!--populating row with col with offset-->
</div>
</div>
<div class='row'>
<!--some other cols will start counting from zero because it is a new row-->
</div>
</div>
I have the following simplified markup:
<div class="row">
<div class="col-lg-3" ng-if="isSuperUser()">
Conditional column 1
</div>
<div class="col-lg-3">
Column 2
</div>
<div class="col-lg-6">
Column 3
</div>
</div>
I want Column 3 to take up the last 6 grid columns always. I also want the contents of Column 1 or Column 2 if not a super user to take up the first 3 grid columns depending.
The problem is when the Column 1 is not displayed, Column 2 and Column 3 shift to the left such that Column 3 is no longer on the right side. A solution that seems hacky is to add a <div class="col-lg-3" ng-if="!isSuperUser()"> before Column 3, but it seems like there may be a better solution.
I can't see anything in Bootstrap's documentation that demonstrates this functionality. I see there is push and pull classes, but they don't seem to be what I'm looking for.
Thanks in advance.
JSBIN
you can try nest row into the .col-xs-*. That's mean you could use the out row to fixed position before you want hidden something.
<div class="container">
<div class="row">
<div class="col-xs-6">col 6
<div class="row">
<div class="col-xs-2">
2
</div>
<div class="col-xs-10">
10
</div>
</div>
</div>
<div class="col-xs-6">col 6
<div class="row">
<div class="col-xs-12">
your purpose
</div>
</div>
</div>
</div>
</div>
You are looking to offset columns in Bootstrap. Conditionally add the class .col-lg-offset-3 to the second column.
This question already has answers here:
Changing number of columns dynamically in Bootstrap grids
(2 answers)
Closed 9 years ago.
When using Bootstrap's fluid grid, is it necessary to declare a column when you want the content to span the entire width of the row. In other words, is this sufficient
<div class="row-fluid">
This column should span the full width of the row
</div>
Or is it really necessary to do this (as the docs suggest):
<div class="row-fluid">
<div class="span12">This column should span the full width of the row</div>
</div>
Also, when I want to nest columns in a fluid grid, according to the docs
Nesting with fluid grids is a bit different [to a non-fluid grid]: the number of nested columns should not match the parent's number of columns. Instead, each level of nested columns are reset because each row takes up 100% of the parent column.
The docs then go on to give this example where the first row is one full-width column and the second row has 2 half-width columns
<div class="row-fluid">
<div class="span12">Fluid 12
<div class="row-fluid">
<div class="span6">Fluid 6</div>
<div class="span6">Fluid 6</div>
</div>
</div>
</div>
Apart from the class name of the rows, I don't see how this is at all different to a non-fluid grid. Also, this example seems to contradict the statement
the number of nested columns should not match the parent's number of columns
Because last time I checked 6 + 6 = 12. Can someone improve on this explanation?
(1) I don't see how this is at all different to a non-fluid grid
It uses percentages
(2) the number of nested columns should not match the parent's number of columns
Well, bad example, what they simply mean is that the number in the class names should always add up to 12, regardless of what they are nested in.
This is correct:
<div class="row-fluid">
<div class="span6 row-fluid">
<div class="span4"> </div>
<div class="span4"> </div>
<div class="span4"> </div>
</div>
</div>
instead of this, which is wrong:
<div class="row-fluid">
<div class="span6 row-fluid">
<div class="span2"> </div>
<div class="span2"> </div>
<div class="span2"> </div>
</div>
</div>
I hope you can help me with this one.
I'm trying to transfer the layout of a PHP/SQL website currently using tables to CSS.
I already have the css working (thanks to Yahoo Grid Builder) but now I need to show it programmatically in my website after I have the info on an array (through $row = dbFetchAssoc($result))
I guess the solution is to use n%m to catch the condition I need but I'm struggling with It.
The css I need to replicate is this one, the two class="yui-g" create a row and each class="yui-u first" and class="yui-u" create a cell in that row, so this code gives you a table with 2 rows and 4 columns. I want to show a new item of my array in each "Item N" (cell).
<div class="yui-g">
<div class="yui-g first">
<div class="yui-u first">Item 1</div>
<div class="yui-u">Item 2</div>
</div>
<div class="yui-g">
<div class="yui-u first">Item 3</div>
<div class="yui-u">Item 4</div>
</div>
</div>
<div class="yui-g">
<div class="yui-g first">
<div class="yui-u first">Item 5</div>
<div class="yui-u">Item 6</div>
</div>
<div class="yui-g">
<div class="yui-u first">Item 7</div>
<div class="yui-u">Item 8</div>
</div>
</div>
Thanks for your help guys!
In general - HTML tables should be used to display tabular data, with CSS used to style those tables.
HTML + CSS should be used for layouts, rather than the old ways of using tables to position content.
Use <table> for tabular data (data that you would store in a table). Everything else should be using HTML with CSS. From the looks of your code you should be using tables.