How to hide first pseudo css element - css

Is it possible to hide the first pseudo element?
<div id="builder-widgets_rule_0" class="ruleTemplate rule-container">
<div class="custom-condition">AND</div>
</div>
<div id="builder-widgets_rule_1" class="ruleTemplate rule-container">
<div class="custom-condition">AND</div>
</div>
<div id="builder-widgets_rule_2" class="ruleTemplate rule-container">
<div class="custom-condition">AND</div>
</div>
this html element has a pseudo styling like this:
.custom-condition::before {
content: '';
position: absolute;
width: 1px;
height: auto;
min-height: 25px;
border: 2px solid #f1f1f1;
top: -25px;
left: 50%;
margin-left: -2px;
}
It is not possible to do something like this?
.custom-condition:first-child::before {
content: '';
}
Also tried to added a span element to avoid the psuedo element like this:
<div id="builder-widgets_rule_0" class="ruleTemplate rule-container">
<div class="custom-condition">AND</div>
<div class="smallLine"></div>
</div>
<div id="builder-widgets_rule_1" class="ruleTemplate rule-container">
<div class="custom-condition">AND</div>
<div class="smallLine"></div>
</div>
<div id="builder-widgets_rule_2" class="ruleTemplate rule-container">
<div class="custom-condition">AND</div>
<div class="smallLine"></div>
</div>
Just copied the psuedo styling to the .smallLine

If all the elements are inside the same wrapper you can do this. Instead of removing the pseudo-element from the first simply define it for all the other but not the first.
.custom-condition ~ .custom-condition::before {
content: '[Before]';
}
<div>
<div> OR </div>
<div class="custom-condition"> AND </div>
<div class="custom-condition"> AND </div>
<div> OR </div>
<div class="custom-condition"> AND </div>
</div>
UDPATE
You can consider the parent element with your current HTML structure
.rule-container ~ .rule-container .custom-condition::before {
content: '[Before]';
}
<div id="builder-widgets_rule_0" class="ruleTemplate rule-container">
<div class="custom-condition">AND</div>
</div>
<div id="builder-widgets_rule_1" class="ruleTemplate rule-container">
<div class="custom-condition">AND</div>
</div>
<div id="builder-widgets_rule_2" class="ruleTemplate rule-container">
<div class="custom-condition">AND</div>
</div>

Related

moving last row to bottom of container in bootstrap 4

I have a simple footer with contact information that contains of three rows. The first two appear at the top, the last one should be placed on the very bottom of the container.
So what I did was using an absolute positioning:
footer .verybottom {
position: absolute;
bottom: 0px;
background-color: grey;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<footer id="kontakt">
<div class="container">
<div class="row">
<div class="col md-12">
<h2>Contact</h2>
</div>
</div>
<div class="row">
<div class="col-md-6">
Adress
</div>
<div class="col-md-6">
something else
</div>
</div>
<div class="row verybottom">
<div class="col-md-6">
some more Text
</div>
<div class="col-md-6">
some more Text
</div>
</div>
</div>
</footer>
The positioning works fine, but whatever I do - the last row is only a wide as the col above it. can someone help me align the content with the rows above?
You need to put a container inside to get it to work... and then introduce another .row since we want the col-md-XX classes to work
working snippet:
footer .verybottom {
position: absolute;
bottom: 0px;
background-color: grey;
padding-left: -15px;
}
.row {
border: 1px dotted red;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<footer id="kontakt">
<div class="container">
<div class="row">
<div class="col md-12">
<h2>Contact</h2>
</div>
</div>
<div class="row">
<div class="col-md-6">
Adress
</div>
<div class="col-md-6">
something else
</div>
</div>
<div class="row">
<div class="container verybottom">
<div class="row">
<div class="col-md-6">
some more Text
</div>
<div class="col-md-6">
some more Text
</div>
</div>
</div>
</div>
</div>
</footer>

CSS selector: only select child if there is more than one child

it is actually quite simple:
If I have several children, I want .child to have margin-bottom: 10px;
if there is only one child, I don't want to have that margin
obviously:
Just adding another class to the container is not an option. CSS solution only
<div class="container">
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
so first container's child should have no margin. The other examples should have a margin between each child
You can make use of the :first-of-type pseudo-class in conjunction with the :not negation pseudo-class, and set margin-top instead. This will only give the margin-top to child elements which have a preceding element, thus giving the separation effect you're looking for:
.container {
border: 1px solid black;
}
.child:not(:first-of-type) {
margin-top: 10px;
}
<div class="container">
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
You can add a margin to each element after a previous one, so we only have margin-top if there is an element before.
.container {
border:2px solid;
margin:20px;
}
.child {
height:20px;
background:red;
}
.child + .child {
margin-top:10px;
}
<div class="container">
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
Or remove the margin-bottom from the last element so when having only one element it will also be the last element:
.container {
border:2px solid;
margin:20px;
}
.child {
height:20px;
margin-bottom:10px;
background:red;
}
.child:last-child {
margin-bottom:0;
}
/* OR
.child:not(:last-child) {
margin-bottom:10px;
}
*/
<div class="container">
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>

Selecting 2nd li of second occurrence of a class

I have
<ul class="biglist">
on many places of a page... in which i want to select only the second
<ul class="biglist">
and in that again select second li and add color to it...
i currently have it like follows
.biglist li:nth-child(2) {
color:#ff0000;
}
which i try to add...
.biglist:nth-child(2) li:nth-child(2)
it does not selects the second list's second item. Tried in internet search and could not able to get suitable solution. can someone help pls ?
Here is my complete code...
<div class="vc_col-sm-4 wpb_column column_container ">
<div class="wpb_wrapper">
<div class="dt-fancy-separator title-left accent-border-color" style="width: 100%;">
<div class="dt-fancy-title bg-on" style="color: #ffffff;">
<span class="separator-holder separator-left"></span>List of Places:
<span class="separator-holder separator-right"></span>
</div>
</div>
<div class="gap" style="line-height: 10px; height: 10px;"></div>
<section class="shortcode-teaser frame-fancy frame-on rotateInDownLeft animate-element">
<div class="shortcode-teaser-content text-big">
<ul class="biglist">
<li><p>New York</p></li>
<li><p>Ontario</p></li>
<li><p>London</p></li>
</ul>
</div>
</section>
<div class="gap" style="line-height: 30px; height: 30px;"></div>
</div>
</div>
<div class="vc_col-sm-4 wpb_column column_container ">
<div class="wpb_wrapper">
<div class="dt-fancy-separator title-left accent-border-color" style="width: 100%;">
<div class="dt-fancy-title bg-on" style="color: #ffffff;">
<span class="separator-holder separator-left"></span>List of Old Places:
<span class="separator-holder separator-right"></span>
</div>
</div>
<div class="gap" style="line-height: 10px; height: 10px;"></div>
<section class="shortcode-teaser frame-fancy frame-on rotateInDownLeft animate-element">
<div class="shortcode-teaser-content text-big">
<ul class="biglist">
<li><p>Mumbai</p></li>
<li><p>Tokyo</p></li>
<li><p>Bali</p></li>
</ul>
</div>
</section>
<div class="gap" style="line-height: 30px; height: 30px;"></div>
</div>
</div>
<div class="vc_col-sm-4 wpb_column column_container ">
<div class="wpb_wrapper">
<div class="dt-fancy-separator title-left accent-border-color" style="width: 100%;">
<div class="dt-fancy-title bg-on" style="color: #ffffff;">
<span class="separator-holder separator-left"></span>List of New Ones:
<span class="separator-holder separator-right"></span>
</div>
</div>
<div class="gap" style="line-height: 10px; height: 10px;"></div>
<section class="shortcode-teaser frame-fancy frame-on rotateInDownLeft animate-element">
<div class="shortcode-teaser-content text-big">
<ul class="biglist">
<li><p>Paris</p></li>
<li><p>Cairo</p></li>
<li><p>Delhi</p></li>
</ul>
</div>
</section>
<div class="gap" style="line-height: 30px; height: 30px;"></div>
</div>
</div>
My understanding is this is not possible in CSS using nth-child or nth-of-type.
The class check is done after the nth element check, so if there are other ul elements between those of class biglist, you have no guarantee of selecting the ul you are looking for.
You need a JavaScript based solution.
For example, using Jquery:
uls = $("ul");
var bigListCount = 0;
for(i = 0; i < uls.length; i++)
{
if($(uls[i]).hasClass("biglist")) bigListCount++;
if(bigListCount == 2){
$(uls[i]).css("color", "#ff0000");
}
}
You can try using :nth-of-type(N):
ul.biglist li:nth-of-type(2) { background-color: #ff0000; }
nth-of-type checks the occurrence of an item in its direct parent. In the case of your HTML, inside a div there is only one ul. So what you have to do is first select one of the top level elements (the column_container) and then set its ul's second li to red. Here you can see a working codepen example using your HTML.
https://codepen.io/tskjetne/pen/gWLKKr
For clarification, what I do is set the 2nd column_container's ul's 2nd li to color red.
Given the knowledge now that you have elements in between the ULs, css only will not work. Here's a jQuery solution:
if (($uls = $("ul.biglist")).length > 1){
$uls[1].find("li:nth-child(2)").css({ color: "#ff0000" })
}

Why do browser prefixes for text-align have different behaviour and which is correct?

I want to vertically centre <div> tags that have a horizontal margin between each other.
The problem is that this behavior appears to be inconsistent between text-align: center and text-align: -webkit-center or text-align: -moz-center:
.parent {
display: inline-block;
border: 1px dotted #fd0;
position: relative;
}
.parent.ta {
text-align: center;
}
.parent.browser-ta {
text-align: -webkit-center;
text-align: -moz-center;
}
.child {
display: inline-block;
vertical-align: top;
}
.child > .content {
display: block;
margin: 0 10px;
border: 1px solid #888;
width: 200px;
text-align: left;
}
.wrong {
background-color: #e00;
color: #fff;
}
.right {
background-color: #0a3;
color: #fff;
}
<div>
Using <tt>text-align: center</tt>;
<div class="parent ta">
<div class="child">
<div class="content wrong">child 1 LEFT</div>
<div class="parent ta">
<div class="child">
<div class="content">child a</div>
</div>
<div class="child">
<div class="content">child b</div>
</div>
<div class="child">
<div class="content">child c</div>
</div>
</div>
</div>
<div class="child">
<div class="content wrong">child 2 LEFT</div>
<div class="parent ta">
<div class="child">
<div class="content">child d</div>
</div>
<div class="child">
<div class="content">child e</div>
</div>
<div class="child">
<div class="content">child f</div>
</div>
</div>
</div>
<div class="child ">
<div class="content right">child 3 CENTRE</div>
</div>
</div>
</div>
<br>
<br>
<div>
Using <tt>text-align: -vendor-center</tt>
<div class="parent browser-ta">
<div class="child">
<div class="content right">child 1 CENTRE</div>
<div class="parent browser-ta">
<div class="child">
<div class="content">child a</div>
</div>
<div class="child">
<div class="content">child b</div>
</div>
<div class="child">
<div class="content">child c</div>
</div>
</div>
</div>
<div class="child">
<div class="content right">child 2 CENTRE</div>
<div class="parent browser-ta">
<div class="child">
<div class="content">child d</div>
</div>
<div class="child">
<div class="content">child e</div>
</div>
<div class="child">
<div class="content">child f</div>
</div>
</div>
</div>
<div class="child">
<div class="content right">child 3 CENTRE</div>
</div>
</div>
Run that snippet and the two similar HTML and CSS produce different layouts in Chrome (Webkit/Blink) and FireFox. The red panels are in the wrong location, the green ones are correct.
So text-align: -webkit-center and text-align: -moz-center appear to be correct (to me) but text-align: center appears to be bugged in both browsers.
Digging out the venerable old <centre> tag (that we're not supposed to use) and that works right too (though examining it reveals it uses the browser prefix too).
Is this correct? Is this a bug? Is there a reason for the difference? Which one should I use?
The prefixed values are described by MDN to be "block alignment values", which means block boxes themselves are aligned in addition to the inline content within them. This is the exact behavior of the <center> element, and the prefixed values are in fact intended for that element — if you look in the UA stylesheets for each engine you'll find a ruleset that says exactly center { display: block; text-align: -vendor-center; }.
The reason text-align: center is not implemented this way is because text-align is designed to affect inline-level boxes (as evidenced by the "text-" in its name), not block-level boxes. But that, I suspect, is not the answer you're really looking for.
What's happening is that the boxes that are actually being aligned in your snippet are the .content elements, which are block boxes, not inline-blocks. The reason that last element is being centred is because its parent, an inline-block, is being shrink-wrapped, and itself then centred by the text-align: center declaration in its ancestor.

Center Div scroll

In my code,
Within one container Three blocks will be there. one freezes on the left and one freezes on the right and the other will scroll in between these two divs. Just like modern grids. But I don't want to use the grid.
I have tried, but the center block is not getting the Horizontal scroll.
I want no breakage of the center block, instead, it should scroll horizontally.
* {
box-sizing: border-box;
}
.container {
width: 100%;
overflow: auto;
white-space: nowrap
}
.scroll-center {
width: auto;
overflow: auto;
display: block;
white-space: nowrap
}
.row {
float: left;
}
.cell {
padding: 3px;
border: 1px solid #bbb;
min-height: 25px;
min-width: 200px;
}
<div class="container">
<div class="row">
<div class="cell">HeaderL1</div>
<div class="cell">HeaderL2</div>
<div class="cell">HeaderL3</div>
</div>
<div class="scroll-center">
<div class="row">
<div class="cell">HeaderT2</div>
<div class="cell">Data21</div>
<div class="cell">Data22</div>
</div>
<div class="row">
<div class="cell">HeaderT3</div>
<div class="cell">Data31</div>
<div class="cell">Data32</div>
</div>
<div class="row">
<div class="cell">HeaderT4</div>
<div class="cell">Data41</div>
<div class="cell">Data42</div>
</div>
<div class="row">
<div class="cell">HeaderT5</div>
<div class="cell">Data51</div>
<div class="cell">Data52</div>
</div>
<div class="row">
<div class="cell">HeaderT6</div>
<div class="cell">Data61</div>
<div class="cell">Data62</div>
</div>
<div class="row">
<div class="cell">HeaderT7</div>
<div class="cell">Data71</div>
<div class="cell">Data72</div>
</div>
<div class="row">
<div class="cell">HeaderT8</div>
<div class="cell">Data81</div>
<div class="cell">Data82</div>
</div>
<div class="row">
<div class="cell">HeaderT9</div>
<div class="cell">Data91</div>
<div class="cell">Data92</div>
</div>
</div>
<div class="right">
<div class="row">
<div class="cell">HeaderTR</div>
<div class="cell">DataR1</div>
<div class="cell">DataR2</div>
</div>
</div>
</div>
You probably need to add width to your container. Right now it's set to 100% so it will not size beyond the browser window. Instead you could do something like this:
.container {
overflow: auto;
white-space: nowrap;
width:2000px;
}
I realize that you may need to change this value dynamically but hopefully this gets you started
Example:http://codepen.io/nilestanner/pen/jAjbdK
Try with For example:
css:
* {
box-sizing: border-box;
}
.left, .center, .right{
float:left
}
.center {
width:400px;
overflow: scroll;
display: block;
white-space: nowrap
}
#center-scroll{
width:2000px;
}
.center .row{
display:inline-block;
width:33%;
}
.center .row .cell{
min-width:100%;
}
.row{
float:left;
}
.cell {
padding: 3px;
border: 1px solid #bbb;
min-height: 25px;
min-width: 200px;
}
HTML
<div class="container">
<div class="left">
<div class="row" >
<div class="cell">HeaderL1</div>
<div class="cell">HeaderL2</div>
<div class="cell">HeaderL3</div>
</div>
</div>
<div class="center">
<div id="center-scroll">
<div class="row">
<div class="cell">HeaderT2</div>
<div class="cell">Data21</div>
<div class="cell">Data22</div>
</div>
<div class="row">
<div class="cell">HeaderT3</div>
<div class="cell">Data31</div>
<div class="cell">Data32</div>
</div>
<div class="row">
<div class="cell">HeaderT4</div>
<div class="cell">Data41</div>
<div class="cell">Data42</div>
</div>
<div class="row">
<div class="cell">HeaderT5</div>
<div class="cell">Data51</div>
<div class="cell">Data52</div>
</div>
<div class="row">
<div class="cell">HeaderT6</div>
<div class="cell">Data61</div>
<div class="cell">Data62</div>
</div>
<div class="row">
<div class="cell">HeaderT7</div>
<div class="cell">Data71</div>
<div class="cell">Data72</div>
</div>
<div class="row">
<div class="cell">HeaderT8</div>
<div class="cell">Data81</div>
<div class="cell">Data82</div>
</div>
<div class="row">
<div class="cell">HeaderT9</div>
<div class="cell">Data91</div>
<div class="cell">Data92</div>
</div>
</div>
</div>
<div class="right">
<div class="row">
<div class="cell">HeaderTR</div>
<div class="cell">DataR1</div>
<div class="cell">DataR2</div>
</div>
</div>
</div>

Resources