Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Link Element Not Displaying When Selected And Styled As nth-of-type

https://codesandbox.io/s/damp-worker-k7fj6y?file=/src/App.js

Why is the .row:nth-of-type(1) > .content:nth-of-type(4) .content <Link/> not displaying?

Is it a bug, am I just missing something?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import "./styles.css";
import { Link } from "react-router-dom";

export default function App() {
  return (
    <div className="App">
      <div className="row">
        {/* I dont want this div to be a Link */}
        <div className="content"></div>
        <Link to="/" className="content"></Link>
        <Link to="/" className="content"></Link>
        <Link to="/" className="content"></Link>
      </div>
      <div className="row">
        <Link to="/" className="content"></Link>
        <Link to="/" className="content"></Link>
        <Link to="/" className="content"></Link>
        <Link to="/" className="content"></Link>
      </div>
    </div>
  );
}
.App {
  height: 100vh;
  width: 100vw;
}

.row:nth-of-type(1) {
  height: 500px;
  width: 100%;
  display: grid;
  grid-template-areas:
    "a a b c"
    "a a d d";
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 20px;
}

.row:nth-of-type(1) > .content:nth-of-type(1) {
  grid-area: a;
  background-color: orange;
}
.row:nth-of-type(1) > .content:nth-of-type(2) {
  grid-area: b;
  background-color: blue;
}
.row:nth-of-type(1) > .content:nth-of-type(3) {
  grid-area: c;
  background-color: green;
}
.row:nth-of-type(1) > .content:nth-of-type(4) {
  grid-area: d;
  background-color: red;
}

wheres the red content

I am not looking for an alternative approach to achieve the same result, I am simply asking why the fourth <Link/> is not displaying so I know what is going wrong.

>Solution :

Use the :nth-child psuedoselector since you are mixing element types (div and Link (a)), there isn’t a 4th link type element to style.

.row:nth-of-type(1) > .content:nth-child(1) {
  grid-area: a;
  background-color: orange;
}
.row:nth-of-type(1) > .content:nth-child(2) {
  grid-area: b;
  background-color: blue;
}
.row:nth-of-type(1) > .content:nth-child(3) {
  grid-area: c;
  background-color: green;
}
.row:nth-of-type(1) > .content:nth-child(4) {
  grid-area: d;
  background-color: red;
}

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading