Bootstrap 3 grid in less vs in html - html

What is the best practice for implementing the bootstrap 3 grid? There are two options, via classes in html and via less mixins.
Using bootstrap classes in html and bootstrap.css (which seems to be the standard):
<div class="container">
<div class="row">
<div class="column-md-6 column-xs-8">
<p>test</p>
</div>
<div class="column-md-6 column-xs-4">
<div class="row">
<div class="column-md-8 column-xs-6">
<p>Another test</p>
</div>
<div class="column-md-4 column-xs-6">
<p>Yet another test</p>
</div>
</div>
</div>
</div>
</div>
Using LESS and bootstrap mixins and appropriate html structure:
<div id="maincontent">
<div id="maincontentarea">
<div id="blogarticles">
<p>test</p>
</div>
<div id="whatsnew">
<div id="whatsnewarea">
<div id="whatsnewheading">
<p>Another test</p>
<div>
<div id="whatsnewlist">
<p>Yet another test</p></div>
<div>
</div>
</div>
</div>
<div>
and the corresponding LESS:
#maincontent{
.container();
#maincontentarea{
.make-row();
#blogarticles{
.make-md-column(6);
.make-xs-column(8);
}
#whatsnew{
.make-md-column(6);
.make-xs-column(4);
#whatsnewarea{
.make-row();
#whatsnewheading{
.make-md-column(8);
}
#whatsnewlist{
.make-xs-column(6);
}
}
}
}
}
It sounds like a nice idea to have a .LESS file simply using the bootstrap mixins to define the structure, but is that not essentially duplicating the element structure in the less file which is already defined in LESS. Which one is more maintainable?

Personally i think using Bootstrap's class will give you a maintainable structure. Otherwise you could prefer a more semantic solution. Note your appropriate html structure don't have added value in my opinion and is not semantic.
Using and implementing Bootstrap in a more semantic way won't be always easy:
Example of problem with the grid to have to solve: How can I create multiple rows using semantic markup in Bootstrap 3?. Also Twitter's Bootstrap 3.x semantic mobile grid and especially pay attention to the answer of #Gravy (https://stackoverflow.com/a/18667955/1596547).
Also interesting : How to use sass to properly avoid embedding twitter bootstrap class names on HTML

Related

Bootstrap 4 grid layout not working with dompdf

I am using dompdf to render a PDF document. We use Bootstrap 4 on the whole application, so I would like to be able to use it in the twig template used to generate our document.
Currently, I'm facing a problem with Bootstrap 4 grid system not rendering well in the generated PDF: the element in a same .row div all pile up.
I'm sure the Bootstrap CSS is loaded in the template.
My code:
<div class="container-fluid">
<div class="row">
<div class="col-xs-1">
little text
</div>
<div class="col-xs-11">
<h1>Big title</h1>
</div>
</div>
</div>
The generated PDF:
Update: with col-n instead of col-xs-n
My code:
<div class="container-fluid">
<div class="row">
<div class="col-1">
little text
</div>
<div class="col-11">
<h1>Big title</h1>
</div>
</div>
</div>
try this class .col-1 and .col-11, or .col-sm-1 .col-sm-11
avaible:
.col- .col-sm- .col-md- .col-lg- .col-xl-
col-xs it's for bootstrap 3
I had the same problem.
Than I found this issues related at: https://github.com/barryvdh/laravel-dompdf/issues/653
One tip tha I tried was changing the class col- to col-xs- than the layout is better now. Not perfect as in browser but better than before.
I'm using bootstrap v4.4.1.
Pdf after change:

CSS Grid: Using an element to encompass grid elements?

I've created a typical layout using CSS Grid with this structure:
<div class="dashboard">
<header></header>
<nav></nav>
<div class="main-header"></div>
<div class="main-content"></div>
<div class="main-footer"></div>
</div>
Now, due to our environment (PHP, Smarty Templates, AngularJS), I would like to split these up into separate components. But here is the issue… I can't wrap an element around grid elements without breaking the layout:
<div class="dashboard">
<header></header> <!-- component -->
<nav></nav> <!-- component -->
<div class="wrapper"> <!-- component -->
<div class="main-header"></div>
<div class="main-content"></div>
<div class="main-footer"></div>
</div>
</div>
I've experimented with nesting another grid inside of 'wrapper', but that introduces more layout issues, such as improper scrolling. (…and nesting grids doesn't sound like a good idea).
I am wondering if there is some CSS to "pass through" the 'wrapper' div to maintain the css grid properties?
Or is there another way to handle this situation?
Thanks!

Bootstrap3: what is standard Structure and Layout?

There is a lot of tutorial about bootstrap elements.
But I want to know where I must use nav/header/container/row/well/panel/section
for example..Do it needs use row for column 12?
1- currently I do it this way:
<body>
<div class="container-fluid"> /*only for top navbar*/
<nav>
</div>
<div class="container"> /* for body */
<header></header>
<main class="row">
<div class="col-md-2"></div>
<div class="col-md-5"></div>
<div class="col-md-5"></div>
</main>
<footer class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</footer>
</div>
</body>
Is it true?
2- Is this format true or necessary?
<div class="row">
<div class="col-md-12"></div>
</div>
3- which one is standard?
<div class ="well">
<div class="row"> <div class="col-md-*"></div> </div>
</div>
or
<div class ="row">
<div class="well"> <div class="col-md-*"></div> </div>
</div>
4- dose it need use "container" class for all section or only for parent section?
for 1:- yes it's a correct method. whenever you want to use bootstrap column classes like col-xs-12 in their first parent you must put class " row ".
for 2:- this is true. method also accessory.
for 3:- first option is correct.
for 4:- depends of need of page design. if all site are in same container with then you can put it in parent class.
All options you mentioned are correct.
However, below written structure makes sense. That means if you are using col in container or container-fluid it should be in row.
<div class="container">
<div class="row">
<div class="col-*-*">
</div>
</div>
</div>
If anytime you want to check how well your bootstrap is written, you can check it on http://www.bootlint.com/
But I want to know where I must use nav/header/section/footer
Well all these fields are only for semantic purpose, actually they all could be div. In the future or even now it is best practise for SEO to use nav for navigation, footer for the footer etc. For example header should be used to introduce content, it often contains <h1> - <h6> tags.
There are many informations to this in the web, here is a reference
All the other bootstrap classes are just styles which you could apply by yourself. A container for example can be used once for all of your content if you never need a full width element, but sometimes you have a situation where you need a full width element (f.e. an image) then you dont want to wrap all of your content into container.
Here you want to use multiple containers and not one for everything (Fiddle)
Hope this helps you a bit.

CSS pseudo-classes

I have a problem, maybe it's obvious, but I couldn't find any answers how to do this.
I have a structure like this on my website:
<div class="row-even">
<article class="featured-job">a</article>
</div>
<div class="row-odd">
<article class="featured-job">b</article>
</div>
<div class="row-even">
<article class="regular-job">a</article>
</div>
<div class="row-odd">
<article class="regular-job">b</article>
</div>
<div class="row-even">
<article class="regular-job">c</article>
</div>
This tiny thing is generated by PHP for listing some articles from two types, a Featured job, and a Regular job. I want to separate these two content types by adding a margin-top for the first one of the .regular-job articles. I tried using first-line, first-child, first-of-type, all from the first-* and even tried nth-child, but nothing worked for me.
(I know these separators working on the parent of the element I am using on.)
Is there any way it can be done?
The problem with first-child and regular-job is that the articles are not directly in the same parent because they are nested in row-even & row-odd. You either could wrap the regular-job rows in another div which gets the margin applied or add another class to the first row containing a regular-job. You could even add a class directly to the first regular-job.
I don't know how you PHP loop looks like, but maybe try to use a counter for that matter.
If needed I will gladly provide an HTMl/CSS example!
You would probably want to do someting like that:
div:first-child .regular-job {
margin-top: 20px;
}
You select the first parent element that has the child of .featured-job.
PS. Be careful where you are applying the margin, it won't work on inline elements or if you want to separate the parent elements then applying it to the article is not a good idea.
As Sven says, the problem is that you need the elements to be siblings for this selectors to work.
Set a class in the parent, matching the one of the child:
HTML
<div class="row-even featured-father">
<article class="featured-job">a</article>
</div>
<div class="row-odd featured-father">
<article class="featured-job">b</article>
</div>
<div class="row-even regular-father">
<article class="regular-job">a</article>
</div>
<div class="row-odd regular-father">
<article class="regular-job">b</article>
</div>
<div class="row-even regular-father">
<article class="regular-job">c</article>
</div>
Then, it is easy to set the CSS. for instance:
.featured-father + .regular-father article {
background-color: red;
}
fiddle
while iterating in the PHP, add another dummy class with index.
Then it will be a piece of cake to make your custom class:
<div class="row-even featured_1">
<article class="featured-job">a</article>
</div>
<div class="row-odd featured_2">
<article class="featured-job">b</article>
</div>
<div class="row-even regular_1">
<article class="regular-job">a</article>
</div>
<div class="row-odd regular_2">
<article class="regular-job">b</article>
</div>
<div class="row-even regular_3">
<article class="regular-job">c</article>
</div>
notice the two introduced classes: featured_X and regular_X.
then:
.regular_1{
margin-top:50px;
}

In Twitter Bootstrap, should a Grid Column be its own special Div?

When using Twitter bootstrap's grid system, should every grid column div (with the class span*) have span* class as its only class, like:
<div class="row">
<div class="span4">
<div class="sidebar">...</div>
</div>
<div class="span8">
<div class="content">...</div>
</div>
</div>
Or can we mix span* class with other classes, like:
<div class="row">
<div class="span4 sidebar">
...
</div>
<div class="span8 content">
...
</div>
</div>
.sidebar and .content are CSS rules and not simply for Javascript/CSS rule traversal or used as IDs.
It depends on what those other classes do.
If .sidebar and .content are used exclusively to scope CSS inside those divs, or if they are labels for javascript traversal, then you are probably fine using them.
However, if you have rules attached to these classes that impact layout such as width, height, margin, and so on, you may experience problems.