CSS select only elements that dont have a class starting with this - css-selectors

Hi,
I have this html code:
<ul>
<li>
Locations
<ul class="submenu1">
<li>London</li>
<li>York</li>
</ul>
</li>
<li>
About
<ul class="submenu2">
<li>Site</li>
<li>Contact</li>
</ul>
</li>
</ul>
I want to select all the a elements EXCEPT the ones that are children to the submenu class elements.
I tried like this:
ul li a:not([class^="submenu"] a) {background-color:darkkhaki;}
but it wont work. Whats the right selector for this case?
Thank you.

Hello dear CSS friend!
In other words, taking your example, you want to select "Locations" and "About" links but not the others.
(Kind of) dirty one
The easier to understand solution is to apply styles to all a then remove the styles to the others.
li > a {
/* Styles you want to apply */
}
[class^="submenu"] a {
/* Remove styles here */
}
It's always dirty to place styles then remove them, because it's less maintainable and a bit more heavy. But it will do the job.
Nicer solution
In your case, the submenu links are the only child of your li elements. That's why I would try to target the links that are not only child of your list item to style those, like that.
li a:not(:only-child) {
/* Your styles here */
}
For more information on :only-child pseudo class, I leave you with some reading :)
https://developer.mozilla.org/fr/docs/Web/CSS/:only-child
Don't hesitate if you have question, and have fun!

Option 1:
This will work:
ul li a {
background-color: darkkhaki;
}
ul ul li a {
background-color: transparent;
}
Just reset the styles on the elements you don't want styled.
Option 2:
If you have a container, for example a <div id="menu"> you can do:
#menu > ul > li > a {
background-color: darkkhaki;
}

Related

quill.js: how to style a list

I know that UL and OL (even v2.0.0 TABLE) has no existence in the scroll however I wondering if there is a way (or a trick) to style these elements (UL or OL, not the LI) through class or style attributor, eg.
<ul class="..."`
<li ...
<li ...

Can we use :not selector on hidden element?

I created list with some elements as display:block and rest with display:none.
Tried to apply search on whole list but it resulted the set from visible list instead of complete list.
So how can I search in whole list in below eg.?
<ul>
<li class="searchable show" data-index="ajay">ajay</li>
<li class="searchable show" data-index="amit">amit</li>
<li class="searchable hide" data-index="ashish">ashish</li>
<li class="searchable hide" data-index="ali">ali</li>
<li class="searchable show" data-index="xyz">xyz</li>
</ul>
When I apply style by:
.searchable:not([data-index*=\"" + val + "\"]) {
display: none;
}
// where val=a; since I am searching by a
It resulted in:
ajay
amit
Instead expected result was:
ajay
amit
ashish
ali
Your .hide rules will still hide the elements that match the criteria of your :not([...]) selector.
Assuming your .show and .hide rules look this ...
.searchable.show {
display: block;
}
.searchable.hide {
display: none;
}
... in cojunction with your rule ...
.searchable:not([data-index*="a"]) {
display: none;
}
... you still need a rule like this to make hidden items, that meet the criteria, visible:
.hide[data-index*="a"] {
display: block;
}
Working fiddle: http://jsfiddle.net/x5py4c5j/

How to override Foundation's display:inherit property for visibility classes?

I'm using Foundation in a mobile first project where many elements are hidden based on the browser size, and I'm running into some trouble using Foundation's visibility classes like .show-for-small-only as Foundation applies
display: inherit !important;
to any element which uses these visibility classes. (For example, see line 5808)...
.show-for-small-only {
display:inherit !important;
}
This is causing me issues. Say have an element that I want to .show-for-small-only:
<div class="someElem show-for-small-only">
<!-- Content -->
</div>
Yet I want this element, when shown, to be formatted as a display:inline-block element. Due to Foundation's use of !important, the div is forced to assume it's default display state of block.
Is there any workaround to this, short of declaring my styling as !important too? (I don't want to have to do that though)...
I agree, using !important always feels gross.
Precedence in CSS is given to the element furthest down the tree so to override the Foundation !important property, just target an element further down the tree, like so:
<div class="show-for-small-only">
<div class="someElm">
<!-- your content here -->
</div>
</div>
With the following CSS
.someElm {
display: inline-block;
}
Here's a Plunker for kicks (just remember the items wont show up unless the screen is small).
I hope this helps.
To overwrite inportant just declare it again after the first declaration
.show-for-small-only {
display:inherit !important;
}
.show-for-small-only {
display: inline-block!important;
}
<div class="someElem show-for-small-only">
Content
</div>

ui bootstrap tooltip cutoff in iframe

I have an app running in an iframe and it makes use of angular ui boostrap tooltips. Unfortunately if the element with the tooltip is on the edge of the iframe, the tooltip will be cutoff by the iframe. Is there any solution to this? Should I play with its position within the iframe, or the z-index value?
UPDATE
So I'm trying to override the tooltip positions (note that I an using angularjs ui bootstrap). I have 2 tooltips which each require their own positioning. I managed to change the css styles (colours and fonts) globally, but I'm having trouble targeting each one to give them unique positions. I have the following html and css:
<div id="my-div">
<ul>
<li tooltip="Foo">A</li>
<li tooltip="Bar">B</li>
</ul>
</div>
Tooltip "Foo" needs a different position that "Bar". So I'm trying to access the li tags using the following css, but it doesn't work.
#my-div > ul > li:nth-child(1).tooltip.top {
margin-left: 10px;
}
#my-div > ul > li:nth-child(2).tooltip.top {
margin-left: 30px;
}
Note that .tooltip.top is the bootstrap class added via the angularjs tooltip directive. I'm guessing this doesn't work because the directive is actually adding another element somewhere.
So it turns out angular will insert a div element right after the element defined as the tooltip. So in my case, when the tooltip event for A is triggered, angular inserts the new element like so:
<div id="my-div">
<ul>
<li tooltip="Foo">A</li>
<div><!-- tooltip for foo --></div>
<li tooltip="Bar">B</li>
</ul>
</div>
Therefore the solution I came up with was to add id's to each of my li tags:
<li id="foo-tip" tooltip="Foo">A</li>
<li id="bar-tip" tooltip="Bar">B</li>
and then access the css tooltip element like so:
#foo-tip + div {
margin-left: 25px;
}
#bar-tip + div {
margin-left: 15px;
}

Retain scroll position while model is updated in angular js

i have a list of teams and user can add a team to list of teams. the problem i having is that when i add an item to an list, angular re-renders the list and scroll position is reset to the top.
this is the template
<div ng-controller="scores">
<ul>
<li ng-repeat="team in teams">
{{team.name}}:
<button ng-click="decr(team)">-</button>
{{team.score}}
<button ng-click="incr(team)">+</button>
</li>
</ul>
(+)Add Team
</div>
here is the controller code
function scores($scope){
$scope.teams = [
{name:'red', score:100},
{name:'blue', score:100},
{name:'green', score:100}
];
$scope.decr= function(team){team.score-=1;};
$scope.incr= function(team){team.score+=1;};
$scope.add= function(){$scope.teams.push({name:"...", score:100});};
}
you can see working example here. http://jsbin.com/asedib/5
The problem is that you have href="#", which resets the anchor / scroll position to the top of the page every time you click the link.
I see two easy solutions:
The easiest is to change the anchor to a button. This still makes it clear that this is a clickable element, but without the anchor element:
<button ng-click="add()">(+) Add Team</button>
If you prefer the anchor-style appearance, you can remove the href="#", but then update your CSS to style the non-anchor link to look like a link. Something like this:
<a ng-click="add()" class="clickable">(+) Add Team</a>
And the CSS:
a, a.clickable {
color: blue;
text-decoration: underline;
cursor: pointer;
}
Both of these solutions solve the immediate problem without any extra JavaScript.

Resources