overide zurb foundation float right property for last element - css

I am using Zurb foundation and I am trying to create a css property that will be called and override the property float:right that they give the the last column. I know that they provide the end class to make you able to float a div on the left, but I have a case where I really have to make sure that my css property is the one to be called at the end.
code:
<div class="row">
<div class="my-class small-6 columns">floated on the right by foundation</div>
</div>
.my-class{
float:left;
}
the above code does not work, but it works when I add the important property which is something I want to avoid as well.

I found this question when dealing with dynamic content. In this case, I didn't know how many items I would ultimately have and didn't want to override foundations default behavior. The solution in this case was Foundation's block grid:
http://foundation.zurb.com/docs/components/block_grid.html
As an example, the way I initially tried to implement this was by wrapping each repeating element in a div with that amount of columns it should use like this:
<div class="row">
<div class="columns small-3">content</div>
<div class="columns small-3">content</div>
<div class="columns small-3">content</div>
<div class="columns small-3">content</div>
<div class="columns small-3">content</div> <!-- Floated right. -->
</div>
Instead, the better way to do this is to use Foundation's block grid class, which specifies how many items should be in each row, like this:
<div class="row">
<ul class="small-block-grid-4">
<li>content</li>
<li>content</li>
<li>content</li>
<li>content</li>
<li>content</li> <!-- Right where I expected it! -->
</ul>
</div>
Hopefully that help some fellow Googlers. :-)

In HTML/CSS, you need to make sure that your custom class is more specific than the class you're overriding and that your CSS is loaded after Zurb's CSS.
Zurb has the following class;
[class*="column"] + [class*="column"]:last-child {
float: right; }
Which means attribute class contains "column" and is last in parent. To be able to override this, try adding this to the end of your CSS file that is loaded after Zurb's and change the div to <div class="small-6 columns my-class">
[class*="my-class"]:last-child {
float: left;
}

Related

Bootstrap visibility classes working but content not removed from markup

I am using bootstrap visibility classes as follows on my webpage:
<div class="hidden-sm">
<div id="lrg-div-A"></div>
</div>
<div class="hidden-lrg">
<div id="lrg-div-B"></div>
</div>
<div class="hidden-md">
<div id="lrg-div-C"></div>
</div>
The visibility classes work and are hidden in the viewport where required. But, when I look at the markup in the browser's developer tools, I still see the markup for the hidden divs. For example, on large screens, "lrg-div-B" is not seen in the viewport, but the markup is still seen in the HTML tab. Is there anyway to remove it from the markup as well, similar to what 'dispaly: none' does?
display: none doesn't remove it from the markup, but it does remove it from the document flow so that it doesn't take up space. You can remove a node with javascript using remove() or removeChild() but mind you can't get it back again (unless you store it and re-append it later).
console.log('Hidden node: ', document.querySelector('.hidden-sm'));
//Hidden node: <div class="hidden-sm">…</div>
console.log('Before remove(): ', document.getElementById('lrg-div-B'));
// Before remove(): <div id="lrg-div-B">large B</div>
document.getElementById('lrg-div-B').remove();
console.log('Removed node: ', document.getElementById('lrg-div-B'));
// Removed node: null
.hidden-sm {
display: none;
}
<div class="hidden-sm"> <!-- hidden but still in markup -->
<div id="lrg-div-A">large A</div>
</div>
<div class="hidden-lrg">
<div id="lrg-div-B">large B</div> <!-- removed from markup -->
</div>
<div class="hidden-md">
<div id="lrg-div-C">large C</div>
</div>
It is not supposed to remove the elements from markup. CSS handles how DOM looks not its structure. You need to use a bit of Javascript if you actually want to remove the DOM elements.

center a div within organized column system

I am creating a web page and wanted to use a system similar to foundations/ bootstrap with defined columns and rows. I am happy with what I have so far, however I am not sure how I can center a column within a row, while still using a defined grid system.
I know usually the html is formatted like this:
<div class="column column-6 center">
http://codepen.io/Kiwimoose/pen/dpvEqO
Is what I have so far,
I am just not sure how the "center" tag is usually formatted in foundations. I would like to have the column in the second row centered, as well as others in the future.
Your code is OK, you just have to change the order in CSS:
.column {
position: relative;
float: left;
display: block;
}
.center {
margin:auto;
float:none;
}
Style .center class after . column class and it will work.
BTW, it is a good idea to clean up your code a little bit.
Try
<div align="center">
And then you can customize it in the css that you're doing
In Zurb foundation you can use "-offset-" and "end" class names,
for example
<div class="row">
<div class="large-6 large-offset-3 end columns">6 centered</div>
</div>
docs here
to center properly (with no headaches) with Twitter Bootstrap you can simply set empty divs as follows:
<div class="row">
<div class="col-xs-3"></div>
<div class="col-xs-6">
centered div in all resolutions
</div>
<div class="col-xs-3"></div>
</div>
Or you can use offset too

Why "clear:both;" CSS doesn't work in a responsive theme?

I have added the "clear:both;" css command to my responsive theme,however it doesn't work,elements wrap around my block.
Here is the HTML of my block:
<div id="block-views-categories-normal-view-block-1" class="block block--views contextual-links-region block--views-categories-normal-view-block-1">
<div class="contextual-links-wrapper contextual-links-processed">
<div class="block__content">
<div class="view view-categories-normal-view view-id-categories_normal_view view-display-id-block_1 view-dom-id-4d6cdd2580eef8f5826096ea0f8157c1">
<div class="view-content">
<div class="responsive-table-wrapper">
<div class="responsive-table-scroller">
<table class="views-view-grid responsive-table-processed">
etc
I have tried
#block-views-categories-normal-view-block-1{
clear:both;
}
and
.views-view-grid {
clear:both;
}
Am I missing something?
Need to see some more code and corresponding CSS to answer.
My guess is that you're not clearing the float of the proper element.
By putting clear: both on the table class, you're telling it to clear the float of some child table elements.
Unless you altered the display property of the table elements, your clear is in the incorrect place.
You need to clear the parent of your floats to fix the painting issue in the browser.

Embedding Bootstrap class properties into another class

I'm using Bootstrap to set up my site layout and have something like:
<div class="row-fluid">
<div class="span3">
</div>
<div class="span9">
</div>
</div>
That works fine. However, I'm slightly bothered by the fact that this is defining the presentation in the markup and to make it easier to make future changes, I'd like to add another layer of indirection. I'd like to add my own class that defines the semantics and then include the Bootstrap class that defines the layout presentation. For example:
<div class="main-block">
<div class="side-bar">
</div>
<div class="content-area">
</div>
</div>
and my corresponding less file...
#import "twitter/bootstrap";
.main-block { .row-fluid }
.side-bar { .span3 }
.content-area { .span9 }
The less documentation states that you can "embed all the properties of a class into another class by simply including the class name as one of its properties" so it looks like it should work, but I am getting an error:
.row-fluid is undefined
Is there something that I am missing? Or is there a better way to go about this? This is in a rails 3.2 project using the less-rails-bootstrap gem if that makes any difference.
It's a little bit more complicated. What you're referring to is essentially what "mixins" are all about. First, let's resolve the error. From the little I see my bet is that you are trying to compile a "custom".less file and that you did not #import the variables.less and mixins.less files at the top of the page. Is that correct? If so, see if that gets the code to compile as expected.
However, once you get the code to compile you'll see that you have a new problem. In this particular case, by attempting to use a name other than .span you will lose any styling that is applied by the attribute selectors in the grid mixin, namely [class*="span"]. Compiled, it looks like this:
[class*="span"] { float: left; margin-left: 20px; }
.row-fluid [class*="span"] {}
.row-fluid [class*="span"]:first-child { margin-left: 0; }
So in this case the attribute selectors apply their styles to any class that starts with "span".
Here are a couple of options that might be better for you:
1) Adding the word "span" before your custom class names should work
<div class="row main-block">
<div class="span-side-bar">
</div>
<div class="span-content-area">
</div>
</div>
2) And using multiple classes will work, but only if you don't apply any styling to the custom classes that would negate any styles in the native grid classes:
<div class="row main-block">
<div class="span3 side-bar">
</div>
<div class="span9 content-area">
</div>
</div>
3) My recommendation is to live with the little bit of extra markup required to maintain the default Bootstrap grid system. Renaming sounds great now, but if you have any desire to merge in future updates, the one mixin I'd leave alone is the grid.
<div class="row">
<div class="span3">
<div class="side-bar">
</div>
</div>
<div class="span9">
<div class="content-area">
</div>
</div>
</div>

CSS table-like style

I want to create the following table-like element in my page:
I used to do it using <table>...<table> tags , but now I am switching all my sites to CSS and I'm using DIVs and such.
I would like to know what is the "best" way to achieve this kind of an element (is it still the <table> tag?).
I don't want to create just 3 columns and separate Items in the same column with <BR /> since I would like to control the spacing between elements in the same column (such as between Item1 and Item4).
Thanks!!
Joel
use display:table, display:table-row, display:table-cell
#table {display:table;}
.row {display:table-row; }
.cell{display:table-cell;}
<div id="table">
<div class="row">
<div class="cell">Item 1</div>
<div class="cell">Item 2</div>
<div class="cell">Item 3</div>
</div>
<div class="row">
<div class="cell">Item 4</div>
<div class="cell">Item 5</div>
<div class="cell">Item 6</div>
</div>
<div class="row">
<div class="cell">Item 7</div>
<div class="cell">Item 8</div>
<div class="cell">Item 9</div>
</div>
</div>
Live example http://jsbin.com/awagu4
...but I suggest you to use table html tag if you need a table. For this reason exist, and then you can modify it with css. In any case both solutions have the same result.
you can achive the same effect with using unordered list nested in a div element
<div class="wrapper">
<ul class="itemHolder">
<li><div>item1</div></li>
<li><div>item2</div></li>
<li><div>item3</div></li>
<li><div>item4</div></li>
<li><div>item5</div></li>
<li><div>item6</div></li>
<li><div>item7</div></li>
<li><div>item8</div></li>
<li><div>item9</div></li>
</ul>
</div>
this would be your css
.wrapper{
width:600px;
}
.itemHolder{
margin:0;
padding:0;
}
.itemHolder li{
float:left;
margin-bottom:10px;
}
.itemHolder li div{
width:200px;
}
you can see it live here
Using tables for creating your layout is usually frowned upon. Using divs alongside CSS for tabular data is also frowned upon. The best way - as asked by your question - is to use tables on this occasion.
Unless of course the items represented in your image is not tabulated data, but containers/boxes which in turn will hold respective data. In which case I would probably recommend CSS.
You can also achieve this with a flexbox.
.items {
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
This will generate a responsive table like structure.
Flex box is suitable for this.
ul {
display: flex;
flex-flow: row wrap;
}
li {
flex-basis: 40%;
}
<ul>
<li> item 1</li>
<li> item 2</li>
<li> item 3 </li>
<li> item 4 </li>
</ul>
with list style set to none and some use of float you can make a similar result to tables. there's this link: http://mindrulers.blogspot.com/2008/03/create-table-using-css.html and here is it in action: http://www.jsfiddle.net/pJgyu/3247/
I personally prefer using a design-grid, when doing layouts.
At the moment, I would recommend this "framework": http://960.gs/
The name 960 is because its a design that has 960 pixels width, so that it is viewable on most computers which has minimum 1024 pixels in width. 960 is a great number for dividing into columns etc. but have a look at the website for further info.
In addressing which method you should use:
If this is purely a layout issue and the items have no semantic relation issue I would use as your container, row and item elements. In which case use something like Sotiris' answer.
If your items are semantically related then look at who they are related. If they are semantically in groups, i.e. a table use a table, particularly if there would be a title for each column. If it is just generally a group of related items, use a list structure like cac's answer (thoguh it'd probably lose the inner divs).
There are also some interesting variations on the list approach.
By removing the wrapper, or the width from the wrapper in Cac's answer you can create a layout that adjusts it self to different browser width, so for wider screens you'll get less rows of elements as you will get more elements in the row.
Also don't ignore the definition list, if that is a better semantic option to an unordered list.

Resources