I want to make the border of my error select box outside div.wwctrl color red. The problem is it doesn't changed it color using advance css selector. I want to use css and not javascript to implement this. Is this possible? Thank you.
<div class="wwctrl">
<select id="error" name="summaryData.type"></select>
</div>
.wwctrl {
position: relative;
border: 1px solid blue;
}
select {
border: 1px solid pink;
}
select#error + div {
position: absolute;
z-index: -1;
top: 0; left: 0;
width: 100%; height: 100%;
background: yellow;
}
SAMPE CODE - JFIDDLE
Sure you can do so with CSS.
Most important: IDs (#) are only allowed to be used on one element in the whole document, so if you want to apply an identifier to several elements, you have to use a class (.)!
You just declare the border for the selectbox outside wwctrl.
select.error{
border:1px solid red;
}
Now you override this selector with a more specific selector for the error boxes inside wwctrl:
.wwctrl select.error{
border-color:pink;
}
Because the rule is more specific, it overrides the previous rule.
<div class="wwctrl">
<!-- has a pink border -->
<select class="error" disabled="disabled"><!--...options...--></select>
<select><!--...options...--></select>
</div>
<!-- outside wwctrl - has a red border -->
<select class="error" disabled="disabled"><!--...options...--></select>
Your modified example
Related
I'm trying to get a second sibling element displaying in front of the first - with some severe restrictions:
I cannot alter the HTML or use javascript or jQuery.
I can only use CSS.
I can't change how classes are assigned (again, I don't have access to change any code apart from the one bespoke CSS file).
The left-hand menu features a number of the above HTML structures, building a clickable menu for the sections on the page. When a page section is completed, the 'completed-section' class is added to the first span (as shown above). This is what is causing me problems:
The CSS styling of the nav-link 'button' should change when it's completed, but since I can't access the parent of a CSS-selected element I need to make these changes directly to the 'menu-number' span element, including a 'nav-link' sized background colour. So I've made the menu-number the same size as the containing 'nav-link' . But when I add a background colour to the 'menu-number' , the text in the second is obscured.
How can I 'move' the second span in front of the first so I can see its text?
I have also tried making both spans position absolute or position relative and used z-index but this pulls the spans out of the flow of the document and means the width of the menu collapses. I can't set the width to a hard-coded value because the menu toggles open and closed, width-wise, (without a class being set) and the toggled width is set by javascript which, again, I can't access.
I have also tried using display: flex on the 'a' element and reversing the 'order' of span elements. No luck.
In semi-desperation I have tried setting the direction property on 'nav-link' to rtl. No luck.
I think I've tried a couple other things too, but at this point I'll wrap this question up.
Any pointers, much appreciated...
.menu-number {
border: none;
border-left: 10px solid transparent;
border-radius: 0px;
padding-top: 13px;
padding-left: 20px;
height: 45px;
position: absolute;
width: 100%;
text-align: left;
z-index: 100;
float: left;
}
.menu-number + span {
/*position: absolute;*/
padding-left: 40px;
z-index: 200;
}
.completed-section {
color: #42bb76 !important;
border-left: 10px solid #42bb76;
background-color: #274d56;
text-decoration: underline;
}
.nav-link > div > a {
display: flex;
*/flex-direction: row-reverse;*/
}
.nav-link > div > a > span:nth-of-type(1) {
order: 2;
}
.nav-link > div > a > span:nth-of-type(2) {
order: 1;
}
.nav-link > div > a > .section-name {
color: white;
padding: 13px 20px 0px 60px;
height: 45px;
float: left;
}
<div class="nav-link">
<div>
<a href="scroll/to/section">
<span class="menu-number completed-section">1.</span>
<span class="section-name">Section name</span>
</a>
</div>
</div>
I've also tried 'flex-direction' but I've now commented that out.
You can achieve this using CSS order property:
Here is the fiddle:
.menu-number {
order: 2;
}
.section-name {
order: 1;
}
.nav-link a{
display: flex;
}
<div class="nav-link">
<div>
<a href="scroll/to/section">
<span class="menu-number completed-section">1.</span>
<span class="section-name">Section name</span>
</a>
</div>
</div>
The actual version of the Ionic progress bar comes without an option to display the percentage text.
I tried to add it manually using the ::after selector but to no avail.
This is my Ionic code:
ion-progress-bar {
height: 18px;
border-radius: 20px;
}
<ion-progress-bar color="success" value="0.9"></ion-progress-bar>
While inspecting the element this is what I get in chrome's elements inspector
.progress, .progress-indeterminate {
background: var(--progress-background);
z-index: 2;
}
.buffer-circles, .indeterminate-bar-primary, .indeterminate-bar-secondary, .progress, .progress-buffer-bar, .progress-buffer-bar:before, .progress-indeterminate {
left: 0;
right: 0;
top: 0;
bottom: 0;
position: absolute;
width: 100%;
height: 100%;
}
<ion-progress-bar _ngcontent-c0="" color="success" value="0.9" ng-reflect-value="0.9" ng-reflect-color="success" role="progressbar" aria-valuenow="0.9" aria-valuemin="0" aria-valuemax="1" class="ion-color ion-color-success progress-bar-determinate hydrated">
#shadow-root
<!-- ....... -->
<div class="progress" style="transform: scaleX(0.9);"></div>
<div class="progress-buffer-bar" style="transform: scaleX(1);"></div>
</ion-progress-bar>
The only way with which I can add a text from the elements inspector to the progress bar, is to add it inside the div with the progress class:
<div class="progress" style="transform: scaleX(0.9);">90%</div>
But adding this text from my Ionic code isn't possible, so I tried to use the ::after selector but It did not work:
.progress:after{
content: "90%";
}
I don't need that the text changes dynamically since the progress-bar must display a static value that does not change.
Thanks!
I think what I was trying to achieve is impossible since it is a direct manipulation of the shadow dom.
Based on this article, There are some key points concerning shadow dom:
You cannot style any of the internal elements of a web component from outside of the web component using CSS selectors
You can style the internal elements of a web component if CSS4 variables are being used, as you can change the values of the CSS4 variables.
You can style slotted content inside of a web component (i.e. content you have supplied to the web component) from outside of the web component
You can style the host element of the web component (i.e. the element you use to add the web component to a page) from outside of the web component
Since there is no css4 variable or property that allows us to add a text value to the progress-bar, I had no choice but to use a custom html progress bar:
.progress-outer {
width: 96%;
margin: 10px 2%;
padding: 3px;
text-align: center;
background-color: #f4f4f4;
border: 1px solid #dcdcdc;
color: #fff;
border-radius: 20px;
}
.progress-inner {
min-width: 15%;
width: 90%;
white-space: nowrap;
overflow: hidden;
padding: 5px;
border-radius: 20px;
background-color: var(--ion-color-primary);
}
<div class="progress-outer">
<div class="progress-inner">90%</div>
</div>
The appearance of the progress-bar can be then customized by changing the css properties
simply you can put
ion-progress-bar {height:15px;}
in global.scss ..
if you also want to make the border radius then you can add the radius inside as well , as
ion-progress-bar {height:15px;border-radius:15px;}
I tried to make work my library and I found that "background-color" CSS property not work when it used by jQueryUI. On the other hand if I simple use the "background" property with color value.
I make examples on jsfiddle:
- Working example
- Not working example
However is I simply make a class and apply to a div element in the html markup it works well.
Code:
HTML markup. Same in both cases:
<div id="selectable">
<div class="ui-widget-content">1</div>
<div class="ui-widget-content">2</div>
<div class="ui-widget-content">3</div>
</div>
Javascript. Also same in both case:
$(document).ready(function(){
$("#selectable").selectable();
});
CSS working scenario:
.ui-selected
{
background: rgb(255,0,0);
border: 1px solid yellow;
width: 100px;
height: 30px;
}
CSS non-working scenario:
.ui-selected
{
background-color: rgb(255,0,0);
border: 1px solid yellow;
width: 100px;
height: 30px;
}
LIVE DEMO
hi Peter, try putting the id in front of css, then it works.
#selectable .ui-selected { background: rgb(255,0,0); color: white; }
I have two HTML samples... Basically there is always a name div in the info div but the total number of could be more.
1)
<div class="person">
<div class="info">
<div class="name">Isabelle of_Bavaria</div>
</div>
</div>
2)
<div class="person">
<div class="info">
<div class="name">King of France Charles_V the_Wise</div>
<div class="title"><label>Title:</label>King of France</div>
<div class="date"><label>Birth:</label>Jan 21st, 1337</div>
<div class="date"><label>Death:</label>Sep 16th, 1380</div>
</div>
</div>
I'm using this bit of CSS to add a line under the name as well as a box around the person div.
.person .name
{
position: relative;
text-align: center;
border-bottom: 1px dotted black;
}
.person
{
position: relative;
width: 250px;
height: auto;
border: 1px solid black;
margin-top: 5px;
padding: 5px;
}
Is there anything I can do with the css to prevent the name from having a border in sample 1 while leaving it in sample 2 without the need for additional classes or divs?
Try adding this piece of CSS at the top of your .person .name entry
.person .name:only-of-type
{
border-bottom: 0px transparent;
}
This piece of CSS means that if there is only one of the element type using the .name class in .person (in this example it's a div), it will not have a bottom border. You have to put it before the .person .name in order to overwrite it.
EDIT :
After thinking about it a bit more, i think the pseudo class :only-child would be better suited for your needs instead of :only-of-type since it will only apply if the .name is the only child of .person. So here's the updated CSS
.person .name:only-child
{
border-bottom: 0px transparent;
}
Something logically like this?
.person > .info[having more than one div child] > .name
{
border-bottom: ...
}
sadly, i don't think there's a [...] selector quite like that, however, there are "adjacent sibling selectors" ( http://www.w3.org/TR/CSS2/selector.html#adjacent-selectors )
Maybe as #PhilPerry has suggested, you could change the concept to being "put a top-border on the div immediately following the first-child (or name)", like so:
.name:first-child + div
{
border-top: ...
}
i am not able to find the reason why this popup won't work.
He recognizes the hover above the table, but it has no effect on the popup.
The weird thing is, when i include the path to the table to the .popup class he won't do anything, not even modify the span itself. I assume it has something to do with the selectors, but the path works without span.popup. I don't get the problem because space means descendant, but it kills somehow the whole selection.
<div id="center">
<tr id="name">
<td class="description">Name</td>
<td>Hulu</td>
<span class="popup">
This should be the text in the popup.
</span>
</tr>
</div>
----------css
div#center tr.name:hover {
background-color: white;
}
div#center tr#name span.popup {
display: none;
}
div#center tr#name:hover span.popup {
display: block;
background: white;
border-style: solid;
border-width: 1px;
border-radius: 15px;
position: absolute;
top: 45%;
left: 550px;
padding: 20px;
width: 450px;
}
I would be glad for some answers.
tonlap
You cannot have tr tags without a table tag. Moreover, you cannot have extraneous tags outside of the td tags within a tr for them to be valid. These are not being recognized. If you put table tags around the table row and the span inside a td, then it will work more or less as you intend. Instead of using the table row in such a way, any reason to not use two divs?