css has() selector weirdness (chrome) - css

Recently, I had a case where the has() selector seemed to provide the answer to a problem. And I found that it isn't. And not because FireFox doesn't support it. (Although that is a problem too.)
To show this I made a codepen lookahead selector is weird
The bit with class v1 is the first solution I came up with. And I have no idea why it doesn't work.
When I saw v1 didn't work, I came up with the alternative with class v2. That also didn't work. But I could at least understand why.
Considering that the halves that did work cover all that I need, I made the one with class v3.
Intrigued by v1 not working, I also made v1a,to see if I could figure out which part of the selection doesn't do what I think it does.
And that shows just how weird has() is. Adding the rule for the background of the table flipped the does/doesn't work on the rules.
Also, by accident, I ended up wildly moving across the elements of the table of v1. And at some moment...both rules started working. For v1a, the same. If you want to see this, just make circles on the v1 table hitting all the tds until you see both spans on the right responding.
I tried with both Chrome and Edge. FireFox simply doesn't support it. And I don't happen to have Safari handy to try it on.
Can anyone give an explanation so I understand what is going on? Preferably with pointers to getting something that works in a way that makes a bit more sense.
td {
border: 1px solid black;
}
table {
background-color: skyblue;
margin: 10px;
}
span {
display: inline-block;
padding: 5px;
}
.v1a:has(td .span1:hover) {
background-color: green;
}
.v1:has(td .span3:hover) tr td .span2, /* Ok */
.v1:has(td .span1:hover) tr td .span4 { /* NOk. Why? */
background-color: red;
}
.v2 tr:has(td .span3:hover)~tr td .span2, /* NOk, but I know why. */
.v2 tr:has(td .span1:hover)~tr td .span4 { /* Ok */
background-color: red;
}
.v3:has(td .span3:hover) tr td .span2, /* Ok */
.v3 tr:has(td .span1:hover)~tr td .span4 { /* Ok */
background-color: red;
}
<table class="v1">
<tr>
<td>
<span class="span1">1</span>
</td>
<td>
<span class="span2">2</span>
</td>
</tr>
<tr>
<td>
<span class="span3">3</span>
</td>
<td>
<span class="span4">4</span>
</td>
</tr>
</table>
<table class="v1 v1a">
<tr>
<td>
<span class="span1">1</span>
</td>
<td>
<span class="span2">2</span>
</td>
</tr>
<tr>
<td>
<span class="span3">3</span>
</td>
<td>
<span class="span4">4</span>
</td>
</tr>
</table>
<table class="v2">
<tr>
<td>
<span class="span1">1</span>
</td>
<td>
<span class="span2">2</span>
</td>
</tr>
<tr>
<td>
<span class="span3">3</span>
</td>
<td>
<span class="span4">4</span>
</td>
</tr>
</table>
<table class="v3">
<tr>
<td>
<span class="span1">1</span>
</td>
<td>
<span class="span2">2</span>
</td>
</tr>
<tr>
<td>
<span class="span3">3</span>
</td>
<td>
<span class="span4">4</span>
</td>
</tr>
</table>

Related

How do I display:none specific text with a table?

I need to hide “for 1 year” in the following, using css:
<tr class=”order-total recurring-total”>
<th rowspan=”1″>Recurring total</th>
<td data-title=”Recurring total”>
<strong><span class=”woocommerce-Price-amount amount”><span class=”woocommerce-Price-currencySymbol”>$</span>425.00</span></strong> for 1 year
<div class=”first-payment-date”><small>First renewal: July 4, 2020</small></div>
</td>
</tr>
my editor requires me to set it up something like:
.recurring-total {
display: none;
}
But that hides everything, which I don't want. Any help much appreciated!
First of all, you have errors: Change all occurrences of ” to ".
Then just change the visibility of the td to hidden and all the texts you want visible inside it to visible. That will do.
.recurring-total td[data-title='Recurring total'] {
visibility: hidden;
}
.recurring-total td[data-title='Recurring total'] * {
visibility: visible;
}
<table>
<tr class="order-total recurring-total">
<th rowspan=”1″>Recurring total</th>
<td data-title="Recurring total">
<strong><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>425.00</span></strong> for 1 year
<div class="first-payment-date"><small>First renewal: July 4, 2020</small></div>
</td>
</tr>
</table>

Why does Microsoft Edge ignore td width?

I expected all browsers behave the same, which is setting all tds in a table to the width of the largest width indication of all tds.
Take a look at the following examples:
https://jsfiddle.net/rpkbf4n6/
=> This one is displayed correct in FF/IE but wrong in Edge (the very long text is not wrapped)
https://jsfiddle.net/8oa4fw2u/
=> This one is displayed correct in FF/IE/Edge
Why is this? I don't like to give all tds the width attribute and I don't like to give the width attribute to the largest content td (because the content is filled dynamically, so I don't know which is the largest)
Add a DIV above the table and use table-layout: fixed then it works with Edge
<div class="wrap">
<table class="table">
<tbody>
<tr>
<td style="width:100px;">
<span>Text</span>
</td>
<td>
<input style="width:160px;">
</td>
</tr>
<tr>
<td>
<span>Very very very very very long text</span>
</td>
<td>
<input type="checkbox">
</td>
</tr>
</tbody>
</table>
</div>
.wrap {
width: 500px;
}
.table {
width: 100%;
table-layout: fixed
}

Hide checkbox using css

I have the code, which I get it from inspecting:
<td class=ox-list-pair style>
<input type="CHECKBOX" name="ox_CkSurvey_Sport__xava_selected" value="selected:0" onclick="openxava.onSelectElement('CkSurvey','Sport','null','row=0,viewObject=xava_view',this.checked,'ox_CkSurvey_Sport__0',false,'','border-bottom: 1px solid;','',false,false,0,'xava_tab')">
</td>
I have tried to hide the checkbox but none of them success.
My attempts:
input[type=checkbox].ox_CkSurvey_Sport__xava_selected {
display: none;
}
ox_CkSurvey_Sport__xava_selected {
display: none;
}
.ox_CkSurvey_Sport__xava_selected input[type="checkbox"]{
display:none;
}
Please note that <td> is valid as it is inside <tr> as well as <table>.
Please help me. Thanks.
You should read up on CSS selectors.
https://www.w3schools.com/cssref/css_selectors.asp
You are trying to hide the check box with the class "ox_CkSurvey_Sport__xava_selected", but that doesn't exist.
You need to do this:
input[type=checkbox][name=ox_CkSurvey_Sport__xava_selected] {
display: none;
}
Is your <td> valid? What makes a <td> valid is:
It must be in a <tr>
That <tr> must be in a <table>
Technically <tr> must be in a <tbody>, <thead>, or <tfoot> but the browser will create a <tbody> by default if there's a <table>.
In the demo there's:
a <table>, <tr>, <td>, and your messy checkbox.
a <td> and a simple checkbox.
Note: The selector is td.ox-list-pair > input[type="checkbox"] and it successfully hides the messy checkbox and fails to hide the simple checkbox. So as you can see that the browser will ignore an invalid <td> and everything within it. I'm going out on a limb and assume that your <td> is not inside a <tr> and/or <table>.
Demo
$('td.ox-list-pair > input[type="checkbox"]').css('display', 'none');
b {
color: red
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td class='ox-list-pair' style>
<input type="CHECKBOX" name="ox_CkSurvey_Sport__xava_selected" value="selected:0" onclick="openxava.onSelectElement('CkSurvey','Sport','null','row=0,viewObject=xava_view',this.checked,'ox_CkSurvey_Sport__0',false,'','border-bottom: 1px solid;','',false,false,0,'xava_tab')">I'm
in a valid cell
</td>
</tr>
</table>
<td class='ox-list-pair'>
<input type="CHECKBOX">I'm in an <b>invalid</b> cell
</td>

CSS - Style the title from the image tag

I'm trying to style the title from the image tag.
I have search other question but can´t it put working in my project.
But I can´t make any changes.
Someone can give me hand with this pls?
my code:
table.tablesorter tbody tr td a:hover img[title]:after
{
content: attr(title);
padding: 4px 8px;
color: #FFF;
background-color:black;
}
<table class="tablesorter" style="width:98% !important">
<thead>
<tr>
<th>
.....
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
..........
</td>
<td>
<a href="#Url.Action("Edit","Account", new { id=item.UserId })">
<img src="~/Content/images/icon_edit.png" title="Edit"/>
</a>
</td>
</tr>
</tbody>
<tfooter>
</tfooter>
</table>
It should be content: attr(title);, not content: attr(data-title); - you don't have a data attribute.
Also, it seems ::before and ::after pseudo-elements are not defined for img - you may have to use something else:
CSS Content attribute for IMG tag
Working Example (when the image is missing): http://jsfiddle.net/DMAFm/
Another example, with the title on the <a> tag: http://jsfiddle.net/DMAFm/1/

Mozilla border-radius in a table not working consistently

Driving myself nuts here!.
Firstly can I just clarify that it is no longer necessary to prefix border radius eg with -moz-. But is it good practice to do so in case an old browser is employed?
Secondly I accept that in employing a border radius inside a table demands that border-collapse is not collapse I also believe that border-spacing should not be 0.
The following draft CSS & HTML creates nicely rounded table elements in all browsers except mozilla where for some reason the table is rounded the th is rounded BUT the td's are all square.
Fire bug reports that the radius is applied. Indeed if I place a background colour on td I can see that this background is rounded. But it still displays the remainder as square.
Any thoughts ???
/* borders */
#booking_Form_Wrapper{
border: 0px;
padding: 0px;
margin: 0px;
}
#booking_Table{
width: 300px;
height: 400px;
background-color: #a5a5a5;
border-radius: 14px;
border-spacing: 6px 6px;
}
#booking_Table th{
border-radius: 10px;
}
#booking_Table td{
border-radius: 10px;
}
/* other styles */
HTML
<table id="booking_Table">
<thead id="booking_Title">
<th>
Booking
</th>
</thead>
<tbody>
<tr id="booking_Session">
<td>
<a>Class - Level</a><br />
<a>Day and Date</a><br />
<a>Start Time - End Time</a>
</td>
</tr>
<tr id="booking_XXXXXXX">
<td style="border-radius: 6px;">
<label>Do you want to XXXXXXXX</label><input type="checkbox"/>
<label>XXX</label><input type="radio" name="XXX" value="b">
<label>XXX</label><input type="radio" name="XXX" value="s">
<label>XXX</label><input type="radio" name="XXX" value="r">
</td>
</tr>
<tr id="booking_Cancel">
<td>
<P><span>Cancellation Policy</span> - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</P>
</td>
</tr>
<tr class="form_Footer">
<td>
<input class="form_Submit" type="submit" name="submit" value="Make Booking"/>
<input class="form_Cancel" type="cancel" name="cancel" value="Cancel"/>
</td>
</tr> <!-- form footer -->
</tbody>
</table> <!-- booking table -->
Here is the firebug computed style info for the first square td
I found the solution - I may not be stating this in the correct technical terms but the effect was caused in FF by giving the containing element a height. In my case the <tr>. The interesting thing is that none of the other browsers complain about this and round the <td> regardless. I think that this is connected to the mozilla developer notes which say that the radius is applied to the background of the element where the radius is applied regardless of whether a border is specified or not. The <tr> was not part of the background and so was not rounded.
Anyway don't give the container a height and everything good.

Resources