I'm looking to hide an element platform-group based on whether it has any visible job-btn children. If all the children are hidden, then I'd like to hide the parent.
So if I have HTML showing like this:
B R( C J ) HideMe( )
I would like it to show like this:
B R( C J )
A JS fiddle with this is here: http://jsfiddle.net/cheshirecam/wf60z08n/5/
The HTML:
<tr>
<span style="display: inline-block;" class="job-btn">B</span>
<span style="display: inline;" class="platform-group">R(
<span style="display: inline-block;" class="job-btn filter-shown">C</span>
<span style="display: inline-block;" class="job-btn filter-shown">J</span>
<span style="display: none;" class="job-btn">V</span>
</span>
<span style="display: inline;" class="platform-group">HideMe(
<span style="display: none;" class="job-btn">C</span>
<span style="display: none;" class="job-btn">J</span>
</span>
</tr>
CSS:
.platform-group::after {
content: ")";
}
B, C and J are different job codes. C and J are in the platform-group of R. The platform-group of "HideMe" has no visible jobs, so I'd like it to hide itself.
A job gets the filter-shown class added/removed and the display: none or inline-block depending on some complex filter parameters the user can set. When I do that check, I could add or remove anything from the element. Adding/removing a class seems slow, and data values seem slow, too. Is there something better to tag the element with that the parent can detect somehow? Something that works kind of like this seems so close: https://developer.mozilla.org/en-US/docs/Web/CSS/:empty
I have this working using jQuery to check if the parent has 0 descendents jobs with the .filter-shown class and then hiding it.
The trick is, I'm doing this thousands of times on the page (it's a test-result dashboard of extra-ordinary magnitude) I would like a CSS only (or at least mostly) solution. The problem is it's kind of slow when turning filtering on and off. Profiling shows that adding/removing the filter-shown class is fairly expensive for each job.
I'm not above rearranging the HTML to make this work, as long as it looks roughly the same visually. Any thoughts or ideas on good directions to try are most appreciated.
Rather than adding classes suppose, in the Javascript/jQuery, you add the child spans you want shown by setting the innerHTML of the parent? Then, if there were no spans added, the parent element would be truly empty, and you could then use :empty, as in:-
platform-group:empty {
display : none;
}
Related
Context (skip ahead for question):
While designing a Stylish theme for the online typing game, Typeracer (in Css), I stumbled on this problem:
As the user progresses, the portion of the text already typed turns from gray to green. I would like to change this green color, to any other.
What the text progress interface looks like on Typeracer
What makes it difficult, is that this block is broken into multiple spans, without any id, which get assigned multiple random classes -- different ones every game, and which change during the race:
Example of the architecture of the text progress interface
Leaving aside the very last span, which is collapsed on the screenshot above, and does not interest us -- a varying number of spans represent the portion of the text which was already typed, and a varying number of others represent the portion which was not typed yet (In the screenshot above, the first two spans contain the "typed" portion, while the last two spans represent the "not typed" portion. But later in the same race, these numbers may become 1 and 2, or 3 and 1, etc.)
I have however noticed that the spans representing the text already typed, and the spans representing the text which was not typed yet, share the same first class: in the example from screenshot #2, the "typed" portion spans have "vdFKqLpl" as their first class, and the "not typed yet" portion spans have "CARsHknB" as their first class.
I have attempted to select the first group of spans by their style.color attribute instead:
.span[style*="color: #99cc00;"] {
color: #ff0000;
}
But I could not get any results.
Question:
Is it possible, using css, to select children elements sharing the same first class, without specifically knowing what that class is?
For example, if the parent div is:
<div>
<span unselectable="on" class="vdFKqLpl">When the little bluebird, who has never said a word, starts to sing, </span>
<span unselectable="on" class="vdFKqLpl CARsHknB">"Spri</span>
<span unselectable="on" class="CARsHknB WvLvCiod">n</span>
<span unselectable="on" class="CARsHknB">g</span>
<span unselectable="on">...</span>
</div>
Where "vdFKqLpl" and "CARsHknB" are randomly attributed classes which I cannot know ahead,
is it possible to select the first two divs, which share "vdFKqLpl" as their first class?
I don't know if this will work completely, but this could get you closer.
span {
color: green;
}
span[class*=" "], span[class*=" "] ~ span {
color:red;
}
<div>
<span unselectable="on" class="vdFKqLpl">When the little bluebird, who has never said a word, starts to sing, </span>
<span unselectable="on" class="vdFKqLpl CARsHknB">"Spri</span>
<span unselectable="on" class="CARsHknB WvLvCiod">n</span>
<span unselectable="on" class="CARsHknB">g</span>
</div>
I am aiming to open all collapsible items on a certain website that doesn't belong to me.
The website is built in a way that only one collapsible item can be opened at a time, while I would like to open all items at once:
Webpage screenshot
While inspecting the element I noticed that once an item is clicked its status changes from "display: none;" to "display: block;"
I can successfully manually change all items from "display: none;" to "display: block;"
However, I would like to find an easier way to do so since the webpage contains more than 200 items. Any suggestions on how I might be able to do so?
Here is what the code looks like in one out of 200 similar items-
<div class="meaning" data-font-size="17" data-font-size-type="px" data-line-height="24.2857px" style="display: none;">לפחות</div>
If the site has jQuery (try "$" in the console) you can find all the class="meaning" elements with $(".meaning") and then show() them. Like this:
$(".meaning").show()
If the site has jquery you can use
$(".meaning").css("display", "block");
$(".meaning").css("display", "none");
Created a blog using Jekyll and git hub pages. I need to indent to align a list of expenses. I found a way how, but I would like to insert that into a function.
Example:
Sum of Contractor expenses - $6,800
Heating and Air - $5,100
Fridge and Stove - $1,100
Hardware store purchases - $5,000
Miscellaneous - $2,000
I would like all of the amounts to line up.
According to this SO question, I can use to create a space. However, I need to insert a lot of these to obtain what I want.
Another suggestion is Tab+Space but this doesn't seem to work in the middle of the text.
From the same post, I tried using Alt+0+1+6+0 and that seems to work.
The expected results would look like this.
Sum of Contractor expenses - TAB;$6,800
Heating and Air - TAB;(5)$5,100
As the answer to that SO question states:
There's no way to do that in markdown's native features. However markdown allows inline HTML...
There are a couple of ways you could do this. You could use a <table> element, where the HTML looks like this:
<table>
<tr><td>Sum of Contractor expenses</td><td>$6,800</td></tr>
<tr><td>Heating and Air</td><td>$5,100</td></tr>
<tr><td>Fridge and Stove</td><td>$1,100</td></tr>
<tr><td>Hardware store purchases</td><td>$5,000</td></tr>
<tr><td>Miscellaneous</td><td>$2,000</td></tr>
</table>
Or, you could use class names and CSS, where the HTML looks like this:
<div>
<span class="description">Sum of Contractor expenses</span>
<span class="cost">$6,800</span>
</div>
<div>
<span class="description">Heating and Air</span>
<span class="cost">$5,100</span>
</div>
<div>
<span class="description">Fridge and Stove</span>
<span class="cost">$1,100</span>
</div>
<div>
<span class="description">Hardware store purchases</span>
<span class="cost">$5,000</span>
</div>
<div>
<span class="description">Miscellaneous</span>
<span class="cost">$2,000</span>
</div>
And, the CSS looks like this:
.description { width: 100px }
.cost { width: 30px; text-align: right; }
Note 1: You'll need to play with the widths to get things aligned the way you want.
Note 2: You could also apply class names and CSS to the <td> tags in the <table>.
I select all <a> elements inside all <td> elements
<td class="thread">
<i class="ter green"></i>
Something about...
<p class="info">Author</p>
</td>
I use the following:
driver.findElements(By.cssSelector("td.thread a"));
However, I'm getting much more elements than there should be. I guess that I must select only first a inside td class="thread". How can I do that?
When you use the CSS Selector td.thread a, that reads any descendant a under td.thread. What you more likely want is td.thread > a which reads a child a of td.thread. It's still possible there are more than one a but you will likely get a lot fewer depending on the overall HTML.
CSS Selector reference
thread = driver.find_element_by_class_name('thread')
correct_link = thread.find_element_by_tag_name('a').get_attribute('href')
print(correct_link)
>>> "/forum/threads/12/"
I have this table in some code;
<table>
<tr><td align="left">One</td><td align="center">Two</td><td align="right">Three</td>
<tr><td align="left">One</td><td align="center">Two</td><td align="right">Three</td>
<tr><td align="left">One</td><td align="center">Two</td><td align="right">Three</td>
</table>
I would like to not use tables and do the alignment and such all in CSS. I tried;
<span style="float:left;">One</span><span style="margin-left:auto;margin-right:auto;">Two</span><span style="float:right;">Three</span>
<span style="float:left;">One</span><span style="margin-left:auto;margin-right:auto;">Two</span><span style="float:right;">Three</span>
<span style="float:left;">One</span><span style="margin-left:auto;margin-right:auto;">Two</span><span style="float:right;">Three</span>
Example would be trying to convert this data to CSS to align as the table would;
<table>
<tr><td align="left">Bob</td><td align="center">Dingle</td><td align="right">3923.33</td></tr>
<tr><td align="left">Johann</td><td align="center">Strauss</td><td align="right">33.33</td></tr>
<tr><td align="left">Skip</td><td align="center">Skipperson</td><td align="right">0</td></tr>
</table>
But the text in the middle doesn't align correctly as its jagged (different lengths) and so are the left and right values. Seems this is madness and I am leaning towards "Just Use Tables".
First, get your HTML right: Use the correct tags to contain your data. The information you gave isn't really enough for us to ascertain what type of information you're trying to format. If it is tabular data, then there's no shame in using tables - its what its meant for.
Now the correct manner to using CSS is not to place all of your styles inline like what you are doing. Keep them in a separate CSS file instead, and use selectors to avoid having to repeat yourself so many times.
Here's the solution: http://www.jsfiddle.net/2TDXc/
Oh, and please don't listen to that 'Just Use Table' bullcrap. Really, its better for everyone in the long run.
What do you mean jagged? You mean you want text-align:justify ? Or do you mean you're having trouble with the columns being different heights? If the latter, containing divs might help. For that matter, try using divs instead of spans or setting display:block
Anyway, looking at the CSS templates provided by Matthew James Taylor may help if you mean the latter problem.
You need to make use of the display:inline and display:inline-table css attributes. They're great for forcing any element to sit next to each other on the same line.
<div>
<span style="display:inline-table;padding:2px;">One</span><span style="display:inline-table;padding:2px;">Two</span><span style="display:inline-table;padding:2px;">Three</span><br />
<span style="display:inline-table;padding:2px;">One</span><span style="display:inline-table;padding:2px;">Two</span><span style="display:inline-table;padding:2px;">Three</span><br />
<span style="display:inline-table;padding:2px;">One</span><span style="display:inline-table;padding:2px;">Two</span><span style="display:inline-table;padding:2px;">Three</span><br />
</div>
As for the jagged-ness, you must realize that your columns do not inherit or share anything from each other like they would in a table, so you'll ultimately have to hardcode a width. It looks like a table might be what you need.