On my web page, I have spaces between the rows (each section of the page is it's own row). As seen below in the responses, I had "Colspec" tags where my "Col-md" tags should've gone. I also didn't have the 'row' tag in there. Fixed those, thanks to those that helped. I've tried replacing the 'colspec' tags with the 'col-md-12' tags. This gave me spaces on the sides of each row/column, which I also don't like. I have since pulled out the 'col-med' tags. The rows now go all the way to each side. Great. However, I still have spaces between each row.
In an attempt to be more clear, here is the code for one of my rows:
<div class="container-fluid">
<div class="row">
<div class="classWithPad2">
<h1 class="customfont">TEXT</h1>
<div class="classWithPad">
<p class="customfont">TEXT<span tabindex="0" data-term="goog_20335794">TEXT<br>
TEXT<br>
TEXT<a href="mailto:XXX#XXXXX.com">
<span class="glyphicon glyphicon-envelope"></a><br>
</p>
</div>
<div class="classWithPad2"><h1 class="customfont">PRICES</h1>
<div class="classWithPad">
<p class="customfont">TEXT<br>
TEXT</p>
</div>
</div>
</div>
Each row is coded similarly.
SITE IS HERE
What does colspec-md-12 do in your HTML? You have assigned colspec-md-12 as class to many divs. Replace that with col-md-12 which is a bootstrap class, which will remove the blank spaces.
As others mentioned in their comments, your markup is not at all valid.
For the bootstrap to work correctly, the col-md-12 class should be nested inside a .row class, which itself should be nested inside a .containerclass.
Please see the official page of bootstrap for more details
There are multiple issues here
One, the class should be col-md-12 instead of colspec-md-12
Second of all, the col-md-12 class should be nested inside a .row class, which should itself be nested inside a .container or .container-fluid class. It should look something like this
<div class="container">
<div class="row">
<div class="col-md-12">
</div>
</div>
</div>
The space between sections indicates that there is a margin between these sections. Probably has to do with these lines of code
.classWithPad {
margin:30px;
}
.classWithPad2 {
margin:15px;
}
It looks like you are confusing margin with padding. I'd change the margin property to padding property, which allows space at the end of the section, instead of between sections.
Related
I just want to be sure about some basic HTML structuring.
Most HTML page body layouts start with a <div class="container"> which of course contains all the HTML in with boostrap v4 it contains rows and columns.
All nice and easy there.
My question is, am I "correct" or not to place columns and rows within separate containers?
This is what I mean:
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
Some Content
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
Some Content
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
Some Content
</div>
</div>
</div>
</div><!-- end body -->
I think the answer to my question is that "it is ok" because for example what happens if you want a full-page width div container then you'd use a separate container for those elements.
I just want to be sure, thanks!
As per your example, if the content has to be inside the container, then using multiple containers is redundant. Use a single container and then separate the rows.
This approach also depends heavily on the design.
Full page width div, YES, the separate container is correct.
Note : For full width
Use container-fluid for full width, and remove the padding as well.
container-fluid class has padding-left : 15px and padding-right: 15px.
You can remove it to cover the div end to end. You can use pl-0 and pr-0, classes provided by bootstrap to set padding-left and padding-right to 0, respectively.
I am using Twitter Bootstrap for my grid system. I have a JS script that gets a list of items from an XML file. Every item that I get from this file should be inserted into the grid with it's own column. To make it easier to insert these items into the DOM, I use a div called news-results and just append it each time the script loops through the next item in the XML.
<div class="container">
<div class="row">
<h1>Recent News</h1>
<div id="news-results">
<div class="col-lg-4 col-md-6 col-sm-12 col-12">
<div class="card">
<div class="card-body">
<h3>{news_title}</h3>
<p>{news_body}</p>
<div class="card-footer text-muted">
<div class="card-link">
<h6>Posted on {news_date}</h6>
</div>
<div class="card-link">
Read More
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
The problem with this is that the news-results div seems to be affecting the layout of the grid. The cells stack on top of each other instead of the way they should be. If I copy the HTML of only the newly inserted news items and insert it into the page without the news-results div, it works fine.
Is there an element I can use to easily identify to the script where in the page the elements should be inserted?
Here is a JS fiddle to demonstrate. If you remove the news-results tag, you'll see what I mean.
I found a solution that works for me.
#news-results {
display: contents;
}
It basically makes the div act as strictly a placeholder for the content HTML.
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.
I have several elements I want to display on a page, and I am using Angular's ng-repeat to do it. I want to display it by having a 3x3 column, so I am using Bootstrap's col-md-4. My HTML is as follows:
<div ng-controller="resourcesController">
<div class="main-body">
<div class="container-fluid">
<div class="resources">
<div ng-repeat="org in orgs" class="col-md-4">
<img src={{org.icon}}>
</div>
</div>
</div>
</div>
</div>
However, the elements are appearing like so:
How can I center the elements and spread them over evenly across the page while using ng-repeat? Thank you!
My suggestion would be that it is not enough to use only one ng-repeat.
Instead, you could separate your orgs array into an array of arrays representing rows of columns.
Then you could modify the code similarly to below (making it easier to apply the grid format you want):
<div ng-repeat="orgRow in orgRows" class="rowClass">
<div ng-repeat="orgElement in orgRow "class="columnClass" >
<img src={{org.icon}}>
</div>
</div>
A simple bootstrap helper class text-center should do most of it for you
<div ng-repeat="org in orgs" class="col-md-4 text-center">
In addition could add class to the <a> tags and:
a.content-class{display:block; text-align:center}
If my page uses the Bootstrap class row, col-md-x and such to arrange the content, what would be the proper way to create a distance between each div containing a whole element semantically speaking?
I am adding a div with a padding between the divs to simulate the gap, is this a good tactic or is there a better one?
Starting from Bootstrap v4 you can simply add the following to your div class attribute: mt-2 (margin top 2)
<div class="mt-2 col-md-12">
This will have a two-point top margin!
</div>
More examples are given in the docs: Bootstrap v4 docs
Adding a padding between the divs to simulate a gap might be a hack, but why not use something Bootstrap provides. It's called offsets. But again, you can define a class in your custom.css (you shouldn't edit the core stylesheet anyway) file and add something like .gap. However, .col-md-offset-* does the job most of the times for me, allowing me to precisely leave a gap between the divs.
As for vertical spacing, unfortunately, there isn't anything set built-in like that in Bootstrap 3, so you will have to invent your own custom class to do that. I'd usually do something like .top-buffer { margin-top:20px; }. This does the trick, and obviously, it doesn't have to be 20px, it can be anything you like.
I required only one instance of the vertical padding, so I inserted this line in the appropriate place to avoid adding more to the css. <div style="margin-top:5px"></div>
The easiest way to do it is to add mb-5 to your classes. That is <div class='row mb-5'>.
NOTE:
mb varies betweeen 1 to 5
The Div MUST have the row class
An alternative way to accomplish what you are asking, without having problems on the mobile version of your website, (Remember that the margin attribute will brake your responsive layout on mobile version thus you have to add on your element a supplementary attribute like #media (min-width:768px){ 'your-class'{margin:0}} to override the previous margin)
is to nest your class in your preferred div and then add on your class
the margin option you want
like the following example:
HTML
<div class="container">
<div class="col-md-3 col-xs-12">
<div class="events">
<img src="..." class="img-responsive" alt="...."/>
<div class="figcaption">
<h2>Event Title</h2>
<p>Event Description.</p>
</div>
</div>
</div>
<div class="col-md-3 col-xs-12">
<div class="events">
<img src="..." class="img-responsive" alt="...."/>
<div class="figcaption">
<h2>Event Title</h2>
<p>Event Description. </p>
</div>
</div>
</div>
<div class="col-md-3 col-xs-12">
<div class="events">
<img src="..." class="img-responsive" alt="...."/>
<div class="figcaption">
<h2>Event Title</h2>
<p>Event Description. </p>
</div>
</div>
</div>
</div>
And on your CSS you just add the margin option on your class which in this example is "events" like:
.events{
margin: 20px 10px;
}
By this method you will have all the wanted space between your divs making sure you do not brake anything on your website's mobile and tablet versions.