Increment a counter based on number of elements - angularjs

I have a below snippet for showing TABS which is static HTML. But each item would get shown on UI based on some business logic. Based on the number of tabs I need to set a width. For e.g if two tabs are shown then I need to equally divide tabs i.e 50%. when three, it will be 33.3%.
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
Using 'ng-class' I can add runtime classes to apply the width but its increasing the complexity and killing the page as I need to apply the same business logic in ng-class.
Rather, I was trying to use ng-init to get the count to check how many tabs are formed.
<ul ng-init="totalTabs=0">
<li ng-init="totalTabs=totalTabs+1">1</li>
<li ng-init="totalTabs=totalTabs+1">2</li>
<li ng-init="totalTabs=totalTabs+1">3</li>
<li ng-init="totalTabs=totalTabs+1">4</li>
</ul>
This doesn't give me the expected count. Do you have any clue or suggestions ?

It's time to use some new features of CSS3. In case you don't know it, there's a new display called flex. It allows a lot of things, and one of them is to give elements the same width, based on their parent's width.
You can find a quick tutorial here, or if you want to be fast :
ul {
display: flex;
flex-flow: row wrap;
justify-content: center;
align-items: center;
align-content: flex-start;
li {
flex: 1 1 auto;
}
}

Related

Stop text from breaking next line

I am using React, styled-components, and media queries at the moment. I have 3 media queries at; 480px, 768px, 1200px - my text when scaling between these on a desktop does not hold the same structure.
I have an idea to use two styled components one for the first line of the title and one for the second and then make sure that each one has white-space: nowrap;. But, I am not sure that this is the best solution... Any suggestions?
Here is a visual example of what I am working with:
Here is the line breaking:
You can use the "non-breaking-space" HTML entity instead of the regular spaces at the positions that should not break / should form a unit or line
h1 {
width: 400px;
margin: 0 auto;
text-align: center;
font-size: 60px;
font-family: sans-serif;
}
<h1>The fastest way to finance NFTs</h1>
Your solution is good, however you can use two span elements within the h1 and give them a display:block; and white-space: nowrap;
<h1>
<span className="block whitespace-nowrap">The fastest way</span>
<span className="block whitespace-nowrap">to finance NFTs</span>
</h1>

Need first-of-type to work on first paragraph, but not on nested first paragraphs

I have successfully put a large first letter on the first paragraph on blog posts. But if there are other first paragraphs in the post (examples: the first paragraph of a blockquote, the first paragraph in an embedded podcast player) they are also displaying the large first letter.
I have tried some examples from this post but I'm not sure if this article is covering my situation or not. I'm new to the idea of adjacent sibling selectors. I'll share the code I tried to implement by (assumedly) telling any other p:first-of-type::first-letter incidents after my first incident to not have the styling...
.single .post .entry-content p:first-of-type::first-letter {
float: left;
width: 0.75em;
font-size: 600%;
font-family: alice, serif;
line-height: 78%;
}
.single .post .entry-content p:first-of-type::first-letter ~ p {
float: none;
width: 0;
font-size: 100%;
font-family: lora, serif;
line-height: 0%;
}
The large letters remain in block quotes and the embedded podcast player. How would I explain that first letters of first paragraphs inside of divs which are nested inside the .entry-content area should not have the first letter styling?
If your targeted paragraph is a direct child of .entry-content then you can use the direct children selector > :
.single .post .entry-content > p:first-of-type::first-letter {}
By using the direct children selector you don't select descendant elements that are nested deeper than direct children. And by adding :first-of-type or nth-of-type(n), you select only your paragraph within those childrens.

mwl calendar mark hour in different color

I use the mwl calendar and I will mark the hour from 12 - 13 in another color inday view.
Is there a simple possibility to do this?
[EDIT]
Now I have tried this one
<style type="text/css">
.cal-day-hour-part:nth-of-type(2n) {
background-color: #f00 !important;
}
</style>
with this plunker example:
Plunker example
and this works fine, than I have tried it with .cal-day-hour-part:nth-of-type(3n) and this does not work. Does anyone know why?
The DOM is structured like this:
<div class="cal-day-hour">
<div class="cal-day-hour-part">
<div class="cal-day-hour-part">
</div>
<div class="cal-day-hour">
<div class="cal-day-hour-part">
<div class="cal-day-hour-part">
</div>
...
The :nth-of-type(n) selector matches every element that is the nth child, of a particular type, of its parent. There are at most 2 .cal-day-hour-part children of .cal-day-hour in your DOM. That's why 2n works but 3n does not.
Regarding your original question (and thanks for the edits to clarify), you'll want to use :nth-of-type(n) on .cal-day-hour instead, and stop using the counter n as you don't need it.
.cal-day-hour:nth-of-type(7) {
background-color: #f00 !important;
}
Here's an updated plunkr

Creating an animated 1-3 column layout using Angular

Here's the situation:
I'm building a page for an application which consists of a navbar, a footer and a 3 column body.
Initially, only one column should be shown. This first column will be filled with clickable divs (let's call them cards). When one of these cards is clicked, the second column should slide open from the side, revealing more information about the clicked card.
The same workflow applies to the second column: the details displayed in the second column contains its own cards, which - when clicked - open up the third column with more details about the card in the second column.
The second and third column can also be closed, while the first can not.
I'm loading the column information using Angular, and so far I've had no real struggle implementing the 1-3 column layout.
But when I try to make this work smooth - e.g. using animations - things get weird. I don't really know how I can animate the (dis)appearance of one of each columns.
Here's what I have so far: Codepen example
<div class="container" ng-controller="Controller as ctrl">
<div class="column" ng-repeat="column in ctrl.columns" ng-class="[column.mode, column.color]" ng-show="column.open">
<button ng-click="ctrl.close(this)" ng-show="column.id != 0">Close</button>
<p ng-click="ctrl.open(this)">Name: {{column.name}}</p>
<p>Open: {{column.open}}</p>
<p>Mode: {{column.mode}}</p>
<p>Color: {{column.color}}</p>
</div>
</div>
CSS:
.container {
height: calc(100% - 50px);
display: flex;
}
.column {
padding: 10px 0 0 10px;
overflow-y: auto;
}
.column-narrow {
flex: 33;
}
.column-wide {
flex: 66;
}
.column-full {
flex: 100;
}
The second and third column can be triggered by clicking the name paragraph.
Don't worry about the colors, they're definitely not final and are used only for a clear visual difference between containers etc.
Can any one of you offer me a CSS(3) solution to this? If my code can be optimised please do, as I'm currently learning Angular.
There is not a lot of code needed to get some basic animations working.
The ng-show and ng-hide directives already provide support for animations out of the box. That means that AngularJS will add animation hooks in the form of additional classes ng-hide-add, ng-hide-add-active, ng-hide-remove, ng-hide-remove-active.
So these classes get added to your CSS column.
I literally only had to add these CSS lines to make animations work in your Codepen.
.column.ng-hide-add.ng-hide-add-active,
.column.ng-hide-remove.ng-hide-remove-active {
-webkit-transition: all linear 0.5s;
transition: all linear 0.5s;
}
Here is the updated codepen:
http://codepen.io/anon/pen/XbVLxO

inline-block elements not showing in IE7

So, this is an odd one...
I've got basic pagination code:
<div class="pagination">
< 1 <a class="current">2</a> 3 >
</div>
And I want it all centred, so I'm using inline-block on the anchor tags. Simple enough, stripped down CSS code:
.pagination{text-align:center; margin-bottom:20px;}
.pagination > a{display:inline-block; vertical-align:middle; margin:0 2px 0 1px;}
.ie7 .pagination > a{zoom:1;}
.pagination .next,
.pagination .prev{width:26px; height:38px; text-indent:-9999px; overflow:hidden;
background:url(../images/page-arrows.png) no-repeat;}
.pagination a{width:37px; height:31px; line-height:32px; font-size:15px; font-weight:bold; color:#7e7e7e;
background:url(../images/page-numbers.png) left top no-repeat;}
Problem is that, NOTHING is displaying in IE7 (at least IE7-mode of IE9). I'm well aware of the display-inline bugs that IE7 has, but those only apply to elements that aren't inline by default. I've added in a zoom:1 anyway though for good measure.
If I put a background colour on the .pagination wrapper, that wrapper does indeed show up with the background colour, but the elements inside just aren't showing!
I've tried the usual IE 'fixes' ...position:relative, zoom:1, height:1% on any and every element, but not luck.
What am I missing?!
After some experimenting in JSFiddle I've managed to discover that the problem relates to this particular rule
.pagination .prev {text-indent:-9999px; }
Disabling this fixes the issue but is not ideal as you would then have the text charecter appear on top of your background images.
Interestingly enough your .next does not cause the same issue. with that in mind added an to either side of your paging control (so your center alignment dosnt get skewed) and it seems to of fixed the problem.
<div class="pagination">
< 1 <a class="current">2</a> 3 >
</div>
JSFiddle available here (background images replaced with solid colors for obvious reasons)

Resources