I really would like to use twitter-bootstrap, and their scaffolding system with the 12 columns - is there a way to get this working properly with for example ember.js and handlebars.js? I recently ran into trouble, because inserted tags disterb bootstrap.css descriptions like :first-child, my specific situation described below.
So question: Is there a way properly avoid disterbing bootstrap.css when working with for example ember and handlebars, including tags?
My specific trouble: the <div class="span9"> misses out on the CSS below, because the tag picks it up instead, i think...
<!-- Using a handlebars code block helper, {{#if}}, -->
<div class="row-fluid show-grid">
{{#if controller.currentItem.isDuo}}
<div class="span9">{{controller.currentItem.text}}</div>
<div class="span3">{{controller.currentItem.imgText}}</div>
{{/if}}
</div>
<!-- Rendered HTML from code above (stripped script tag's attributes for readability) -->
<div class="row-fluid show-grid">
<script></script>
<div class="span9"><script></script>00<script></script></div>
<div class="span3"><script></script>Mask<script></script></div>
<script></script>
</div>
CSS-code in bootstrap.css, relevant to my situation
.row-fluid [class*="span"]:first-child {
margin-left: 0;
}
If fixed this by adding and extra div right after the diff like this:
<!-- Using a handlebars code block helper, {{#if}}, -->
<div class="row-fluid show-grid">
{{#if controller.currentItem.isDuo}}
<div>
<div class="span9">{{controller.currentItem.text}}</div>
<div class="span3">{{controller.currentItem.imgText}}</div>
</div>
{{/if}}
</div>
Not the most elegant solution, but it works.
Related
Is there a way to tell Tailwind: If a parent has a certain class then show a certain HTML element, if not hide it? Or can this not be done in Tailwind?
<body>
<div class="hidden">Hello</div>
</body>
<body class="show">
<div class="block">Hello</div>
</body>
Yes!
You can use and arbitrary value on the parent, if you conditionally add the class it will show the children like so:
Demo: https://play.tailwindcss.com/0pCtnVrAh7
<!-- hidden -->
<div class="">
<div class="hidden item">Hey!</div>
</div>
<!-- Show if class "[&_.item]:flex" is added-->
<div class="[&_.item]:flex">
<div class="hidden item">Hey!</div>
</div>
<!-- Coming soon -->
<div class="group should-show">
<div class="hidden group-[&.should-show]:block">Hey!</div>
</div>
In a future update, hopefully tailwind will allow us to use the group modifier to style based on if the group has an additional class.
No. Tailwind is a css framework. To use conditional statements, you can either use Tailwind with javascript or php or any other languages.
Actually, there is.This is a css solution, but it can be achieved in tailwind as well:
.hidden {
display:none
}
.parent .hidden {
display:block
}
<div class="hidden">Text that doesn't show up</div>
<div class="parent">
<div class="hidden">
Text is visible
</div>
</div>
html
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 a code block like:
<div class="col-md-12">
<div class="row">
<ng-template dynamicComponents></ng-template>
</div>
</div>
dynamicComponents is a directive using which I inject dynamic components.
All the application is using Bootstrap and is working fine but the dynamically injected components are shrinking or not working with bootstrap css, I even tried using encapsulation: ViewEncapsulation.None but it doesn't seem to work.
Please refer the screenshots below:
Here everything works fine till class=row and it is taing the full width, but once a dynamic component named app-from-builder-components-editor is injected it breaks up the bootstrap properties, please see below:
What can I do to get the bootstrap properties to work ?
The problem is your component host (app-form-builder-components-editor) that sits between your row and col divs. To make it work, your 'col-md-12' div should be a direct child of your 'row' div.
What you could do is putting the <div class="row"> inside your app-form-builder component's template to work around this issue.
I solved this by using containers:
<ng-template>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<!-- content -->
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<!-- content -->
</div>
</div>
</div>
</ng-template>
Not ideal, but it seems to stop the layout issue. Angular templates seem to rewrite the DOM and nest the rows, for some reason. This "resolves" the issue.
I need to update one of my pages that contains portraits and bios -to one that has a hover effect with a drop down field that shows the bio. I found code here that does exactly what I need (How to show text on image when hovering?) and I tested it out on another site to make sure it's working correctly. Problem is, when I put it on my page template, all the header and footer coding (color, font, styles, etc.) are overwritten by the code that I've pasted in. I'm not a coder and only know a little bit of the terminology and how it all works (so please be specific with your responses). I am thinking I need the new code to be in some kind of container that keeps the default page/site styles intact but I'm not sure what to put to do that. I'm also not sure if my new hover code is in the right place. The original code on my template is this:
<!DOCTYPE html>
<html lang="en">
<!-- Head Tag -->
[[$head-tag]]
<style>
.top {
margin-bottom: -75px;
}
</style>
<body>
[[$gtm]]
<!-- Navigation -->
[[$navigation]]
<!-- PAGE CONTENT -->
<section class="top">
<div class="container">
[[$top-page-info]]
<div class="row body-copy">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
[[*content]]
</div>
</div>
</div><!--end row-->
</div><!--end container-->
</section>
<section class="leaders">
<div class="container">
<div class="row">
[[!getPage?
&elementClass=`modSnippet`
&element=`getResources`
&parents=`14`
&depth=`0`
&pageVarKey=`page`
&includeTVs=`1`
&processTVs=`1`
&includeContent=`1`
&showHidden=`1`
&sortby=`{"publishedon":"DESC"}`
&tpl=`LeaderTpl`]]
</div><!--end row-->
</div><!--end container-->
</section>
<!-- PAGE CONTENT END-->
<!-- Footer -->
[[$footer]]
<!-- JS Includes -->
[[$js-includes]]
</body>
</html>
Should I insert the new code in place of the "!getPage?" section (though I'm wondering if deleting some of that is removing code that I need for the default page settings/styles) or should it go below it, just above the line at the end that closes the div and ends the container?
Any help or direction would be greatly appreciated. (And please be specific as I don't really understand all this language.) TIA
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>