Creating a responsive website using Tailwind and React

I have created a blog and I want to ensure it is responsive. My aim is to have a dropdown menu on the right side for mobile devices, featuring options for new profile and logout. On desktop mode, I prefer to have the about, new, and profile options in the middle with only the logout button on the right.

Here is the code I have been working on so far. I used 'lg:' to make it responsive for larger than desktop screens.

If there are any grammatical or spelling errors, I apologize in advance as English is not my first language.

``import React from 'react'; import { Link } from 'react-router-dom'; import { useUserContext } from './UserProvider';`

function Navbar() {

const { user, setUser } = useUserContext()

function logout() { localStorage.removeItem('user') setUser(null)

}

return ( Tech-Blog

  <div className=" NavLinks  bg-pink-100 flex flex-col absolute top-10 right-0 p-4 lg:flex-row  ">
    <div className="Links
    flex flex-col
     lg:flex-row lg:absolute lg:left-1/2 lg:top-1/2 lg:transform md:-translate-x-1/2 lg:-translate-y-1/2  text-2xl lg:justify-between lg:w-60   " >
      <div className='hover:cursor-pointer '>About</div>
      <div className='hover:cursor-pointer '>Profile</div>
      <Link to="/new">New</Link>
    </div>
    <div className='buttons flex md:flex-row md:absolute lg:right-8 lg:top-1 lg:gap-6  '>

      {/* check if someone is logged in, if yes then show a logout button */}
      {user === null ?
        <> <Link to="/login" ><button className='bg-blue-400 px-4 rounded-md py-2 text-white'>SignIn</button></Link>
          <Link to="/register" ><button className='bg-blue-400 px-4 rounded-md py-2 text-white'> Register</button></Link> </> :
        <button className='bg-blue-400 px-4 rounded-md py-2 text-white font-mono' onClick={logout}>Log out </button>}

    </div>


  </div>



</div>

) }

export default Navbar `

I tried making some changes in Tailwind using 'lg:' and other adjustments

Answer №1

In order to create a responsive design, it is essential to leverage the Tailwind CSS properties such as "sm:", "md:", "lg:", and "xl:". These allow you to customize styles for various viewport sizes. For detailed instructions, refer to the documentation on responsiveness provided by Tailwind. https://tailwindcss.com/docs/responsive-design

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Space between Logo Header and Navigation Bar

Recently, I attempted to create a new header with a responsive logo and menu. After seeking guidance from StackOverflow experts, everything seems to be functioning correctly now. However, I am facing an issue regarding the gap between the header and navba ...

Functions that are imported are unable to access the state using `this.state`

Looking for help with my code in app.jsx import { test } from './functions' test() I also have functions.jsx: var test test = () => { console.log(this.state) } export { test } The current issue is: TypeError: _this is undefined I atte ...

Update the color of the text depending on the background color

When hovering over my CTA, a sliding effect occurs. However, I am facing an issue with the text being difficult to read depending on the background color. To better understand what I'm trying to achieve, you can view the demo here: Demo on CodePen T ...

Managing compatibility with IE11 for all dependent packages: Best practices

Currently, I am working on a React app using version 17.0 and Next.js version 11.1.2 among other stacks. While Next.js typically supports IE11 by default, I have encountered issues with compatibility after adding certain packages to my project. The consol ...

Creating a dynamic 3x3 layout using flexbox: a step-by-step guide

Is it possible to dynamically create a layout in Next.js with 3 columns of 3 rows using flexbox, React Bootstrap, or CSS only? https://i.sstatic.net/tTinS.jpg ...

Using TypeScript with React and Redux to create actions that return promises

Within my React application, I prefer to abstract the Redux implementation from the View logic by encapsulating it in its own package, which I refer to as the SDK package. From this SDK package, I export a set of React Hooks so that any client can easily u ...

What could be causing the issue with React Router not functioning properly in Material UI?

I'm currently working on creating a tab and adding routing inside the first tab. However, I am facing an issue where the desired page does not display after clicking on the link. Strangely, upon refreshing the page, the corresponding page appears as e ...

Auto-selecting the first item in a CSS menu when the switcher is tapped on mobile devices

Struggling with a responsive CSS menu on my website, . The switcher on mobile seems to automatically click the first item in the menu (Home) as I open it, redirecting me instantly. When setting the link to "#" everything is fine, but then I lose the home l ...

Error occurred in React-Redux when dispatching an action: "this.props.mostrarProduto is not a function"

I'm trying to trigger 2 actions on my container, but I keep encountering the error "this.props.mostrarProduto() and this.props.esconderProduto() is not a function". The goal is to implement a mouseover action to show and hide a component. Thank you ...

VS Code fails to provide auto-suggestions for typed attributes in my library

While working on my React application with a component library, I realized that VS Code isn't providing hints for attributes that are typed with my custom types. Below is a simplified version of the code I'm using: import { ProviderApp } from &ap ...

Implementing a feature in jQuery to reveal an element upon button click

I need to create a functionality where clicking a button will display a panel. Initially, I have set the panel's visibility to false in its properties. So, when the user clicks the button, the button should hide and the panel should show up. How can I ...

Trigger an event when the menu is outside the viewport and then lock the menu to the top of the viewport

I am trying to create a menu element that remains fixed at the top of the browser viewport as the user scrolls, ensuring it is always visible. In my webpage layout, the menu sits below some text in the header initially. Once the user scrolls past the heade ...

retrieve movies = await response.data.films.map(movie =>

My server.js file is throwing an error message. Here's the error: let films = await response.data.films.map(film =>{ ^^^^^ SyntaxError: await is only valid in async function at new Script (vm.js:79:7) ...

Empty Github page displayed on individual professional website

Hello everyone, I am new to development. I recently put together my own personal portfolio and stored it in this GitHub repository -> https://github.com/LuisssM/Portfolio. However, when I try to launch the website at , it shows the content of the read-m ...

What is the best technique to incorporate dark/light mode in Bootstrap 5?

Is it best to introduce themes such as dark and light themes in Bootstrap 5 using CSS/SCSS, JavaScript, or a combination of both? Should we create a separate CSS file like dark.css to overwrite classes? Or should we use JavaScript to switch classes like ...

Increase the div id using jQuery

I've got this code snippet here and, oh boy, am I a newbie. How can I increase the number in the div using a jQuery script? if($res >= 1){ $i=1; while($row = mysqli_fetch_array($qry)){ echo "<div clas ...

Encountering a 404 error while trying to refresh the page in a React App hosted on Her

After deploying a React App on Heroku, I encountered a frustrating issue: every time a page is refreshed, a 404 error appears, such as: Cannot GET /create In my search for a solution, I came across a related issue: Question about 404 with React Router ...

What is the best way to retrieve the URL of a website using scrapy?

Currently, I am faced with the challenge of scraping the Amazon website using Scrapy. While I have successfully extracted items like product titles and prices, I am struggling to figure out how to extract the URL of a product (as shown in the image at the ...

The slider feature is malfunctioning on Internet Explorer version 8

Hello everyone, I am facing an issue with my website located at: http://210.48.94.218/~printabl/ When viewed in IE 8, the slider is not functioning properly (it is showing collapsed between the menu and product images section) The theme used for my site ...