How to select a specific child by className in Tailwind?
I have tried some selectors but it seems nothing is matching, is it even possible?
<div className="[CHILD_CLASSNAME]:bg-red [NESTED_CHILD_CLASSNAME]:bg-blue">
<div className="CHILD_CLASSNAME">
text in red
<div className="NESTED_CHILD_CLASSNAME">text in blue</div>
</div>
<div>
note: I can't style directly child component with CHILD_CLASSNAME
Arbitrary variants should contain & sign - it points on current element with this variant class
<div class="[&_.CHILD-CLASSNAME]:bg-red-500 [&_.NESTED-CHILD-CLASSNAME]:bg-blue-500">
<div class="CHILD-CLASSNAME">
text in red
<div class="NESTED-CHILD-CLASSNAME">text in blue</div>
</div>
<div>
&_.CHILD-CLASSNAME simply will point on every element within as in regular CSS. You can use any CSS selector
Please note: if your class contains _ in the class name, it should be escaped with \ - otherwise Tailwind will consider it as a space
<div class="[&_.CHILD_CLASSNAME]:bg-red-500 [&_.NESTED-CHILD-CLASSNAME]:bg-blue-500">
<div class="CHILD_CLASSNAME">
text in red (not working because of "_")
<div class="NESTED-CHILD-CLASSNAME">text in blue</div>
</div>
<div>
<div class="[&_.CHILD\_CLASSNAME]:bg-red-500 [&_.NESTED-CHILD-CLASSNAME]:bg-blue-500">
<div class="CHILD_CLASSNAME">
text in red
<div class="NESTED-CHILD-CLASSNAME">text in blue</div>
</div>
<div>
DEMO
Related
<div id='test' /><div>
In the above example, I need to find div under below scenario:
WebElement
divelement = driver.FindElement(By.css("#test"));
Now I want to find the div tag with no attribute using the divelement variable.
How to navigate to div descendant using divelement?
There are a couple ways you can do this.
By using a CSS Selector:
driver.findElement(By.cssSelector("#test div"))
// ^ note the space. this is CSS for "descendant".
I'm confused by the phrasing of
find the div tag with no attribute using the divelement variable.
but if you mean a <div> element with no specific attributes, then you can use the :not() pseudo-selector.
driver.findElement(By.cssSelector("#test div:not([id])")
// will find all <div>s that are descendants of #test that do not have an id attribute.
The other way, is to just use chained findElement's like so:
driver.findElement(By.cssSelector("#test")).findElements("div")
divelement.findElement(By.css("div"));
That should be the way to go. That was listed in the comment above from #Sudharsan Selvaraj
If you know the use of double slash // in Xpath and looking for its counterpart in CSS, then you need to use space.
For example: You want CSS for grey line then it will be .image .row.width-for-gray-line
<div class="image parbase wq-GridColumn wq-GridColumn--default--12">
<div class="component">
<div class="row bottom-buffer">
<div class="col-sm-12">
<a href="https://msn.com" target="_blank">
<picture>
<img src="/image/path/cover.jpg"
class="image-max-width-responsive" alt="test_alt_text">
</picture>
</a>
<p class="light-txt">test_caption</p>
</div>
</div>
<div class="row width-for-gray-line">
<hr class="bottom-buffer-gray-line">
</div>
</div>
</div>
I have the following HTML code:
<div class="t2-selector">
<div>
<div class="inactive">USA</div>
<div class="inactive">Google</div>
<div class="inactive">Microsoft</div>
<div class="inactive">Apple</div>
</div>
<div>
<div class="">Europe</div>
<div class="selected">BT</div>
</div>
<div>
<div class="">Indices</div>
<div>Vodafone</div>
<div>Renault</div>
</div>
<div>
<div class="">Currencies</div>
<div>EUR/USD</div>
<div>GBP/USD</div>
<div>USD/JPY</div>
<div>USD/CHF</div>
<div>AUD/USD</div>
<div>USD/CAD</div>
</div>
I can select a group by Xpath xpath = "//div[contains(text(),'Currencies')]"
What I need is to select a child in Currencies list by it's number.
I need something like CSS div:nth-child(2) but I can't use CSS here since CSS doesn't really support selecting an element by text.
So is there nth-child analog for Xpath?
You can use
//div[contains(text(),'Currencies')]/following-sibling::div[1]
Please note that the index starts from 1 not 0.
Check the following link : http://www.w3schools.com/xsl/xpath_axes.asp
I have this:
<div class="block3">
<div class="surround">
<div class="s_title">
<h3>Title</h3>
</div>
<div class="block_content">
<div class="content"> </div>
</div>
</div>
</div>
In my example I can't add content directly in HTML (blocks rendered by default in PHP), so I need to add in CSS.
The hard part of this is that I need to add text only in block3 element, after <h3> (.s_title:after will affect all s_title, so it will not work for me.)
Is there any way to do this?
Just add .block3 in front of your selector like how you would limit selection of any other element to some container element:
.block3 .s_title:after
I'm trying to select the div that has "Trying to access this element"
<div id="main" class="wrapper clearfix 3-column">
<div id="col1" class="floatleft">
<div><img src="img/main.jpg" /></div>
<div class="col1-grid2">
Trying to access this element
</div>
</div>
</div>
Doing .col1-grid2 or #main .col1-grid2 works as expected. However, why would doing .3-column .col1-grid2 not target the element?
The problem is not the selector, it's the name of the class. 3-column is not a valid class name. It must start with a -, _ or a letter (a-z or A-Z). EDIT: updated to say not just lower case letters
For some reason div elements change their parents during rendering in unexpected way, reproducible in Firefox and Chrome.
E.g.
<div class="main">
<div class="slot"/>
<div class="slot"/>
</div>
<div class="footer"></div>
Firefox debugger will show as this at runtime as:
<div class="main">
<div class="slot"><div class="slot"/></div></div>
<div class="footer"></div>
</div>
When I remove .slot elements(see the code attached), everything renders as expected(#footer place in tree after rendering is same as in the source).
Code:
http://pastebin.com/3j3aQFdh
The problem is that you use empty divs: like that
<div />
You should try to change your code to use valid divs with empty content:
<div></div>