advanced css: target last adjacent sibling - css

I am trying to target the last adjacent sibling in a situation where I don't know how many siblings there will be (1 to 6). See this plunk: http://plnkr.co/edit/JBsMUg2yl1JkbK6j8Bfj?p=preview
<section>
<div class="c">Category 1</div>
<div class="c">Category 2</div>
<div class="p">product</div>
<div class="p">product</div>
<div class="p">product</div>
<div class="c">Category 3</div>
<div class="p">product</div>
<div class="p">product</div>
<div class="c">Category 4</div>
<div class="c">Category 5</div>
<div class="p">product</div>
<div class="p">product</div>
<div class="p">product</div>
<div class="c">Category 6</div>
<div class="c">Category 7</div>
<div class="c">Category 8</div>
<div class="p">product</div>
<div class="c">Category 9</div>
</section>
My best efforts still left me with this missing: Category 3 SHOULD be selected; Category 7 should NOT be selected.
div {
padding: 5px;
margin-bottom: 5px;
}
.c {
color: yellow;
background: blue;
opacity:.1;
}
.c+.c {
opacity:1;
}
.p+.c {
color: yellow;
background: blue;
}
.c:last-child { /* orphan cat on end of list */
opacity:.1;
}
I cannot easily change my html, nor put a class on the last adjacent sibling.
The background: this is a catalog rendered by angular ng-repeat on a flat array that contains category headings followed by products. The ng-repeat uses a text filter (from a search box) which ignores the category headings (otherwise they would likely all be hidden) and applies only to the products. I therefore end up with a situation where I have empty category heading which I want to remove via css (but other suggestions are welcome)

The solution shown here: http://plnkr.co/edit/6DUHUEHC9j5mONGG1z0N?p=preview will work as far as creating the visual effect I need.
It uses separate <ul> for each category and :only-child pseudo selector.
However, it is actually not an acceptable answer to the question because it required changing the html which was undesirable. I think there should still be a solution for a flat list of elements using some combination of nth child / last child / not(), etc. but haven't found it yet.

I changed the HTML code and used the title-Attribute as well as the CSS visibility property. Thats the only solution I can imagine right now.
.c {
visibility: hidden;
}
.c ul {
visibility: visible;
}
.c ul:before {
content: attr(title);
}
<ul>
<li class="c">
Category 1
</li>
<li class="c">
Category 2
<ul title="Category 2">
<li class="p">product</li>
<li class="p">product</li>
<li class="p">product</li>
</ul>
</li>
<li class="c">
Category 3
<ul title="Category 3">
<li class="p">product</li>
<li class="p">product</li>
</ul>
</li>
<li class="c">
Category 4
</li>
<li class="c">
Category 5
<ul title="Category 5">
<li class="p">product</li>
<li class="p">product</li>
<li class="p">product</li>
</ul>
</li>
<li class="c">
Category 6
</li>
<li class="c">
Category 7
</li>
<li class="c">
Category 8
<ul title="Category 8">
<li class="p">product</li>
</ul>
</li>
<li class="c">
Category 9
</li>
</ul>

Related

CSS Grid auto-fit + minmax only wraps the last element

I'm trying to make a responsive footer using grid and it's almost working but not quite. When the screen is wide everything's spaced out perfectly. Once the screen size gets smaller, the items should start wrapping onto the next implicit row. At least that's what happened in a video guide I watched.
In my case though, for some reason only the last item wraps to the next row while the rest of them stay static causing overflow and horizontal scrolling. I've been trying to figure out what's going for a few hours now but no luck. Am I not seeing something? Please help.
.footer__logo {
width: 40px;
margin-bottom: var(--spacer-xs);
}
.footer__header {
margin-bottom: var(--spacer-xs);
}
.contact-us {
margin-top: var(--spacer-xs);
}
.footer__unit--last {
align-self: end;
}
.footer-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 10px;
}
<footer class="footer">
<div class="container footer-grid">
<div class="footer__unit">
<h3 class="footer__header">Abstract</h3>
<ul class="footer__list">
<li class="footer__item">Start Trial</li>
<li class="footer__item">Pricing</li>
<li class="footer__item">Download</li>
</ul>
</div>
<div class="footer__unit">
<h3 class="footer__header">Resources</h3>
<ul class="footer__list">
<li class="footer__item">Blog</li>
<li class="footer__item">Help Center</li>
<li class="footer__item">Release Notes</li>
<li class="footer__item">Status</li>
</ul>
</div>
<div class="footer__unit">
<h3 class="footer__header">Community</h3>
<ul class="footer__list">
<li class="footer__item">Twitter</li>
<li class="footer__item">LinkedIn</li>
<li class="footer__item">Facebook</li>
<li class="footer__item">Dribble</li>
<li class="footer__item">Podcast</li>
</ul>
</div>
<div class="footer__unit">
<h3 class="footer__header">Comapny</h3>
<ul class="footer__list">
<li class="footer__item">About Us</li>
<li class="footer__item">Careers</li>
<li class="footer__item">Legal</li>
</ul>
<ul class="footer__list contact-us">
<li>
<h4 class="contact-us__header">Contact Us</h4>
</li>
<li class="footer__item">info#abstract.com</li>
</ul>
</div>
<!-- Footer last item -->
<div class="footer__unit footer__unit--last">
<img src="/img/venus-svgrepo-com.svg" alt="logo" class="footer__logo">
<ul class="copyright">
<li class="copyright__item">
<p class="copyright__text">© Copyright 2022</p>
</li>
<li class="copyright__item">
<p class="copyright__text">Abstract Studio Design, Inc.</p>
</li>
<li class="copyright__text">
<p class="copyright__item">All rights reserved</p>
</li>
</ul>
</div>
</div>
</footer>
I made a screenshot, as you can see the last item (copyright section) wraps while the rest of them stays where they are.
https://i.stack.imgur.com/ht35u.png
edit: added screenshot

pseudoelement works in Firefox but not Chrome, why?

I am trying to use a pseudoelement to replace the <li> for <ul> with a triangle. I followed this tutorial.
The problem is that my CSS works in Firefox but not Chrome on Windows.
Here is my CSS:
article ul {
list-style: none;
}
article ul > li::before {
font-family: FontAwesome;
content: "\f0da";
color: $darkbrown;
display: inline-block;
width: 1em;
margin-left: -1em
}
I am targeting article because I have <ul> in the header and footer that I do not want to apply the triangle to.
In Firefox, this works as expected (<ul> in the article have the triangle, and <ol> in the article show numbers). However, in Chrome, the <ul> in the article have a triangle, but the <ol> in the article also have triangles.
Here's an example of the HTML (sorry, it's from Drupal and a little ugly; I cleaned it up as best I could):
<body class="path-node page-node-type-lp navbar-is-static-top has-glyphicons">
<a href="#main-content" class="visually-hidden focusable skip-link">
メインコンテンツに移動
</a>
<div role="main" class="main-container container js-quickedit-main-content">
<div class="row">
<div class="col-sm-12" role="heading">
<section class="col-sm-12">
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10 col-xs-12">
<a id="main-content"></a>
<div class="region region-content">
<article role="article" about="/myurl" class="lp full clearfix">
<div class="content">
<div class="layout layout--onecol">
<div class="layout__region layout__region--content">
<section
class="block block-layout-builder block-field-blocknodelpbody clearfix">
<div class="field field--name-body field--type-text-with-summary field--label-hidden field--item">
<ol>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ol>
</div>
</section>
</div>
</div>
</div>
</article>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</body>
I'm not sure i'm understanding your issue as your code appears to work the way you intend. I've added a <ul> inside your <article> to show that it has a triangle next to it while the <ol> shows the default numbering. Try browsing this example in Chrome to see the results.
article ul {
list-style: none;
}
article ul>li::before {
font-family: FontAwesome;
content: "\f0da";
color: red;
display: inline-block;
width: 1em;
margin-left: -1em
}
<a href="#main-content" class="visually-hidden focusable skip-link">
メインコンテンツに移動
</a>
<div role="main" class="main-container container js-quickedit-main-content">
<div class="row">
<div class="col-sm-12" role="heading">
<section class="col-sm-12">
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10 col-xs-12">
<a id="main-content"></a>
<div class="region region-content">
<article role="article" about="/myurl" class="lp full clearfix">
<div class="content">
<div class="layout layout--onecol">
<div class="layout__region layout__region--content">
<section class="block block-layout-builder block-field-blocknodelpbody clearfix">
<div class="field field--name-body field--type-text-with-summary field--label-hidden field--item">
<ol>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ol>
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
</div>
</section>
</div>
</div>
</div>
</article>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
I finally found the problem, which related to inlining critical css using the Drupal CriticalCSS module.
Basically, what happened is that I had generated the critical CSS based on old CSS, and this inline css (the critical CSS) was overriding the working CSS in the file I was editing.
Apparently, Firefox gives priority to the non-inline CSS, while Chrome and Edge prioritize the inline CSS, hence the reason for the difference in what was displayed.
Lesson learned: Make sure any inline CSS is current when editing CSS. (I am looking in to ways to automate that right now.)

Issue on Ordering Thumbnails in bootstrap 3

Hi I am trying to create simple slider for displaying latest product on the page using Bootstrap 3 at This DEMO. I have 6 thumbnails in a gallery div which I would like to display only 4 of them in front view and slide to left to see two more. I used bootstrap
<ul class="list-inline">
<li>...</li>
</ul>
css to render a display: inline-block; list of my <li>s but I do not know why they are not fitting in one line and 2 last items displays at the buttom of the gallery box. BESIDES the first <li> looks taller (Even if I have only 4 <li>).
Now my questions are:
1 - Why The First item Looks taller than the rest?
2 - Why Items are not displaying in a line?
3 - Finally why the overflow: hidden; property in .gallery is not performing properly?
and here is my code:
.gallery {
margin: 0 auto;
overflow: hidden;
width: 100%;
position: relative;
max-height:325px;
}
<!-- About Section -->
<section id="ft" class="cbp-so-section cbp-so-init">
<div class="container cbp-so-side cbp-so-side-top">
<h4>Latest Features</h4>
<div class="row">
<div class="well gallery col-lg-12 col-md-12 col-sm-2 col-xm-1">
<ul class="list-inline">
<li class="col-sm-3">
<div class="well"><img src="http://placehold.it/500x500" alt="Image" class="img-responsive"></div>
</li>
<li class="col-sm-3">
<div class="well"><img src="http://placehold.it/500x500" alt="Image" class="img-responsive"></div>
</li>
<li class="col-sm-3">
<div class="well"><img src="http://placehold.it/500x500" alt="Image" class="img-responsive"></div>
</li>
<li class="col-sm-3">
<div class="well"><img src="http://placehold.it/500x500" alt="Image" class="img-responsive"></div>
</li>
<li class="col-sm-3">
<div class="well"><img src="http://placehold.it/500x500" alt="Image" class="img-responsive"></div>
</li>
<li class="col-sm-3">
<div class="well"><img src="http://placehold.it/500x500" alt="Image" class="img-responsive"></div>
</li>
</ul>
</div>
</div>
</div>
</section>
Playing a bit with Firebug, I found that the issue here is because of the following rule:
.list-inline > li:first-child {
padding-left: 0;
}
All the .list-inline > li elements have a padding-left:5px rule, expect the first child. Because of that missing padding in the first child, the img inside has 5px more width (because of the max-width:100%; rule).
If you set the width of the img in pixels, you will not have this issue.
Regarding the (2) question, the bootstrap grid system requires that in one row the number sum of the col-sm-* is 12. You need to change in from col-sm-3 to col-sm-2 to have all 6 items in one line.
Regarding the (3) question, I am not sure what exactly you are expecting to see.
EDIT 2: See this link for a CSS fix http://bootply.com/111878
.gallery {
margin: 0 auto;
overflow: hidden;
width: 100%;
position: relative;
max-height:310px;
}
.list-inline img.img-responsive {
height: 233px;
width: 233px;
}

How to create fluid semantical layout with Twitter Bootstrap using LESS?

I want to create fluid layout using LESS and without using Bootstrap grid clasess like .span6 on html code. How can I do this?
When I wrote without LESS I create layout like this:
<div class="container-fluid">
<div class="row-fluid" id="header">
<div class="span4 block">
<h1 class="title">Sample Site</h1>
<h2 class="sub-title">Powered by Twitter Bootstrap</h2>
</div>
<div class="span6 block">
<ul class="nav nav-pills">
<li class="active">Home</li>
<li>Pages</li>
<li>Typography</li>
<li>UI</li>
<li>Calendar</li>
<li>Tables</li>
</ul>
</div>
<div class="span2 block">
<div class="btn-group open">
<button class="btn">Dropdown</button>
<button class="btn dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Change password</li>
<li>Log in with another user</li>
<li>Change token</li>
<li>Log out</li>
</ul>
</div>
</div>
</div>
<div class="row-fluid" id="slider">
<div class="span12 block">
<div id="myCarousel" class="carousel slide">
<div class="carousel-inner">
Now, my layout looks next way:
<div id="wrap">
<div id="header">
<div id="logo">SiteLogo</div>
<div id="top-menu">
<ul>
<li>Home</li>
<li>Page 1</li>
<li>Page 2</li>
</ul>
</div>
<div id="logout">
Logout
</div>
</div>
<div id="slider">
and what I should write on my .less file if I want to make div#wrap -> .container-fluid,
div#header -> .row-fluid, div#logo -> .span4, div#top-menu -> .span6, div#logout -> .span2
without writting this clasess on html code?
First, this wouldn't really be semantic, at least, no more so.
The semantic form of <div id="top-menu"> is <nav> or <nav id="top">
The semantic form of <div id="header"> is <header>
In any case, there are instructions on doing this here:
Please stop embedding Bootstrap classes in your HTML
Honestly, though, it's not as simple as the author makes it look. Just because you have a <nav> inherit the styles of .nav from Bootstrap doesn't mean its children will inherit inherited styles as well.
So if I define a style from .nav ul, a <ul> element will not receive this style if it's in a <nav>.
This worked for me.. posting in case it helps anyone else.
Mixins for semantic fluid grid:
.makeFluidRow(){
width: 100%;
.clearfix();
}
.makeFluidCol(#span:1,#offset:0){
float: left;
#grid > .fluid .span(#span);
#grid > .fluid .offset(#offset);
&:first-child {
margin-left: 0;
.offsetFirstChild(#offset);
}
}
Use them just like the non-fluid mixins:
div#header{
.makeFluidRow();
div#logo {
.makeFluidCol(4); //Spans 4 cols
}
div#top-menu {
.makeFluidCol(6); //Spans 6 cols
}
div#logout {
.makeFluidCol(2); //Spans 2 cols
//Or you could have span1, offset1 using .makeFluidCol(1,1);
}
}

<li> styling with css (chrome problems)

Hello I've got this weird problem with css.
I'm displaying an unordered list
<ul>
<li>
<div class='align-left'>
PMI
</div>
<div class='align-right'>
<img src="/img/delete_icon2.png" id='19' class="elim" name="19">
</div>
</li>
<li>
<div class='align-left'>
GRANDS COMPTES
</div>
<div class='align-right'>
<img src="/img/delete_icon2.png" id='21' class="elim" name="21">
</div>
</li>
<li>
<div class='align-left'>
associations
</div>
<div class='align-right'>
<img src="/img/delete_icon2.png" id='22' class="elim" name="22">
</div>
</li>
<li>
<div class='align-left'>
PME
</div>
<div class='align-right'>
<img src="/img/delete_icon2.png" id='25' class="elim" name="25">
</div>
</li>
<li>
<div class='align-left'>
ecoles privees
</div>
<div class='align-right'>
<img src="/img/delete_icon2.png" id='28' class="elim" name="28">
</div>
</li>
<li>
<div class='align-left'>
organisme
</div>
<div class='align-right'>
<img src="/img/delete_icon2.png" id='32' class="elim" name="32">
</div>
</li>
<li>
<div class='align-left'>
test
</div>
<div class='align-right'>
<img src="/img/delete_icon2.png" id='34' class="elim" name="34">
</div>
</li>
</ul>
now this is accompanied by these css rules:
.align-right{
float: right;
}
.align-left{
float: left;
}
On chrome, the bullet point from the list is actually UNDER the text for the bullet point.
Why did I do this, I want the images to be aligned from top down.
here are screenshots of the problem
thanks in advance.
the code you provided won't cause this problem.
Depending on what you want to do, adding
ul { list-style-type:none; }
or
ul li { padding-left:40px; }
may achieve desired effect.
edit
try adding overflow:hidden; to the li elements
I'd also personally do it like this:
li {
background:url(/img/delete_icon2.png) no-repeat center right;
padding-right:25px; /*might need to adjust */
}
<ul>
<li>PMI</li>
<li>Bla bla</li>
</ul>
no need to over-complicate things.
If you want the DIVS clickable you can just do
<li>PMI</li>
and CSS:
li a { display:block; width:xxx; height:xxx; }
as required.
Try playing with the list-style-position property. Options are inside and outside.
I had the same problem and it seems that you do not have exact control over the position of the default bullet point.
For me the following was working in Firefox and in IE, but in Chrome it is positioned inside the text:
<ul style="list-style-position: outside; margin:0; padding:0;">
<li />
<li />
</ul>
I needed to set margins and paddings for both the list and the list items to get the bullet point(disk) outside the text
<ul style="list-style-position: outside; margin:10px; padding:10px;">
<li style="padding: 10px 0 0 3px; margin-bottom: 8px;" />
<li style="padding: 10px 0 0 3px; margin-bottom: 8px;" />
</ul>
The strange part is, that if I set those bottom margins to anything less than 7 pixel, the bullets jump inside. 8px is the smallest working value, although there is lots of space around and between the elements (they move closer to each other fluently, only the bullet points start to jump).

Resources