How do you grab/affect a specific sibling in CSS or JS - css-selectors

I'm totally new to coding, i'm trying to make a website where when you hover the mouse over a link the the link (a) becomes bigger, but the tricky thing is that i want the hover to affect the sibling right next to the active hover. Right now i'm coding in CSS but maybe i need to use JavaScript instead? Please help :)
Here is what i have written already:
<ul>
<li>Tema 2</li>
<li>Tema 3</li>
<li>Tema 4</li>
<li>Tema 5</li>
<li>Tema 6</li>
</ul>
a {
color: var(--font);
font-size: 100%;
opacity: 0.7;
transition: color 0.5s, font-size 0.5s, opacity 0.5s;
}
a:hover {
color: var(--font);
font-size: 150%;
opacity: 1;
}
a:hover + a {
font-size: 125%;
}
a:not(:hover) {
font-size: 100%;
}
a:hover ~ a {
font-size: 100%;
}
I tried the code shown above, i think that the code is not precise enough, because i'm grabbing all a's, i just seems like a lot of work to give all the a's a class and then write, when sibling no. 1 is active then sibling no. 2 is at 125% font size. And when Sibling no. 3 is active then sibling no. 2 and 4 is at 125%, but right now that is how far my knowlegde reaches...
Hope it makes sense, and sorry for errors, english is not my first language :)

If you apply the sibling styling to the li rather than the a- then you can get the effect you are looking for. This is because the a's are only children within the li's. The li's are the siblings that need to be targetted with teh :hover psedo-styling.
a {
color: blue;
display: block;
font-size: 100%;
opacity: 0.7;
transition: color 0.25s, font-size 0.25s, opacity 0.25s;
}
li {
list-style: none;
padding: 2px 0 ;
}
li:hover a {
color: red;
font-size: 150%;
opacity: 1;
}
li:hover + li a {
font-size: 125%;
}
<ul>
<li>Tema 2</li>
<li>Tema 3</li>
<li>Tema 4</li>
<li>Tema 5</li>
<li>Tema 6</li>
</ul>

Related

When moving a div with ngAnimate, how can I move adjacent divs smoothly?

I have two divs side-by-side (inline block). Using Angular's ngAnimate, I want the left div to slide off the screen and the right div to slide over and take it's place.
Right now what happens is the left div slides away, and once that animation completes, the right div jumps over to take it's spot. How do I make it slide over smoothly at the same time?
Here's a Plunker which demonstrates it a lot better than I can explain it:
https://plnkr.co/edit/ZrtPPkXlttih15ISgEhk
Here's the css/html:
Css:
.well{
overflow-x: hidden;
overflow-y: hidden;
}
.column{
display: inline-block;
width: 100px;
vertical-align: top;
transition: all linear 1.0s;
left: 0px;
position: relative;
opacity: 1;
}
.column.ng-hide{
left: -200px;
opacity: 0;
}
Html:
<div>
<button ng-click="hide = !hide">Toggle</button>
</div>
<div class="well">
<div ng-hide="hide" class="column" style="background-color: lightblue; height: 150px;">
</div>
<div class="column">
This column does not move smothly as the column to the left slides offscreen.
</div>
</div>
Here's that Plunker again, in case you scrolled to the bottom looking for the Plunker link :)
https://plnkr.co/edit/ZrtPPkXlttih15ISgEhk
You simply need to change the width of the column in your transition:
PLUNKR
.well{
overflow-x: hidden;
overflow-y: hidden;
}
.column{
display: inline-block;
width: 100px;
vertical-align: top;
transition: all ease-in-out 1.0s;
left: 0px;
position: relative;
opacity: 1;
}
.column.ng-hide{
width: 0;
left: -200px;
opacity: 0;
}
The reason it wasn't working for you, is due to the fact that the width is remaining the same until the div becomes hidden. This prevents the right column from sliding over as the left column slides out of view. By setting the transition to adjust the width, you can give it that "sliding" effect along the right-edge.
I also changed the animation from linear to ease-in-out to give it a nicer transition

Angular Material mdTabs : is it possible to have vertical tabs?

I am looking for Tabs displayed top to bottom with tab navigation on the left. Is there anyway this can be achieved in Angular Material library?
This codepen by Rahul Sagore uses vanilla Material, not specifically for Angular, but it's exactly what you want. I was looking for the same thing as you; it's a shame Material doesn't offer this, but I can see how it would go against their principles and make Material too extensive.
It comprises of custom css (perhaps overriding, I'm not sure) and use of particular Material classnames. Below I've pasted the contents into a snippet.
I had an issue with the mdl-cell--n-col classes so I changed the content one from 10-col to 6-col so it wouldn't wrap the content beneath the tabs in the restrictive space of this post. You'll probably have to tinker with that yourself, or scrap that and use Material styles the way you know how. Similarly, I cannot see what the .hollow-circle spans are doing, so perhaps they aren't needed.
/*Vertical Tabs*/
.vertical-mdl-tabs {
margin-top: 30px;
}
.vertical-mdl-tabs .mdl-tabs__tab-bar {
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
padding-bottom: 35px;
height: inherit;
border-bottom: none;
border-right: 1px solid rgba(10, 11, 49, 0.20);
}
.vertical-mdl-tabs .mdl-tabs__tab {
width: 100%;
height: 35px;
line-height: 35px;
box-sizing: border-box;
letter-spacing: 2px;
}
.vertical-mdl-tabs.mdl-tabs.is-upgraded a.mdl-tabs__tab.is-active {
border-right: 2px solid #ED462F;
}
.vertical-mdl-tabs.mdl-tabs.is-upgraded .mdl-tabs__tab.is-active:after {
content: inherit;
height: 0;
}
.vertical-mdl-tabs.mdl-tabs.is-upgraded .mdl-tabs__panel.is-active, .mdl-tabs__panel {
padding: 0 30px;
}
.vertical-mdl-tabs.mdl-tabs .mdl-tabs__tab {
text-align: left;
}
<script src="https://storage.googleapis.com/code.getmdl.io/1.1.0/material.min.js"></script>
<link href="https://storage.googleapis.com/code.getmdl.io/1.1.0/material.indigo-pink.min.css" rel="stylesheet"/>
<div class="mdl-tabs vertical-mdl-tabs mdl-js-tabs mdl-js-ripple-effect">
<div class="mdl-grid mdl-grid--no-spacing">
<div class="mdl-cell mdl-cell--2-col">
<div class="mdl-tabs__tab-bar">
<a href="#tab1-panel" class="mdl-tabs__tab is-active">
<span class="hollow-circle"></span>
Tab 1
</a>
<a href="#tab2-panel" class="mdl-tabs__tab">
<span class="hollow-circle"></span>
Tab 2
</a>
<a href="#tab3-panel" class="mdl-tabs__tab">
<span class="hollow-circle"></span>
Tab 3
</a>
</div>
</div>
<div class="mdl-cell mdl-cell--6-col">
<div class="mdl-tabs__panel is-active" id="tab1-panel">
Content 1
</div>
<div class="mdl-tabs__panel" id="tab2-panel">
Content 2
</div>
<div class="mdl-tabs__panel" id="tab3-panel">
Content 3
</div>
</div>
</div>
</div>
you can have verticval tabs by adding vertical attribute to the mat-tab-group and adding following css to your page.
mat-tab-group[vertical] .mat-tab-labels {
display: flex;
flex-direction: column!important;
}
mat-tab-group[vertical] {
display: flex;
flex-direction: row!important;
}
here's the mat-tab-group element with vertical attribute
<mat-tab-group flex="1" vertical>
<mat-tab label="Tab 1"> Loading ... </mat-tab>
<mat-tab label="Tab 2" > Loading ... </mat-tab>
</mat-tab-group>

List items not correctly aligning with an ng-repeat

I have a simple ng-repeat <li>. Each <li> consumes 33.33% of the width so 3 items per row.
However, for some reason the items in the second row do not line up. After a big of digging, if i apply a min-width of say, 400px, then it works. But, i can not do this as the description text length is dynamic.
HTML:
<ul class="grid-wrap">
<li class="grid-col one-third" ng-repeat="job in Jobs" ng-init="descriptionLimit = 20">
<div>{{ job.JobTitle }}</div>
<div>{{ job.Location }}</div>
<div>{{ job.JobDescription | limitTo:descriptionLimit }}
<span ng-click="descriptionLimit = job.JobDescription.length"> >> </span></div>
</li>
</ul>
CSS:
ul, ol {
list-style: none;
padding: 0;
margin: 0;
}
.grid-wrap {
margin-left: -3em; /* the same as your gutter */
overflow: hidden;
clear: both;
}
.grid-col {
float: left;
padding-left: 3em; /* this is your gutter between columns */
width: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.one-third {
width: 33.33%;
}
plunker: http://plnkr.co/edit/oWXrqoJpaYPDbe4TwT3c?p=preview
If you click on the >> the description will expand and you can see each <li> does not line up:
Might something like this be what you are looking for?
.one-third:nth-of-type(3n+1) {
clear: both;
}
I.e. if you want to have exactly a maximum of 3 lis per row, and you want to always align your rows vertically, you'll need to explicitly do so.
Edit: And of course you could do this also with Angular, for example like this, first define a clearing class:
.clear-li {
clear:both
}
and then apply it with ng-class:
<li class="grid-col one-third" ng-repeat="job in Jobs" ng-init="descriptionLimit = 20" ng-class="{'clear-li': ($index % 3 === 0)}">

Aligning divs horizontally using CSS display:

I am trying to align two divs horizontally. My list in the 2nd div is horizontally aligned, but the two divs fail to align horizontally as inline-blocks. Any help would be greatly appreciated.
Here is the CSS and HTML code:
CSS
#wrapper {
margin:0 auto;
width:100%;
position:relative;
}
.navit {
position:relative;
margin-left: auto;
margin-right: auto;
width: 100%;
height: 100%;
display:inline;
}
.container-logo {
display:inline-block;
}
.container-user {
display:inline-block;
}
#user-nav-container ul li {
display:inline;
}
#user-nav-container ul li a {
background-color:#000000;
color:#FFF;
font-size:14px;
}
#user-nav-container ul {
list-style-type:none;
background-color:#000000;
}
HTML
<html>
<body>
<div id="wrapper">
<header id="top">
<div id="navbar" class="navit">
<div id="logo-container" class="container-logo"><a href="http://www.site.com/" id="logo">
<h1>ServiceMyResume.com</h1>
</a></div>
<div id="user-nav-container" class="container-user">
<ul>
<li>Site 1</li>
<li>Site 2</li>
</ul>
</div>
</div>
</header>
</div>
</body>
</html>
Fiddle: http://jsfiddle.net/8TfzJ/
Get rid of:
#user-nav-container ul li {
display:inline;
}
This is what is causing your nav elements to be horizontal instead of vertical.
http://jsfiddle.net/8TfzJ/1/
Update
To vertiacaly align the two elements add vertial-align top to them, see: http://jsfiddle.net/8TfzJ/2/.
Note in the fiddle I've added a border so you can see the elements are vertially aligned. You may need to adjust margins and padding of the contained elements to fully achieve what you are looking for. Use Firebug for Firefox to help you here. You can inpect an experiment with the CSS in the borwser.
In a modern browser you should see:
See this article for some inf on the drawbacks of inline-block and how to over come them:http://robertnyman.com/2010/02/24/css-display-inline-block-why-it-rocks-and-why-it-sucks/
On a side note, you shouldn't put block elements e.g. h1 inside inline elements e.g. a. It should be the other way around. Try validating it here: http://validator.w3.org/#validate_by_input+with_options
I know it is not as inline-blocks, but you you mean something like this JSFiddle?
#navbar:after
{
display: table;
content: "";
clear: both;
}
#logo-container,
#user-nav-container
{
float: left;
}

IE7 (IE8 Compatability Mode) bug: crazy amound of width applied to a floated element that is parent to another float

Here's my problem. It looks perfect in Firefox, Safari, IE8, but in IE7 and IE8 comparability mode, it adds about 4000px of width to the div.team elements nested within the list item. the problem goes away if i remove the span.score elements.
The image attached shows the score in the first box in white number text. The top image is the way it's supposed to look. The bottom is IE7.
I've been trying to figure this out for hours. I even tried making the list a bunch of divs in case it was a weird IE7 list item bug, but I got the exact same results.
Here's my html:
<ul class="selected" data-league="ncaaf">
<li>
<div class="time">THU 12:30PM</div>
<div class="teams">
<div class="team">AUB (21) <span class="score">10</span></div>
<div class="team">MSST <span class="score">22</span></div>
</div>
</li>
...
Here's my CSS:
.boxList ul {
float:left;
margin:0 0 0 0;
heigth:40px;
width:5000px;
clear:left;
display:none;
}
.boxList ul.selected {
display:block;
}
.boxList li {
float:left;
height:40px;
padding:0 5px;
min-width:56px;
background:url(../images/scoreSchedBoxTile.png) repeat-x;
border:1px solid #000;
list-style-type:none;
margin:0;
font-size:9px;
line-height:13px;
font-weight:bold;
cursor:pointer;
position:relative;
}
.boxList li .time {
text-align:center;
}
.boxList li .teams {
}
.boxList li .team {
text-align:left;
color:#000;
clear:left;
line-height:13px;
height:13px;
}
.boxList li .score {
font-weight:bold;
text-align:right;
color:#fff;
float:right;
display:block;
}
try using:
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
The width on your divs is set to 100%, so the div is stretching to 100% width and filling all available horizontal space. You can fix this by applying a fixed width to your divs.

Resources