Correct way to structure HTML with Bootstrap [closed] - html

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I've been using Bootstrap for some time now, structuring my HTML elements without really knowing if I'm doing it in a right way. It works but I would like to know if there is a better way of doing it.
Lets take this template for instance:
What I do first is that I try to divide the page into smaller pieces. In this case I would start by dividing the left and right column, giving the left column 4 and the right one 8 "columns". I would write and position the HTML/class attributes like this:
...
<div class="row">
<div class="col-md-4">
<div id="upperLeftCol" class="col-md-12"> ... </div>
<div id="lowerLeftCol" class="col-md-12">
<div id="uniqueId1" class="col-md-12">
<img src="#" alt="...">
<div class="col-md-12">
some messge
</div>
</div
<div id="uniqueId2" class="col-md-12">
<img src="#" alt="...">
<div class="col-md-12">
some messge
</div>
</div
</div>
</div>
<div class="col-md-8">
.......
</div
</div>
Well you get the picture. I try to divide each subsection as an own div and give it the col-md-12 class attribute since I've noticed it aligns best with the other div that has the same class annotation.
I'm sure there is a more correct way to do this. What is the "best" approach? Also when should I create a new "row"?

I prefer to use more rows:
<div class="row">
<div class="col-md-4">
<div class="row">
<div id="upperLeftCol" class="col-md-12"> ... </div>
The code is better to understanding for others persons and avoid some design errors when you are using dynamic cells.

Related

How to replicate this (pictured) layout using css or bootstrap

My Problem
I am new to Bootstrap. My boss wants me to replicate the following screen ( or as close as possible ):
Desired Layout
I have tried to do this myself using:
<div class = "row">
and
<div class = "col-lg-x">
... but I can't get the rows and columns right! So frustrating. I have tried and tried and tried.
Does anyone have any ideas how I would replicate the following layout easily?
Thank you so much for looking at my problem.
Regards,
John
Not sure if it's the way that you have put your code on to SO however it should look something like this
<div class="row">
<div class="col-sm-4">
4
</div>
<div class="col-sm-8">
<div class="row">
<div class="col-12 col-sm-12">
12
<div class="row">
<div class-"col-sm-4">
4
</div>
<div class="col-sm-8">
8
</div>
</div>
</div>
Edit: You may also wish to take a look at nesting to help you achieve this https://getbootstrap.com/docs/4.0/layout/grid/

What is best way to implement Bootstrap col-md-12 inside row? [duplicate]

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

Bootstrap Layout Issue - multiple columns tiled [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Hi I hope someone can help me. I am relatively new to Bootstrap and I can get my head around the column layouts and how they work. However I've come to a problem when I want to create different columns at different heights.
I am trying to achieve the following layout:
The issue I have is trying to get tab3 in that position, I need it stacked below tab2. I managed to sort out tab5 and 6 by adding in a margin as labelled but thought this would be too messy for tab3.
bootply (thanks #Gorostas)
With regards to the grid system of bootstrap you can always make columns inside other columns.
Ill just show the top half since you have done the bottom half.
<div class ="container">
<div class ="row"> <!--Use a Row to keeps columns on the same line for the top half-->
<div class="col-md-8"> <!--Tab 1-->
</div>
<div class="col-md-2"> <!--Space for Tab 2 and 3-->
<div class="row"> <!--Row is not necassery when using 12 but I use them for smaller columns viewed on a smaller viewport-->
<!-- "col-md12" make use of all spacing of the grid that is available within the parent-->
<div class="col-md-12"> <!--Uses up full portion of the col-md-2 spacing-->
</div> <!--Tab 2-->
<div class="col-md-12"> <!--Uses up full portion of the col-md-2 spacing-->
</div> <!--Tab 3-->
</div>
</div>
<div class="col-md-2">
</div> <!--Tab 4-->
</div>
<div class="row">
<!-- Bottom half of tabs-->
</div>
</div>
http://www.bootply.com/wG58MwAews
If you are using the default Bootstrap 3 your grid will be 12 blocks horizontal. If you make a new col in a col it will break that column into 12 and position it relative to the grid system, http://getbootstrap.com/examples/grid/, you can break it down into another 12 blocks like in my example.Comment if you want a more detailed explanation, but this should do the job.

Trying to learn basic layout principles (HTML, CSS) - Beginner's [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am new to learning HTML, CSS, and coding in general. I plan on coding a Bootstrap grid system based page, but was wondering how to add this functionality to it. I want a dropdown informational panel to appear (as shown in green) whenever a thumbnail is clicked. I want to achieve this using only HTML and CSS and using least code as possible.
I'd appreciate any sort of help.
Excuse my limited vocabulary in this field. Don't know what to call the "informational panel".
I would recommend using Bootstrap grid system.
It's a great way to get started with the layout of your page. It is simple to use and adapt to your own needs.Their grid system is also responsive.
To get you started with your layout:
<div class="row">
<div class="col-md-2">Logo</div>
</div>
<div class="row">
<div class="col-xs-6 col-md-3">
<a href="#" class="thumbnail">
</a>
</div>
<div class="col-xs-6 col-md-3">
<a href="#" class="thumbnail">
</a>
</div>
<div class="col-xs-6 col-md-3">
<a href="#" class="thumbnail">
</a>
</div>
<div class="col-xs-6 col-md-3">
<a href="#" class="thumbnail">
</a>
</div>
</div>
<div class="row">
...
</div>
You get the trick...
You need to place the row within a container class for proper alignment. Again see Bootstrap grid system.
OK, the long and short is you are on the right path. HTML and CSS are technologies, while what you seek is an art. http://www.w3schools.com/. learn about the div tag.

Bootstrap 3 nested grid not reset to 12

I'm somewhat new to Bootstrap 3 so forgive me if this seems far to obvious.
I've created a jsfiddle to start things off with which will hopefully help understand what I'm trying to ask: http://jsfiddle.net/dwdhj/2/
<div class="container">
<div class="row">
<div class="col-sm-8">
8
<div class="row">
<div class="col-sm-4">
4 - but want to appear as 6
</div>
<div class="col-sm-4">
4 - but want to appear as 6
</div>
</div>
</div>
<div class="col-sm-4">
4 - full height of screen
<br /><br /><br /><br /><br /><br /><br /><br /><br />
</div>
</div>
</div>
When a designer uses a grid - lets say from http://gridpak.com/ - they will stick to that throughout the whole design. If they were to create a right hand panel to be the full height of the screen it would take up perhaps 4 grids. This leaves us with 8 - good math I know.
My issue: If I create a new row inside that initial 8 - so that I can make everything in that container nice and fluid - it is essentially creating another 12 column grid. This new 12 column grid won't actually match up to the grid the designer was originally working from.
My Question: Can I make it so the grid remains the same within the initial 8 column div I used - so I can only use a maximum of 8 columns, or is there something else I should be doing here? Perhaps its something the designer needs to be doing?
I did see some examples of this with row-fluid on Bootstrap 2 but that has been done away with - for good reasons from what I've read.
Hopefully that has made enough sense - let me know if anything needs clarifying.
After doing some more research I found that a combination of using push/pull I was able to get the result I was after.
Review the updated jsfiddle link http://jsfiddle.net/dwdhj/3/
<div class="container">
<div class="row">
<div class="col-sm-12">
Header
</div>
</div>
<div class="row">
<div class="col-sm-4 col-sm-push-8">
4 - full height of screen
<br /><br /><br /><br /><br /><br /><br /><br /><br />
</div>
<div class="col-sm-8 col-sm-pull-4">
8
</div>
<div class="col-sm-4 col-sm-pull-4">
4
</div>
<div class="col-sm-4 col-sm-pull-4">
4
</div>
<div class="col-sm-4 col-sm-pull-4">
4
</div>
<div class="col-sm-4 col-sm-pull-4">
4
</div>
<div class="col-sm-3 col-sm-pull-4">
3
</div>
<div class="col-sm-2 col-sm-pull-4">
2
</div>
<div class="col-sm-3 col-sm-pull-4">
3
</div>
</div>
<div class="row">
<div class="col-sm-12">
Footer
</div>
</div>
</div>
Essentially my trouble was creating new rows all the time when what I needed to do was keep adding them next to each other and then when they reach the "sidebar" I add a "push" in to wrap it down to where the next "row" would have started.
Happy to be advised on a better way of doing this but it works for now.
I answered this back on my comments thread, essentially I took a different approach
http://jsfiddle.net/Yjn9V/1/
<div class="container">
<div class="row">
<div class="col-sm-12">Header</div>
</div>
<div class="row">
<div class="col-sm-4 col-sm-push-8">4 full height
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
</div>
<div class="col-sm-8 col-sm-pull-4">
<div class="row">
<div class="col-sm-12">12</div>
</div>
<div class="row">
<div class="col-sm-6">6</div>
<div class="col-sm-6">6</div>
</div>
<div class="row">
<div class="col-sm-6">6</div>
<div class="col-sm-6">6</div>
</div>
<div class="row">
<div class="col-sm-5">5</div>
<div class="col-sm-2">2</div>
<div class="col-sm-5">3</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">footer</div>
</div>
</div>
I would try this, as you're doing way too much push/pull on things where you could just do it once on a wrapper container, as you have a very simple layout.
Check it out, let me know here or back on my comments thread if this works or if you have quesitons.
I had the exact same problem as you. I came up with a solution that is either implemented with pure CSS (compiled SCSS, that is), hard-coded, or javascript - I put both of them below.
The idea for is the following: you have the percentage width of a div A in terms of the container and want to know the percentage for div B, which is descendent of A. There's an easy calculation you can do to figure out the percentage of div B in terms of the container - B/A*100, if I'm not mistaken. The calculation itself is in the comment of the CSS version (link to gist is below).
Please note that, for this to work, divs that descend from A and contain B shouldn't modify the width (much like bootstrap itself).
Solution based on CSS (SCSS, to be exact), that only accepts two levels of grid:
https://gist.github.com/royalsflush/8403942
Here I just loop through the possibilities of parent and child (hence the limitation of two levels).
And a JS solution that uses the calculations I did for the first solution and a tree traversal to adjust all the nested components of the grid.
demo: http://bootply.com/105852
and source: https://gist.github.com/royalsflush/8422780
For this, I used the same idea as the CSS solution, except I use recursion on it. Let me give an example to clarify: suppose you have A and B again, and also a div C, that descends from B. If you perform the calculation I stated above for B, you will have B in terms of the container and C in terms of B, which is the exact same situation we were with A and B. Hope that is clear, not my best explanation.
Both have a demo and plenty of comments, but please let me know if you need further clarification.
Hope it helps!