Angular Div layout container border collapse - html

I am generating a table using angular material's div layout containers. My question is simple, how do I collapse the div's borders? Please check out my jsfiddle of what I have done
Jsfiddle
HTML code below. Appreciate any guidance thanks.
<div ng-app="myApp" ng-controller="mainCtrl">
<script type="text/ng-template" id="/template">
<button ng-click="testFn()">Test</button>
<div layout="row">
<div flex ng-repeat="col in column"><span>HEADER{{$index}}</span>
<div layout="column">
<div flex style="border: 1px solid black;" ng-repeat="row in [1,2,3]">{{$index}}</div>
</div>
</div>
</div>
</script>
<form-table table-layout=tableLayout|filter:{table_id:1}></form-table>
</div>
My code as follows:

Here is a modified version of your jsFiddle:
http://jsfiddle.net/ccf0sphf/13/
The result is obtained not using border-collapse which requires displaying <DIV>s as a table but instead with a mix of CSS combinators (> child selector) and ng-class:
div.col {
border-top: solid 1px black;
}
div.col > div.box {
border-bottom: solid 1px black;
border-right: solid 1px black;
}
the class below is used in an ng-class to apply only to the first column:
div.col-first {
border-left: solid 1px black;
}
This trick is necessary because there is a <SPAN> element as first element in the column, otherwise we could use a first-child pseudo-element to obtain the same result.

Related

CSS attribute selector begin with

[class*="grid-"]{
border: 2px solid green;
}
[class^="grid-"]{
border: 2px solid red;
}
<div class="row">
<div class="grid-sm-1-3">one</div>
<div class="grid-sm-1-3">two</div>
<div class="other class grid-sm-1-3">three</div>
</div>
<div class="layout-grid-edit">do not match at all</div>
The issue is, if the element has multiple classes then the class^="grid-=" doesn't seem to work, and I can't rely on class*="grid-" because it also matches something like layout-grid-edit which is not desired.
#3zzy - Give this attribute selector a try below. This type of selector will be effective in targeting a class attribute beginning with the whole word grid, immediately followed by a hyphen:
[class|="grid"] { border: 2px solid green; }
See if this does the trick, and let me know.
Replaced:
[class*="grid-"]{
}
With:
[class^="grid-"],
[class*=" grid-"]{
}

HTML class with default code

I'm doing some formatting on a webpage and I'm wondering if it's possible to save a chunk of html code as a class and reuse it.
For example:
I want to change this -
<div>
<hr>
<p>Item 1</p>
<a href="oh.jpg" />
<hr>
</div>
<div>
<hr>
<p>Apple</p>
<hr>
</div>
To this -
<div class="section">
<p>Item 1</p>
<a href="oh.jpg" />
</div>
<div class="section">
<p>Apple</p>
</div>
With the same end result of being contained within two horizontal rules.
Is there a way of making a class that isn't just for styling but contains HTML code as well?
The closest thing to what you're describing is the CSS pseudo-elements :before and :after. You can't insert HTML, but you can insert text or images, or a simple rectangle with content:"";display:block;. With some creativity you can pull off a lot of effects with just CSS.
So while you can't insert an actual <hr> with CSS, you can psuedo-elements to draw one with whatever styles you please:
.section:before {
content: "";
display: block;
height: 2px;
border: 1px inset #000;
border-width:1px 1px 0 0;
}
.section:after {
content: "";
display: block;
height: 2px;
border: 1px inset #000;
border-width:1px 1px 0 0;
}
If you absolutely need to add HTML, you can use Javascript to find all elements with class .section and append child elements.
you can use CSS
.section{
width : 100%;
border-bottom: 2px solid #ccc;
margin-top : 5px;
}

how to select last div if i give the last element display none?

Please check the fiddle: http://jsfiddle.net/C23g6/1255/
I want the last child (7777) border top to be display none.
I tried but i couldn't get please give me solution.
Only through css
CSS
.common.true{
display: block;
border-top: 1px solid red;
}
.common{
display: none;
}
.true:last-child{
border-top: none;
}
I dont want the last child border not to be displayed. But not using nth child. some other way
First thing, If you do display: none of last element then how can you use css on that element(hidden element).
If you want to get Id or class (attribute) to perform action on that, you should choose js or jquery.
Second thing, the last-child would be 8888, but you want to do with second last-child, then use this, it may work :
.common:nth-last-child(2){
border-top:none !important;
}`enter code here`
You have a basic mistake in the HTML.Your last child in HTML is 8888 and you want to hide border-top of 7777.Use the following:
<div id="my-section">
<div class="common true">1111</div>
<div class="common">2222</div>
<div class="common true">3333</div>
<div class="common true">4444</div>
<div class="common true">5555</div>
<div class="common true">6666</div>
<div class="common true">7777</div>
<div class="common">8888</div>
</div>
.common.true{
display: block;
border-top: 1px solid red;
}
.common{
display: none;
}
.true:last-child{
border-top: none;
}
#my-section .common:nth-last-child(2){
border-top:none !important;
}
I have added a new css selector,which hide the border of 2nd last child.

nth-of-type acting like nth-child

I have this html code:
<div class="productWarp">
<div class="clear"></div>
<div class="productLine" ></div>
<div class="clear"></div>
<div class="productLine" ></div>
</div>
css:
.productWarp .productLine {
background-color: #DFDDDD;
border-bottom: 1px solid #B7B7B7;
padding-right: 5px;
}
.productWarp .productLine:nth-of-type(2)
{
background-color: white;
border-bottom: 1px solid #B7B7B7;
padding-right: 5px;
}
This choosing the second child of productWarp(first productLine) and not the second productLine,so it acting Exactly as nth-child selector
<div class="productWarp">
<div class="clear"></div>
<div class="productLine" ></div>//this one is choose
<div class="clear"></div>
<div class="productLine" ></div>//this one should be choose
</div>
any idea what wrong here?
:nth-of-type() looks at an element's type, not its class. In this case, all your elements are of the type div, which is why :nth-of-type() works exactly the same as :nth-child().
If you have only two .productLine elements, use the following selector to style your second one instead:
.productWarp .productLine ~ .productLine
{
background-color: white;
border-bottom: 1px solid #B7B7B7;
padding-right: 5px;
}
Otherwise you'll just have to go by :nth-child() indices, in this case :nth-child(4), or override styles for subsequent .productLine elements by adding more rules repeating the ~ .productLine part as necessary.
This take in consideration the clearing div.
.productWarp div.productLine:nth-of-type(4n)

Is it possible to specify sub-sub classes within a <style>?

Example:
<style> div.Style1 div img { border: 3px red solid } </style>
...
<div class="Style1" id="divMain">
<img src="http://someurl.com/someimg.jpg" /> <!--WON'T be styled-->
<div id="divSub">
<img src="http://someurl.com/someimg.jpg" /> <!--WILL be styled-->
</div> <!--End of divSub-->
</div> <!--End of divMain-->
Yes. This CSS:
div.Style1 div img {
border: 3px red solid;
}
says: apply border: 3px red solid; to all img elements within a div element, which are in turn in in another div that has Style1 as a class.
Here's a jsfiddle to demonstrate:
http://jsfiddle.net/WZ3rk/
Try this, it selects only images that are children of a div that are themselves children of the element with class Style1.
.Style1 > div > img {
border: 3px red solid
}
Yes, it is possible - try it out. Although I would use
div.Style1 div.divSub img { ... }