Hi, sometimes learning something makes you more confused, I am in that position right now, thanks in advance.
I asked a question in this address: Why <div class="clear"></div> used?
After getting the answer and accepting (I also read the links given in comments section), now I've 2nd and 3rd questions.
According to the input codes given in related question,
Why grid demo code below didn't use <div class="clear"></div>? Again there exist 2 sets of two floating div elements so isn't it suitable to use <div class="clear"></div> just after the last floating div elements?
I explicitly mention that I would expect <div class="clear"></div> code in 2 places: Just after <div class="col col_7"> and just after <div class="col col_4">
<div class="row">
<div class="col col_1">col_1</div>
<div class="col col_7">col_7
<div class="row">
<div class="col col_3">col_3</div>
<div class="col col_4">col_4</div>
</div><!-- row -->
</div>
</div><!-- row -->
</div><!-- col_8 -->
The owner of accepted answer wrote that: "Without this the content following your nav element may appear alongside your nav element rather than below it." Since he used MAY grammar & I deleted <div class="clear"></div> and saw that nothing has changed in output for IE9 and Chrome 25.0.1364.172; what maked him to write MAY? Old browsers (especially old IE versions)?
This depends on your CSS that is associated with the different classes/ids/elements in your HTML.
<div class="clear"></div> ALWAYS has some css associated with it, that is:
.clear { clear: both; }
The above CSS is what makes it prevent that floating issue. That said... Using a "clear div" as you have shown above is one of many ways to do this.
In your particular case, given this HTML:
<div class="row">
<div class="col col_1">col_1</div>
<div class="col col_7">col_7
<div class="row">
<div class="col col_3">col_3</div>
<div class="col col_4">col_4</div>
</div><!-- row -->
</div>
</div><!-- row -->
</div><!-- col_8 -->
It is very likely that the class of "row" has the clear: both; property in CSS. That would explain why when you remove the clear div, it stayed the same. Essentially you didn't need the clear div, because the row class already has the CSS attached to it to prevent that issue from happening.
The selector probably looks like this: .row { clear: both; } The .row class probably has other CSS associated with it as well, another very likely property is overflow: hidden; That property can also effect how your divs and surrounding divs interact/behave next to each other.
To summarize: It is NOT the HTML <div class="clear"></div> that prevents this floating issue from happening. It IS the CSS property and value clear: both; which can be applied to any HTML element that prevents the issue from occurring.
Some resources:
CSS Wiki on Overflow property
CSS Wiki on Clear property
Hopefully this clears that up for you? (pardon the pun haha)
Related
I'm trying to create a print-friendly version of a webpage, however, the webpage and the print preview in Internet Explorer 11 have some mysterious blank space beneath the div's.
I have checked all the CSS classes, html markup, etc.
Setting the height makes no difference
Setting margin and padding to 0 makes no difference
It is just a huge white block beneath each div - there's nothing associated with it, so I do not understand why IE is putting it there.
Example:
<div class="row"> ## this has the big white space beneath it, after its closing tag
<div class="medium-12 columns"> ## this is the correct height
<!-- content -->
</div>
</div>
## WHITE SPACE HERE ##
## around 20-30 lines long ##
<!-- next div begins here -->
CSS rules on the affected tag:
padding: 0 0 5px 0;
page-break-inside: avoid;
margin: 0 -.9375rem;
max-width: none;
width: none;
overflow: hidden;
Does anybody have any ideas as to why this may be?
I see that you have tried zeroing out the margins, but I would suggest that You must try and add a reset for your stylesheet. CSS resets remove nearly all browser presets that usually interfere with custom stylesheets that include various types of document styles.
You just need to add it as a separate file link in your document, or simply copy and paste the code in your main CSS file, before all of your custom styles.
There are a few options out there regarding CSS resets, but I think that Mr. Mayer's reset would do the best job here.
Edited:
As i see that you are using Foundation, i have seen that foundation grid have some kind of issue adding negative margin values like that margin: 0 -0.9375rem;
Basically the 0.9375 is the main margin for your grid, rendered from SCSS to CSS. To avoid additionally compounding margins on nested columns, Foundation applies a negative padding to equalize.
If you're having problems with nested rows, make sure each sub .row is contained withinin a "small-xx ... columns" class, this should bring the edges back to normal.
Don't do this:
<div class="row">
<div class="small-6 columns"></div>
<div class="row">
<div class="small-3 columns"></div>
<div class="small-3 columns"></div>
</div><!-- .row -->
</div><!-- .row -->
Instead do this:
<div class="row">
<div class="small-6 columns"></div>
<div class="small-6 columns">
<div class="row">
<div class="small-6 columns"></div>
<div class="small-6 columns"></div>
</div><!-- .row -->
</div><!-- .small-6 .columns -->
</div><!-- .row -->
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.
My markup:
<div class="container">
<div class="row">
<div class="col-xs-12"></div>
<div class="col-md-8 col-md-offset-2 col-sm-10 col-sm-offset-1 col-xs-12">
<div class="row"> <!-- this has 0 height -->
<div class="col-xs-6"></div>
<div class="col-xs-6"></div>
</div>
</div>
<div class="col-xs-12"></div>
</div>
</div>
What can be the reason that the nested row has correct width, 0 height and can't have a margin-bottom, no matter what contain its colums?
Interesting thing, when I positioned absolutely a pseudoelement ::after for this row, it resolves correctly sizes like top: 50% but only if the problematic row has position: static and not when it has position: relative.
The row's height might be collapsing due to its floated children? Try adding a clearfix to clear the row of its children's floats:
<div class="row clearfix">
I'm not entirely sure without seeing any of your own CSS that could be also causing issues, but the above might resolve the issue. FYI - The clearfix class ships with BootStrap.
Here's a good read and other information on clearfix: What is a clearfix?
I reproduced the problem: http://jsfiddle.net/phn3Lae6/1
When you remove position: absolute from ::after pseudoelement, row behaves normally.
Since ::before and ::after pseudoelements are an important part of Bootstrap grid, probably the best solution here is to not mess around with them, but to create a separate element inside the grid element to be a pseudoelement parent, for example like:
<div class="row">
<div class="pseudoelement-parent">
<div class="col-xs-6"></div>
<div class="col-xs-6"></div>
</div>
</div>
.pseudoelement-parent {
position: relative;
}
I'm trying to copy bootstrap's columns and I was also wondering why my row's height is 0. It turned out that display: table;, content: " "; and clear: both; are all important for the row's height.
I hope this helps someone.
I have a layout built using CSS display:table (inline, row, cell, etc). I'm doing local development on it with apache, and when I refresh the page, two of the div containers are incorrectly lined up. However, if I uncheck and re-check display:table-row, they correct themselves, and the page displays correctly.
http://jsfiddle.net/fNNKT/
You can see the HTML and CSS at the jsFiddle above. It's actually not working there either, so maybe I'm doing something wrong, and can use help with that.
<div class="cabinet-container">
<div class="mode-bar">
<div class="mode-bar-left">
<div class="mode-bar-item">logo</div>
<div class="mode-bar-item active">Dispense</div>
<div class="mode-bar-item">Inventory</div>
</div>
<div class="mode-bar-right schedule">
<div class="mode-bar-item">Sign-Out</div>
</div>
</div>
<div class="table"></div>
<div class="left-container"></div>
<div class="center-container">
<div class="search-container">
<div class="table-cell">
<div class="search-field"></div>
</div>
</div>
<div class="nav-button-center-container">
<div class="table-cell">
</div>
</div>
<div class="list">
<div class="table-cell">
<div class="list-item-center-container"></div>
<div class="list-item-center-container"></div>
<div class="list-item-center-container-partial"></div>
</div>
</div>
<div class="nav-button-center-container-down-active">
<div class="table-cell"></div>
</div>
</div>
<div class="footer">
<div class="button-group table-border-5">
<div class="button-secondary">Dispense Non-Drug</div>
<div class="button-secondary">Sort By: Last Name</div>
</div>
<div class="button-group-right table-border-5">
<div class="button-primary">New Clinical Order</div>
</div>
</div>
</div>
Is your question related to .mode-bar-left and .mode-bar-right wrapping onto two lines? If so, the problem relates to whitespace. Think of two images displayed inline, side by side. If there's whitespace between the tags in the code, there will be whitespace displayed in the browser.
Solution #1:
Take your logic one level higher up in the DOM. Change the display value for both mode-bar elements to table-cell (instead of the current inline-table). Then change the .mode-bar-item elements to display: inline-block (instead of table-cell).
Solution #2:
A faster, less elegant solution is to add float: left to .mode-bar-left.
On the topic of elegance, I strongly recommend that you consider some more semantically meaningful tags than just div. For example, .mode-bar-left is clearly a list (ul perhaps?) and the .mode-bar-item elements are clearly list items (li).
Are you using any javascript/jQuery? On a recent project of my own, I was having a similar issue and all I had to do was move my custom lightbox script from the to right before the tag, and it seemed to fix the issue. Sometimes javascript can be wonky like that. I don't understand why, but that's the way it is.
<div style="float:left;">
column 1
</div>
<div style="float:left;">
column 2
</div>
<div style="clear:both;"></div>
I'm used to writing clear:both. But I heard in Twitter Bootstrap there is something called "clearfix"? On which element should/would I apply "clearfix"?
You probably only have to do:
<div class="container">
<div class="row">
<div class="span6">column 1</div>
<div class="span6">column 2</div>
</div>
</div>
clearfix should not be necessary.
using css you can simple use the after psudeo
.class1:after, .class2:after //append as many as you like
{
clear:both;
*zoom:1;
height:0;
visibility: hidden;
display:block;
}
alternative(providing children are not using the position selector)
(parent-elemts){overflow:hidden;}//bit of a quick fix!
keep unwanted markup out of your html file
Edit: sorry! for some reason the add comment button or upvote button is not working for me tonight.
To append my answer to answer your other question:
twitter bootstrap you say uses a .clearfix class, which is similar to the css I provided below, however their method needs to be added to the element, ie: "element class="clearfix" OR similar, where as css pseduo's we dont need to add this extra bit of code to our document. Take note however, not all browsers support css pseduo's.