Within a polymer element I am trying to build a simple multi-column layout with lost-grid to render a list of items using dom-repeat. It looks like this:
HTML
<div class="grid">
<template is="dom-repeat" items="{{data}}">
<div class="grid__col">Example Content</div>
</template>
</div>
CSS
.grid {
lost-utility: clearfix;
lost-center: 100%;
position: relative;
}
.grid__col {
lost-column: 1/2 2 0px;
}
For example if the data array assigned to dom-repeat has 4 items, the following HTML is rendered:
<div class="grid">
<div class="grid__col">Example Content</div>
<div class="grid__col">Example Content</div>
<div class="grid__col">Example Content</div>
<div class="grid__col">Example Content</div>
</div>
Instead of displaying the columns at 50% width, the layout breaks and they are stacked on top of each other. If I remove the dom-repeat and list the 4 columns manually, it works. In both cases the code is the same in the end, so I'm guessing the rendering of the template somehow messes with the total width the columns can take up.
Another thing to note is that when using the exact same code inside a dom-bind template directly in the body of the page (outside of a polymer element but using dom-repeat), it works.
I just quickly read about lost. If you must use it I can't give you a specific answer, but if you only have a couple of divs that you are aligning, Polymers layout manager seems sufficient.
In a similar situation I was using the wrap layout and the calc() CSS operator (which seems to be in use behind the scenes with lost anyway).
<div class='horizontal layout wrap'>
Lots of divs here with template repeat
</div>
This is a rudimentary example and would need to be customized of course.
Hope this helps.
I suspect this may be due to shadow DOM. Are you using shadow DOM or are you using shady DOM? If you are using shadow DOM, you will need to add the CSS inside of your element's dom-module in order for it to take effect.
In other words, you should have something like this:
<dom-module id="an-element-with-grid">
<link rel="import" type="css" href="an-element-with-grid.css"> <!-- This will be the home of your lost CSS -->
<template>
<div class="grid">
<template is="dom-repeat" items="{{data}}">
<div class="grid__col">Example Content</div>
</template>
</div>
</template>
</dom-module>
This is per the shadow DOM spec. Nodes inside an element's shadow DOM are hidden from outside scopes, to prevent outside styles from stepping on your element's internal styles.
Related
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.
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.
I'm currently working with a third party JS library that inserts content areas within the page/DOM, the library is Sir Trevor.
Now I wish to apply some custom CSS rules, for example:
.st-block:before {
#include roundedIcon(38px, $colorX, $colorY);
content: counter(mylistCounter, decimal);
counter-increment: mylistCounter;
margin-right: $margin-variable;
}
now this works great and a number is put before my divs with the .st-block class. However a DIV with this class can and some times does contain a child div with the same class, like so:
<div class="content">
<div id="st-block-16" class="st-block st-icon--add st-item-ready" data-type="listicle" data-instance="st-editor-8">
<!-- here's the child... grrr!!! -->
<div id="st-block-17" class="st-block st-icon--add st-item-ready" data-type="listicle" data-instance="st-editor-8">
Child Div Here...
</div>
</div>
<div id="st-block-18" class="st-block st-icon--add st-item-ready" data-type="listicle" data-instance="st-editor-8">
No Child Div
</div>
<div id="st-block-19" class="st-block st-icon--add st-item-ready" data-type="listicle" data-instance="st-editor-8">
No Child Div
</div>
</div>
How can I amend my CSS/SASS class to prevent the child/nested div with the same class being affected (in the example above the one with ID id="st-block-17")? PLEASE NOTE that I have no control over the alocation of IDs
Select only the classes which are only one level deeper then the div with class="content"
.content > .st-block
I am wondering how to override styles of shell view being injected in Durandal inside div with id="applicationHost" ... I am trying to use common Bootstrap template (sticky footer with fixed navbar) and it works as standalone but as soon as I use it within shell.html the "wrapper" looses its auto height...
Here is my shell.html
<div>
<div id="wrapper">
<!-- ko compose: {view: 'nav'} -->
<!-- /ko-->
<div id="content" class="container-fluid">
<!--ko compose: {
model: router.activeItem, //wiring the router
afterCompose: router.afterCompose, //wiring the router
transition:'entrance', //use the 'entrance' transition when switching views
cacheViews:true //telling composition to keep views in the dom, and reuse them (only a good idea with singleton view models)
}--><!--/ko-->
</div>
<div id="push"></div>
</div>
<footer id="footer">
<div class="container-fluid">
<div class="row-fluid">
<div class="span6"><p class="muted">© ABC Company Inc. 2013. All rights reserved.</p></div>
<div class="span6 "><p class="muted pull-right">v0.0.1-debug</p></div>
</div>
</div>
</footer>
</div>
the nav sub-view just has standard <nav id="mainnav" class="navbar navbar-fixed-top"> and the styles are the same as on Bootstrap example page...
When I examine styles via Firebug I can clearly see that wrapper div has lost its full height...Driving me nuts! :)
I fixed this by adding the following style to my main html page after the styles necessary to get the sticky footer to work
/*durandal fixes*/
#applicationHost, #applicationHost > div
{
height: 100%;
}
The first selector takes care of the applicationHost div in the main html page and the second the one inserted by durandal (it has a class of durandal-wrapper, so you could make the selector more specific if you wanted). As you have an extra div in your shell.html file you may need the following:
/*durandal fixes*/
#applicationHost, #applicationHost > div, #applicationHost > div > div
{
height: 100%;
}
For example, I would like to select the two divs with data-role of content that are not children of a data-role="page" div with class "modal". I am not well versed in advanced CSS selectors.
<div>
<div data-role="page">
<div data-role="content"></div>
</div>
<div data-role="page" class="modal">
<div data-role="content"></div>
</div>
<div data-role="page">
<div data-role="content"></div>
</div>
</div>
I've tried a few things but I can't get anything to work... e.g.
[data-role="content"]:not([data-role="page"].modal > :after)
or
[data-role="content"]:not([data-role="page"].modal > [data-role="content"])
[data-role="page"]:not(.modal) > [data-role="content"]
This gets all the elements whose data-role is page and who does not has the class modal, then get all their immediate children whose data-role is content.
Live demo here.
Well, you could do it with:
:not([data-role=page])>[data-role=content] {...}
But for better compatbility you might want to see if you can do:
[data-role=content] {/* define some styles */}
[data-role=page]>[data-role=content] {/* cancel out the previously-defined styles */}