Merge CSS declarations in one, possible? - html

I am trying to face a little problem i have encountered with.
I am designing a map in leaflet. What i want to achieve is add a HTML label above each marker in a leaflet map, like in this photoshoped example:
Ok the code for each label to display it is:
HTML
<table>
<tr>
<td class="red"></td>
<td class="yellow"></td>
<td class="orange"></td>
<td class="blue"></td>
</tr>
</table>
CSS
table{
border-collapse: collapse;
}
td{
padding:20px;
border:5px solid black;
}
.red{
background-color:#F15E66;
}
.yellow{
background-color:#FFDB64;
}
.orange{
background-color:#F58326;
}
.blue{
background-color:#85B1DE;
}
check https://jsfiddle.net/YameenYasin/cx1ka3Ly/ for the live code.
Ok the problem comes when leaflet labels only allow to add one unique CSS entry for each label. Example:
marker.bindLabel('<table><tr><td class="red"></td><td class="yellow"></td><td class="orange"></td><td class="blue"></td></tr></table>',
{noHide: true, className: "onlyone", offset: [-10, -40] });
Notice the className: "onlyone" property. I can only put one css there and the "class" tags added in the html code are not executed (they do not work).
My conclusion is that i need to add all the CSS code in only one classname called "onlyone" so that then i can do className: "onlyone".
Is this possible?
Regards,

It's possible to add a single class to the tr and then target the children by 'number' using nth-child as follows.
table {
border-collapse: collapse;
}
td {
padding: 20px;
border: 5px solid black;
}
.multi td:nth-child(1) {
background-color: #F15E66;
}
.multi td:nth-child(2) {
background-color: #FFDB64;
}
.multi td:nth-child(3) {
background-color: #F58326;
}
.multi td:nth-child(4) {
background-color: #85B1DE;
}
<table>
<tr class="multi">
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>

Here you are:
https://jsfiddle.net/cx1ka3Ly/2/
table{
border-collapse: collapse;
}
td{
padding:20px;
border:5px solid black;
}
.onlyone:nth-child(1){
background-color:#F15E66;
}
.onlyone:nth-child(2){
background-color:#FFDB64;
}
.onlyone:nth-child(3){
background-color:#F58326;
}
.onlyone:nth-child(4){
background-color:#85B1DE;
}

Related

Cell Background in html

I want to provide backgroud color to table cell based on the value this is what so far i have done:
<style type="text/css">
.Scheduled {
background-color: lime;
}
.Completed {
background-color: lawngreen;
}
.Completed with error {
background-color:red ;
}
.Pending {
background-color: #ffbf00 ;
}
</style>
<td class="#item.Status" >
#Html.DisplayFor(modelItem => item.Status)
</td>
i want Complete with error cell to be in Red how can i do it? what i am doing wrong?
expected output:
The spaces in .Completed with error make it an invalid css class name.
If the class name was changed to .Completed-with-error, then it would become valid.
Let's fix this:
<td class="#item.Status.Trim().Replace(' ', '-')" >
#Html.DisplayFor(modelItem => item.Status)
</td>
Now change your CSS as well:
<style type="text/css">
.Scheduled {
background-color: lime;
}
.Completed {
background-color: lawngreen;
}
.Completed-with-error {
background-color:red ;
}
.Pending {
background-color: #ffbf00 ;
}
</style>
Voila!
Updated:
Add .Trim(), to clean up any trailing spaces.
So the first thing that I see is .Completed with error which is not a valid css class. You can't have spaces in a css class.
You'll need to amend the code so the class is .Completed-with-error. Both on the HTML and in the styles.
you may find this useful, notice i dont have border outside table
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid #888;
}
td{
color: #fff;
padding: 6px
}
.red{
background-color: red;
}
.green{
background-color: green;
}
.blue{
background-color: blue;
}
.pink{
background-color: pink;
}
<table border="1">
<tr>
<td class="red">fjdfk fdfdf</td>
<td class="green">fjdfk fdfdf</td>
</tr>
<tr>
<td class="blue">fjdfk fdfdf</td>
<td class="pink">fjdfk fdfdf</td>
</tr>
<tr>
<td class="red">fjdfk fdfdf</td>
<td class="green">fjdfk fdfdf</td>
</tr>
</table>

Html hover style for each row

This is my view table:
<tr>
<th><p>ID</p></th>
<th><p>NAME</p></th>
<th><p>CLASS</p></th>
<th><p>EDIT</p></th>
<th><p>DELETE</p></th>
</tr>
This is my css file:
table.mytable tr{
background-color: #ffff99;
}
For highlights rows using hover, it is not working for me. i don't know where i did wrongly kindly help on this issue?
Many thanks,
viswa
User :hover selector to hover color:
table.mytable tr:hover{
background-color: #ffff99;
}
<table class="mytable">
<tr>
<th><p>ID</p></th>
<th><p>NAME</p></th>
<th><p>CLASS</p></th>
<th><p>EDIT</p></th>
<th><p>DELETE</p></th>
</tr>
<tr>
<td>1</td>
<td>ABC</td>
<td>2</td>
<td>edit</td>
<td>delete</td>
</tr>
</table>
tr:hover {
background-color: #ffff99;
}
Check here
try this one:
ADD P:hover selector to hover color:
p:hover{
background-color: #ffff99;
}
Thanks
DEMO HERE
OR
.mytable{
width:100%;
border-collapse:collapse;
border:#4e95f4 1px solid;
}
.mytable td{
padding:7px;
border:#4e95f4 1px solid;
}
.mytable tr{
background: #b8d1f3;
}
.mytable tr:hover {
background-color: #ffff99;
}
DEMO UPDATED HERE
viswa.
To highlight on hover, you need to add the css for hover too. Since, you are enclosing your rows in <p> tags, you can use the following in you css file.
p:hover{
background-color: #ffff99;
}
Make sure there is no space between : and the word 'hover'.

Css select all but first tr doesn't work

Here's the fiddle:
https://jsfiddle.net/80mek2sL/1/
I want to select all but the first tr and apply:
border-top: 1px grey solid;
Then I want to select all first td's but not the first td of the first tr (= ignore first tr) and apply
border-right: 1px grey dotted;
(I totally dont care about compatibility with prehistorical Web browsers, I just want it to work on nowadays Web browsers)
What I dont get (that's why I'm lost actually) is that immediate selector table > tr doesn't select tr (otherwise I would have solved my problem)
Your selector is working. The problem is that tr's don't have a border. You need to apply it the td within...
#cheatsheet tr:not(:first-child) td {
border-top:1px grey solid;
background-color: #EF0;
}
Updated Fiddle
#cheatsheet td {
margin:2px;
padding:2px
}
#cheatsheet tr td:first-child {
padding-left:10%;
width:30%;
}
#cheatsheet thead {
background-color: #EFE;
}
#cheatsheet h3 {
text-align: center;
}
table#cheatsheet {
border:1px black solid;
margin:2px; padding:2px;
border-right:1px grey solid;
width:100%;
}
#cheatsheet tr:not(:first-child) td {
border-top:1px grey solid;
background-color: #EF0;
}
<h1>Vim</h1>
<table id="cheatsheet">
<thead><tr>
<td colspan="2"><h3>aa</h3></td>
</tr></thead>
<tr>
<td><code class="prettyprint lang-sh">:split</code></td>
<td style="width:auto">bb</td>
</tr>
<tr>
<td><code class="prettyprint lang-sh">:vsplit</code></td>
<td style="width:auto">split vertical</td>
</tr>
</table>
On another note, the reason table > tr doesn't work is because tr's are not an immediate descendant of table in the rendered HTML. If you use your browsers element inspector you will see that thead and tbody elements are automatically inserted for you
EDIT
After the comment below all you need to do is this...
#cheatsheet tbody td {
border-top:1px grey solid;
background-color: #EF0;
}
ie. target the td within tbody only,
Updated Fiddle
check fiddle :https://jsfiddle.net/80mek2sL/6/
nth-child(n+2) selector helps to select any number of child. in following example I am selecting row from ahead of second child.
#cheatsheet tr:nth-child(n+2) td {
border-top:1px grey solid;
background-color: #EF0;
}
You can also play aorund (n + *) and check the result to better understand the nth-child selector
note: you can not put border property to <tr> so you will need to
assign it to <td>
HTML
<table id="cheatsheet">
<thead>
<tr>
<td colspan="2">
<h3>aa</h3>
</td>
</tr>
</thead>
<tr>
<td><code class="prettyprint lang-sh">:split</code>
</td>
<td style="width:auto">bb</td>
</tr>
<tr>
<td><code class="prettyprint lang-sh">:vsplit</code>
</td>
<td style="width:auto">split vertical</td>
</tr>
<tr>
<td><code class="prettyprint lang-sh">:vsplit</code>
</td>
<td style="width:auto">split vertical</td>
</tr>
<tr>
<td><code class="prettyprint lang-sh">:vsplit</code>
</td>
<td style="width:auto">split vertical</td>
</tr>
</table>
CSS
#cheatsheet td {
margin:2px;
padding:2px
}
#cheatsheet tr td:first-child {
padding-left:10%;
width:30%;
}
#cheatsheet thead {
background-color: #EFE;
}
#cheatsheet h3 {
text-align: center;
}
table#cheatsheet {
border:1px black solid;
margin:2px;
padding:2px;
border-right:1px grey solid;
width:100%;
}
#cheatsheet tr:nth-child(n+2) td {
border-top:1px grey solid;
background-color: #EF0;
}

Firefox not respecting visibility:hidden on table header

I want the header of the first column in my table to be hidden, to get this look:
So I am using the CSS visibility: hidden; to do so. The screenshot above is taken in Chrome, where it works perfectly. However, this happens in Firefox:
How can I make Firefox hide the header of the first column in a table?
EDIT: Here's my table CSS, as requested:
.styledtable{
width:100%;
table-layout:fixed; /*each column same width, unless width explicitly specified*/
border:1px solid black;
border-collapse:collapse;
}
.styledtable td, .styledtable th{
border:1px solid black;
padding:3px;
}
.styledtable th{ background:#cfcfcf; }
.styledtable td{ background:white; }
/* in a table with the first columnn empty (ie. with actions in the column below it),
* make the first column take up space, but not actually appear.
* Usage: <th style="width:40%;" class="firstcol"> </th>
*/
.firstcol{
visibility:hidden;
}
/*every second row different color, if the table itself doesn't have the class "no-odd-row-highlight"*/
.styledtable:not(.no-odd-row-highlight) tr:nth-child(odd) td{ background:#eeeeee; }
This works for me in all major browsers:
<style type="text/css">
table {
border: none;
padding: 0;
border-spacing: 0;
border-collapse: collapse;
}
table th,
table td {
margin: 0;
background: #fff;
border: 1px solid #000;
padding: 0;
}
table th.hidden {
border: none;
visibility: hidden;
}
</style>
<table>
<tr>
<th class="hidden"></th>
<th>ID</th>
<th>Something</th>
</tr>
<tr>
<td>Options</td>
<td>1</td>
<td>---</td>
</tr>
</table>
Depends upon what you want to achieve in styling, but generally, setting relevant element's (color/background-color/border-(top n left)-color(in this case)) to 'transparent' usually works across browsers.
hope this helps someone.

Using CSS for solid color background across/between table cells

Consider the following code:
HTML:
<table>
<tr>
<td>Hello</td>
<td>Stack</td>
<td>Overflow</td>
</tr>
<tr>
<td>some</td>
<td>text</td>
<td>here</td>
</tr>
</table>
CSS:
table {
border-spacing: 40px 10px;
border-collapse: separate;
}
tr:first-child {
background-color: #aaa;
}
td {
padding: 5px;
}
I would like the background color on the first row to be between the cells also.
How could I do this ?
I'm sorry but according to this (the last paragraph of section 17.5.1), the background between the cells when you use "border-collapse: separate" is the background of the table element.
This is not possible when using border-spacing, but you could try using individual cell padding instead...
table {
border-collapse: separate;
}
tr:first-child td {
background-color: #aaa;
}
td {
padding: 10px 40px;
}
Live demo available here