CSS Nth-Child 3n hierarchy structure - html

With how my HTML is structure I am having hard time selecting 3n child. It doesn't seem even notice the 3n selector of class heroLetter, but if I use the 1n child selector the code notices the class, but it also selects every div. I am not sure how to call the 3n child selector with this structure of classes I have made.
Code:
.heroLetter {
float: left;
width: 48%;
margin-top: 150px;
text-align: center;
font-size: 600px;
color: #f5543a;
position: relative;
}
.windowWrapper .section .heroLetter:nth-child(3n) {
float: left;
width: 48%;
margin-top: 150px;
text-align: center;
font-size: 200px;
color: #f5543a;
position: relative;
}
<div class="wrapper">
<div id="section1" class="windowWrapper">
<div class="section group">
<h1 class="introH1">
<span class="Grand">GRAND</span>
<span class="Stand">STAND</span>
</h1>
<p class="introP">A new font.</p>
scroll down
</div>
</div>
<div id="section2" class="windowWrapper">
<div class="section group">
<div class="col span_6_of_12">
<h1>STORY</h1>
<p>Grandstand invokes</p>
</div>
<div class="heroLetter">
G
</div>
</div>
</div>
<div id="section3" class="windowWrapper">
<div class="section group">
<div class="col span_6_of_12">
<h1>PROCESS</h1>
<p>Grandstand invokes</p>
</div>
<div class="heroLetter">
S
</div>
</div>
</div>
<div id="section4" class="windowWrapper form">
<div class="section group">
<div class="col span_6_of_12">
<h1>BEAM</h1>
<p>Grandstand invokes</p>
</div>
<div class="heroLetter">
<div class="circle"></div>
a
</div>
</div>
</div>
</div>
</div>

The nth-child refers to children of the same parent only.
You could adjust your code to refer to the outer most common element.
Some css like this should help you:
.windowWrapper:nth-child(4n) .section .heroLetter {}
In this case it's the 4th windowWrapper since it contains your 3rd heroLetter

Related

prevent div from collapsing when hiding or removing all child elements

I created a Vuetify app managing some card items. Before adding the actions / buttons I check the User's permissions. If some permissions are missing these buttons will not be rendered. I created an example here
https://codepen.io/anon/pen/RmMRQb?editors=1010
As you can see the second div collapses because no children is rendered. This problem is not related to Vuetify, so I will reproduce it with default HTML / CSS example.
.container {
background: red;
}
.box {
display: inline-block;
height: 32px;
width: 32px;
margin: 5px;
background: blue;
}
.notRendered {
display: none;
}
<div id="app">
<h1>Div with visible elements</h1>
<div class="container">
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
</div>
<h1>Div with hidden elements</h1>
<div class="container">
<div class="box notRendered">
</div>
<div class="box notRendered">
</div>
<div class="box notRendered">
</div>
</div>
</div>
I don't want the div to collapse. I already found a solution here
JQuery: Prevent div from collapsing when element hides()
but would like to ask if there is a way to achieve it without using some hardcoded heights or selecting the element's height. I don't want to modify Vuetify's native elements, so maybe there is a trick when the action bar is empty (no children got rendered) and the bar would not collapse.
I have added a secondary class for the default/native container. I think this is the best/easiest approach.
.improved-container {
background: red;
min-height: 40px;
}
.box {
display: inline-block;
height: 32px;
width: 32px;
margin: 5px;
background: blue;
}
.notRendered {
display: none;
}
<div id="app">
<h1>Div with visible elements</h1>
<div class="container improved-container">
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
</div>
<h1>Div with hidden elements</h1>
<div class="container improved-container">
<div class="box notRendered">
</div>
<div class="box notRendered">
</div>
<div class="box notRendered">
</div>
</div>
</div>

CSS target specific class

I am attempting to target a specific class which is the first class name inside a div. The attempt I have made looks like the following:
.container-fluid:first-child div.row {
padding-top: 200px;
}
The HTML for the CSS.
<div class="container-fluid">
<div class="row justify-content-md-center"> <<TRYING TO TARGET
<div class="col-3 text-center">
<div class="row">
<img src="/assets/images/fssLogo.png"/>
</div>
</div>
</div>
</div>
As you can see i want to target only the first row inside the container-fluid tag but the padding is also getting applied to the row inside the col-3 class.
Could somone point me in the right direction.
It should be
.container-fluid >.row:first-child {
padding-top: 200px;
}
.container-fluid > .row:first-child {
background-color: red;
padding-top: 200px;
}
.innerRow {
background-color: pink;
}
<div class="container-fluid">
<div class="row justify-content-md-center">
<div class="col-3 text-center">
<div class="row innerRow">
<img src="http://via.placeholder.com/350x150" />
</div>
</div>
</div>
</div>
Or
.container-fluid >.row {
padding-top: 200px;
}
.container-fluid > .row {
background-color: red;
padding-top: 200px;
}
.innerRow {
background-color: pink;
}
<div class="container-fluid">
<div class="row justify-content-md-center">
<div class="col-3 text-center">
<div class="row innerRow">
<img src="http://via.placeholder.com/350x150" />
</div>
</div>
</div>
</div>
But the 2nd snippet is more preferable, it is because you are targeting .row that is the direct child of container-fluid, unless you have another row that is also a direct child of container-fluid, you can use the 1st snippet to only target the first row child.
> is used to target the direct child of a parent, regardless if there is a class that has the same name lower in the hierarchy
.parent > .someClass {
color: blue;
}
<div class="parent">
<p class="someClass">TARGETED</p>
<div>
<p class="someClass">NOT TARGETED</p>
</div>
</div>
Remove > and both text will be blue

Overflow-y and position: absolute cause the offset when scroll bar is not at the top

Here is an example: https://jsfiddle.net/sunvom3a/
I have a list of items.
Basically a container with some text and a dropdown. The idea is when you hover over the text the dropdown should be directly below (kina like a tooltip).
.container {
overflow-y: scroll;
height: 100px;
border: solid 2px green;
}
.popup {
width: 100px;
height: 100px;
background-color: yellow;
position: absolute;
display: none;
}
.item:hover .popup {
display: block;
}
<div class="container">
<div class="item"><span> Text1</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text2</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text3</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text4</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text5</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text6</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text7</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text8</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text9</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text10</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text11</span>
<div class="popup"></div>
</div>
</div>
The first few elements that fit below the scrollbar of overflow-y (with my resolution these are first 5 items) work great:
but the rest are broken - when the scroll bar is moved this offset is added as a distance between the popup and the text:
Is there any way to get the consistent behavior for all items in the list?
This is exhibited in Chrome and Edge (Firefox works as expected). It is calculating the relative position based on the initial, out-of-view position.
You need to add this...
.item{
position: relative;
}
...to make the absolutely positioned element positioned relative to the hovered item.
Fiddle: https://jsfiddle.net/sunvom3a/1/
The downside to the above solution is that it moves the tooltip inside the container, making a portion of it likely to be out of view. On a side note, I'm not sure this is a great UI anyway since you are covering other options with your tooltip. I would recommend attaching it to the parent of your container (then you don't have to worry about the tooltip being out of view either.
Adding to your snippet...
body{
position: relative;
}
...will always put the tooltip in the top right corner of the body. This would be better done by adding a container for your scrolling container, but this is a mere example.
Fiddle: https://jsfiddle.net/sunvom3a/2/
just change position absolute to relative in popup class
jsfiddle: demo
.container {
overflow-y: scroll;
height: 100px;
border: solid 2px green;
}
.popup {
width: 100px;
height: 100px;
background-color: yellow;
position: relative;
display: none;
}
.item:hover .popup {
display: block;
}
<div class="container">
<div class="item"><span>Text1</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text2</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text3</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text4</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text5</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text6</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text7</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text8</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text9</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text10</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text11</span>
<div class="popup"></div>
</div>
</div>

div table column width doesn't match rows

Spending way too much time on (what should be) a simple div table. PROBLEM: the column headers will not resize to the width of the table, or the rows. The rows appear okay, but the column headers don't.
Trying to avoid having fixed widths as the next table I post may have a different number of columns. With the following code the column headers are all scrunched to the left, next to each other, but they don't match the rows...
<style type="text/css">
.table-container {
display: table;
width: 50%;
table-layout: fixed;
border-collapse: collapse;
}
.table-heading {
font-weight: bold;
display: table-caption;
background-color: #e9e9e9;
text-align: center;
padding: 8px;
line-height: 21px;
font-size: 18px;
color: #CA8327;
}
.table-row {
display: table-row;
text-align: center;
}
.table-row-shade {
display: table-row;
text-align: center;
background-color: #e9e9e9;
}
.table-col {
display: table-cell;
text-align: center;
border: 1px solid #ca8327;
}
</style>
<div class="table-container">
<div class="table-heading">Approximate Dimensions (inches)</div>
<div class="table-col">
<div class="table-col">size</div>
<div class="table-col">head strap (inc. frame)</div>
<div class="table-col">chin strap</div>
<div class="table-col">lbs.*</div>
</div>
<div class="table-row-shade">
<div class="table-col">XXS</div>
<div class="table-col">3-9 inches</div>
<div class="table-col">2-3 inches</div>
<div class="table-col">< 5 lbs*</div>
</div>
<div class="table-row">
<div class="table-col">XS</div>
<div class="table-col">5-13 inches</div>
<div class="table-col">3-7 inches</div>
<div class="table-col">5 - 10lbs*</div>
</div>
</div>
http://jsfiddle.net/Speedy1/t3e3ken6/
You only put table-col rather than table-row
<div class="table-container">
<div class="table-heading">Approximate Dimensions (inches)</div>
<div class="table-row"> <!-- must be a table-row -->
<div class="table-col">size</div>
<div class="table-col">head strap (inc. frame)</div>
<div class="table-col">chin strap</div>
<div class="table-col">lbs.*</div>
</div>
<div class="table-row-shade">
<div class="table-col">XXS</div>
<div class="table-col">3-9 inches</div>
<div class="table-col">2-3 inches</div>
<div class="table-col">< 5 lbs*</div>
</div>
<div class="table-row">
<div class="table-col">XS</div>
<div class="table-col">5-13 inches</div>
<div class="table-col">3-7 inches</div>
<div class="table-col">5 - 10lbs*</div>
</div>
</div>
http://jsfiddle.net/vgjb578s/
Try this http://jsfiddle.net/t3e3ken6/1/
It's because you have put the class "table-col" next to your heading. Change it to "table-row" and the problem is solved.
<div class="table-row">
<div class="table-col">size</div>
<div class="table-col">head strap (inc. frame)</div>
<div class="table-col">chin strap</div>
<div class="table-col">lbs.*</div>
</div>

CSS fluid layout: "stacked" div with different heights

I'm trying to figure out if it's possible to create a CSS layout where divs with float: left property would not create a new "row"-like layout but be really fluid.
To be more specific here's what I have now:
All blocks are div with float: left style, certain margins and unfixed height attribute. As you can see every high enough block forms a "line" or "row" with same height. What I'm trying to achieve is -- make all div element obey only their own margin style and not create a row with similar height.
So the question is if it's possible and if yes then how can it be achieved?
HTML (some blocks omitted):
<div id="blocks_wrapper">
<div class="strblock rouded_3px infobox">
<div class="dElement">
<div class="d_option">Web</div>
<div class="d_value"></div>
</div>
</div>
<div class="strblock rouded_3px infobox">
<div class="dElement">
<div class="d_option">Phone</div>
<div class="d_value"></div>
</div>
</div>
<div class="strblock rouded_3px infobox">
<div class="dElement">
<div class="d_option">Thu—Fri</div>
<div class="d_value">11:00—19:00</div>
</div>
</div>
<div class="strblock rouded_3px infobox">
<div class="dElement">
<div class="d_option">Pricing</div>
<div class="d_value">40 USD</div>
</div>
</div>
<div class="strblock rouded_3px infobox">
<div class="dElement">
<div class="d_option">Address</div>
<div class="d_value">0.2km from Historic U.S. 66, Seligman, AZ 86337, USA</div>
</div>
</div>
<div class="strblock rouded_3px infobox">
<div class="dElement">
<div class="d_option">Coordinates</div>
<div class="d_value">
35.52890, -113.23200<br>
N35°31'44", W113°13'55"
</div>
</div>
</div>
<div class="clear"></div>
</div>
CSS:
#blocks_wrapper .strblock { float: left; margin-bottom: 3px; overflow: hidden; }
#blocks_wrapper .infobox { width: 19%; padding: 3px; }
#blocks_wrapper .infobox .dElement .d_option { display: inline-block; width: 90px; overflow: hidden; font-weight: bold; }
#blocks_wrapper .infobox .dElement .d_value { display: inline-block; width: 155px; vertical-align: top; }
I know it's late, but maybe this will help someone.
http://masonry.desandro.com