Can someone help me with this?

I have no idea why I can’t make this responsive. I am attaching the code to see if someone can help me clarify. Thank you so much!

App.tsx

import { useState } from 'react';
import './App.css';
import { ReactMarkdown } from 'react-markdown/lib/react-markdown';

const text=`# Welcome to my React Markdown Previewer!

## This is a sub-heading...
### And here's some other cool stuff:

Heres some code, \`<div></div>\`, between 2 backticks.

\`\`\`
// this is multi-line code:

function anotherExample(firstLine, lastLine) {
  if (firstLine == '\`\`\`' && lastLine == '\`\`\`') {
    return multiLineCode;
  }
}
\`\`\`

You can also make text **bold**... whoa!
Or _italic_.
Or... wait for it... **_both!_**
And feel free to go crazy ~~crossing stuff out~~.

There's also [links](https://www.freecodecamp.com), and
> Block Quotes!

And if you want to get really crazy, even tables:

Wild Header | Crazy Header | Another Header?
------------ | ------------- | -------------
Your content can | be here, and it | can be here....
And here. | Okay. | I think we get it.

- And of course there are lists.
  - Some are bulleted.
     - With different indentation levels.
        - That look like this.


1. And there are numbererd lists too.
1. Use just 1s if you want!
1. And last but not least, let's not forget embedded images:

![freeCodeCamp Logo](https://cdn.freecodecamp.org/testable-projects-fcc/images/fcc_secondary.svg)
`;

function App() {
  const [markdownText, setMarkdownText] = useState<string>(text);

  return (
    <> 
    <div className='body'>
      <h1 className='title'>Markdown Previewer</h1>
      <div className='boxes-container'></div>
      <div className='editorWrap'>
       <div className='toolbar'>
      <div className='editor'>
        <i className='fab fa-free-code-camp'></i>
        Editor
        <i className='fa fa-arrows-alt'></i>
        </div>
          </div>
        <textarea name='editor' id='editor' value={markdownText} onChange={(e) => setMarkdownText(e.target.value)}></textarea>
        </div>
        <div id='preview'>
          <ReactMarkdown>{markdownText}</ReactMarkdown>
        </div>
          </div>
    </>
  )
}

export default App

App.css

.body {
  background-color: darkgray;
  }

.title {
  text-align: center;
  margin: auto;
  margin-top: 40px;
  font-family: Russo One;
  background-color: black;
  color: pink;
  }

.boxes-container {
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  margin: auto;
  margin-top: 40px;
  width: 30%;
}


.editorWrap .toolbar {
  width: 100%;
}

.editorWrap {
  width: 500px;
  margin: auto;
}

.toolbar {
  display: flex;
  background-color: lightpink;
  padding: 0.3rem;
  border: 1px solid pink;
  box-shadow: pink;
  font-family: Russo One;
  font-size: 1rem;
  color: pink;
  text-align: center;
  margin: auto;
}

.editor {
  display: flex;
  height: 5vb;
  font-size: 18px;
  resize: none;
  text-align: center;
  color: black;
  font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
  position: relative;
  left: 210px;
  top: -50%;
}

.fab {
  position: relative;
  left: -200px;
}

.fa {
  position: relative;
  right: -200px;
}

#editor {
  margin: auto;
  width: 500px;
  height: 40vb;
  font-size: 18px;
  background-color: lightpink;
  text-align: left;
}

.editorWrap textarea {
  width: 99%;
  min-height: 200px;
  margin-bottom: -5px;
  resize: vertical;
  outline: none;
  padding-left: 5px;
  padding-top: 5px;
  font-size: 0.875rem;
  }

Thank You!

You are inserting a chunk of HTML (the code you’ve posted there) into some containing HTML structure. What is that HTML structure and what is the CSS you’ve defined for it?

index.html

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" type="image/svg+xml" href="/vite.svg"/>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.12.1/css/all.css" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js" defer></script>
    <title>Markdown Previewer</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>

Ah ok, just needed to check if there were any extra rules I couldn’t see.

Anyway, elements with display: flex and without an explicit width are going to size [approximately] to whatever their contents are. So in this case you have a thin column of elements, so the container with display flex is going to be a thin container

I feel like I’m looking for a dragon in some cave xD

Ah it’s not even implicit: I didn’t scroll down the CSS enough, just saw the element with the class .editor, didn’t realise you’d also applied rules to it via the id #editor as well. You have set a width on the container, and it’s 500px, both the editor and the previewer are in that container.

I’m still looking for the dragon, once I finish finding it I won’t forget it xD

  • Both editorWrap and editor have a fixed width. Use max-width instead.

  • The image element doesn’t have any CSS. Use max-width: 100%

  • Add box-sizing: border-box to everything.

* {
  box-sizing: border-box;
}
1 Like

Yes, I know the image doesn’t have css, neither does the previewer, I’m stuck with the editorwrap css and the editor I’m unable to make it responsive, but I’ll end up doing it! xD, once I achieve that goal, it’s to put css on what I’m missing and finish passing the tests.

As I said, use max-width or use a relative unit like %

If you give an element a fixed width in pixels it can’t shrink below that value.

1 Like

Now it’s responsive, except the toolbar because I don’t have a human way to make that part responsive xD


App.tsx

import { useState } from 'react';
import './App.css';
import { ReactMarkdown } from 'react-markdown/lib/react-markdown';

const text=`# Welcome to my React Markdown Previewer!

## This is a sub-heading...
### And here's some other cool stuff:

Heres some code, \`<div></div>\`, between 2 backticks.

\`\`\`
// this is multi-line code:

function anotherExample(firstLine, lastLine) {
  if (firstLine == '\`\`\`' && lastLine == '\`\`\`') {
    return multiLineCode;
  }
}
\`\`\`

You can also make text **bold**... whoa!
Or _italic_.
Or... wait for it... **_both!_**
And feel free to go crazy ~~crossing stuff out~~.

There's also [links](https://www.freecodecamp.com), and
> Block Quotes!

And if you want to get really crazy, even tables:

Wild Header | Crazy Header | Another Header?
------------ | ------------- | -------------
Your content can | be here, and it | can be here....
And here. | Okay. | I think we get it.

- And of course there are lists.
  - Some are bulleted.
     - With different indentation levels.
        - That look like this.


1. And there are numbererd lists too.
1. Use just 1s if you want!
1. And last but not least, let's not forget embedded images:

![freeCodeCamp Logo](https://cdn.freecodecamp.org/testable-projects-fcc/images/fcc_secondary.svg)
`;

function App() {
  const [markdownText, setMarkdownText] = useState<string>(text);

  return (
    <> 
    <div className='body'>
      <h1 className='title' style={{ textAlign: "center" }}>Markdown Previewer</h1>
      <div className='boxes-container'></div>
      <div className='editorWrap'>
       <div className='toolbar'>
      <div className='editor'>
        <i className='fab fa-free-code-camp'></i>
        Editor
        <i className='fa fa-arrows-alt'></i>
        </div>
          </div>
        <textarea 
          name='editorWrap' 
          id='editor' 
          value={markdownText} 
          onChange={(e) => setMarkdownText(e.target.value)}></textarea>
        </div>
        <div id='preview'>
          <ReactMarkdown>{markdownText}</ReactMarkdown>
        </div>
          </div>
    </>
  )
}

export default App

App.css

* {
  box-sizing: border-box;
}

.body {
  background-color: darkgray;
  }

.title {
  text-align: center;
  margin: auto;
  margin-top: 40px;
  font-family: Russo One;
  background-color: black;
  color: pink;
  }

.boxes-container {
  position: relative;
  max-width: 100%;
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  margin: auto;
  margin-top: 40px;
  width: 30%;
}

.editorWrap .toolbar {
  width: 100%;
  max-width: 100%;
  position: relative;
 }

.editorWrap {
  position: relative;
  max-width: 100%;
  width: 500px;
  margin: auto;
}

.toolbar {
  position: relative;
  max-width: 100%;
  display: flex;
  background-color: lightpink;
  padding: 0.3rem;
  border: 1px solid pink;
  box-shadow: pink;
  font-family: Russo One;
  font-size: 1rem;
  color: pink;
  text-align: center;
  margin: auto;
}

.editor {
  position: relative;
  display: flex;
  font-size: 18px;
  text-align: center;
  color: black;
  font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
  left: 210px;
  top: -50%; 
}

.fab {
  position: relative;
  left: -200px;
}

.fa {
  position: relative;
  right: -180px;
}

#editor {
  max-width: 100%;
  margin: auto;
  width: 500px;
  height: 40vb;
  font-size: 18px;
  background-color: lightpink;
  text-align: left;
}

@media screen and (max-width: 500px) {
  .editorWrap {
    width: calc(100% - 40px);
  }
}

.editorWrap textarea {
  position: relative;
  min-height: 200px;
  margin-bottom: -5px;
  resize: vertical;
  outline: none;
  padding-left: 5px;
  padding-top: 5px;
  font-size: 0.875rem;
  }

index.html

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" type="image/svg+xml" href="/vite.svg"/>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.12.1/css/all.css" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js" defer></script>
    <title>Markdown Previewer</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>

What do you mean by that?

If you see the screenshots you will see what I mean. xD

Not really. You may need help with it, but that doesn’t mean it isn’t possible.

You might want to try and explain why you can’t make it responsive because I see no issue in making it responsive.

Yes, I know it is possible, the expression “there is no human way to do it” is like a joke, I think making that responsive is going to cost me time. xD

As long as you learn something from it, it will be time well spend.

You can ask for help here if you need it.

Yes that’s why I love it! Jajaja. Yes, if I see that I am going to delay too much I will do it. Thank you!