Vertical scroll appearing only on mobile devices - css

I'm using React + Tailwind to build a website.
On desktop and mobile widths in the browser (emulating mobile device using Chrome dev tools), the website looks perfectly fine.
It's only when I load it from my mobile phone (iPhone) that a vertical scroll bar appears.
I've tried removing anything that might be causing it from the CSS including
display: flex and min-height:100vh but nothing is getting rid of the scroll.
Why is the vertical scroll only appearing on my actual mobile device, but not the Chrome emulator and how can I debug it?
App.jsx
function App() {
return (
<div className="min-h-screen flex flex-col">
<Router>
<Navbar />
<Routes>
<Route exact path="/" element={<Login />} />
</Routes>
</Router>
</div>
);
}
Login.jsx
const Login = (props) => {
return (
<div className="flex flex-col flex-1 items-center justify-center ">
<form onSubmit={handleSubmit}>
<div className="">
<input
type="email"
value={emailVal}
onChange={(e) => setEmailVal(e.target.value)}
/>
</div>
<button
onClick={handleSubmit}
className=""
>
Submit
</button>
</form>
</div>
);
};
UPDATE
I noticed removing
className="min-h-screen flex flex-col" from App.jsx actually gets rid of the scroll, but this also removes the ability to expand the container to the full height of the screen and center the content in the middle.

Related

Can't set background under Layout components React and Tailwind CSS

I am trying to set the background image under my components. But it always is on top, so my elements are under it.
Or in the second variant, all works fine, except that I can't apply blur-xl only to the background. it applies to background and Layout elements.
bg-repeat-y needs me to copy down my image, am I right?
import moons from './../assets/moon.svg'
const Background = ({ children }) => {
return (
<div className='bg-white '>
<div className='min-h-screen min-w-screen bg-repeat-y' style={{ backgroundImage: `url(${moons})` }}>
<div className="div"></div>
</div>
{children}
</div>
);
}
export default Background;
This Background element wraps other elements in Laoyout in react-router-dom
export const AppLayout = () => (
<div>
<Background>
<NewNavbar />
<Outlet />
<Footer />
</Background>
</div>
);
Help me, please!
try this, the blur will be applied between your components & background image
export const AppLayout = () => (
<Background>
<div class="backdrop-blur-xl h-full">
<NewNavbar />
<Outlet />
<footer />
</div>
</Background>
);
if you have any queries, refer to this link
https://play.tailwindcss.com/yX9aAMagRj
For the first variant/approach that you mentioned, you can set the z-index of the background to negative using the class -z-10 . Then your background will not come over your other elements.

Second Vertical (Y axis) scroll Bar, cant remove it without removing snap effect

in my nextjs 13.1 website using the new app directory and tailwind css, I have the snap effect on each section of my SPA, with my current code, the snap works, but i then get a second vertical scrollbar. if i remove overflow-y-scroll and put in overflow-y-hidden, of course this does remove the second scrollbar, but then my snap doesnt work. I have tried auto, but cant seem to only have 1 vertical scrollbar with the snap effect. Here is my page.jsx code:
`export default function Home() {
return (
{/* Header in Layout /}
{/ Header */}
{/* Hero */}
<section id="hero" className="snap-start">
<Hero />
</section>
{/* About*/}
<section id="about" className="snap-center">
<About />
</section>
{/* Work Experience */}
<section id="freelance" className="snap-center">
<FreelanceWork />
</section>
{/* Practice Projects */}
<section id="projects" className="snap-start">
<PracticeProjects />
</section>
{/* Skills */}
<section id="skills" className="snap-start">
<Skills />
</section>
{/* Contact Me */}
<section id="contact" className="snap-center">
<ContactMe />
</section>
</div>
);
}`
and if it helps, as an example in every component, generally speaking i have a div wrapping every component with this: <div className=" h-screen flex flex-col relative mx-auto text-center items-center md:text-left md:flex-row max-w-7xl px-10 justify-center">
so not sure if i have to add something to each div to make this work. Thanks!
i tried playing around with different overflows but i couldnt get it to work without losing snap effect

Having trouble with next/Image component centering/covering it's parent div when Header/Footer layout components are added

Home page in NextJS, styled with TailwindCSS, is working as expected. I originally had the background image defined in the tailwind.config.js file and applied via styles (and there is no problem), but I would prefer the image optimization of next/Image.
// index.jsx
const Home = () => {
return (
<div className="flex min-h-screen flex-col items-center justify-center py-0">
<Image src='/images/background.png' fill={true} style={{ objectFit: 'cover' }} className='-z-10' alt='Alt text' />
<main className='flex w-full flex-1 flex-col items-center justify-center px-5 md:px-20 text-center bg-gradient-radial to-r from-black via-black/30'> {/* All content here is displaying as expected */} </main>
</div>
)
}
This works as expected. But, when I add an overall Layout.jsx to the site, the background image alignment is not behaving as I would anticipate.
// Layout.jsx
import Navbar from './Navbar.jsx'
import Footer from './Footer.jsx'
const Layout = ({ children }) => {
return (
<>
<Navbar />
<main>
{children}
</main>
<Footer />
</>
)
}
export default Layout
The background.png image no longer aligns with its parent <div>, but instead with the top of the screen. This means the navbar is sitting on top of the background image, obstructing some of the top portion.
Simultaneously, a gap now exists between the bottom of the background image and the top of the Footer, equal in height to the height of the Navbar.
I have tried all combinations of relative and absolute classes both the parent <div> and the child <Image>, without success.
Switching back to a tailwind.config.js defined background image and inserting it using e.g. className='bg-my_bg_image' solves the alignment issues, but no longer leverages NextJS next/Image optimization and hurts my site performance.
So the preferred solution would be to continue to use the next/Image component, aligned properly.

React, Tailwind and Application of Viewport-Specific Classes

I am trying to apply an onhover effect for a viewport larger than 768px. Below 768px it should look like the elements are "always onhover".
Specifically, on desktop or larger devices in general, there should be a background in a box at onhover. This background should always be shown on mobile, i.e. <768px in my case.
What am I doing wrong?
Here are the snippets.
JSX-Snippet:
import { features } from "../constants"; import styles from "../style";
const FeatureCard = ({ icon, title, content, index }) => (
<div className=
{`
flex flex-row p-6 rounded-[20px]
ss:max-sm:feature-card-small
sm:feature-card
${index !== features.length - 1 ? "mb-6" : "mb-0"}
`}
>
<div className={`
w-[64px]
h-[64px]
rounded-full
${styles.flexCenter}
bg-dimBlue`
}>
<img
src={icon}
alt="star"
className="
w-[50%]
h-[50%]
object-contain"
/>
</div>
<div className="flex-1 flex flex-col ml-3">
<h4 className="
font-poppins
font-semibold
text-white
text-[18px]
leading-[23.4px]
mb-1">
{title}
</h4>
<p className="
font-poppins
font-normal
text-dimWhite
text-[16px]
leading-[24px]
">
{content}
</p>
);
export default FeatureCard;
CSS-Snippet:
.feature-card:hover { background: var(--black-gradient); box-shadow: var(--card-shadow); }
.feature-card-small { background: var(--black-gradient); box-shadow: var(--card-shadow); }
simply apply feature-card as class without viewport specification works as expected; onhover --> background changes
different viewport-specifications (sm:..., ss:max-sm and sm:) and creation of different CSS classes (so there can be no overlap for sure) did not work
sorry if the code block looks like a mess here on stackoverflow. my first post, still learning.

Image fills up the whole space on Safari mobile

So my site's navbar shows up differently on Android and iOS phone, on Chrome/Android it looks fine but for some reason, the hamburger icon got stretched out and covers the whole page on Safari/iOS.
I use TailwindCSS and here's my code:
<nav className="fixed sticky top-0 z-10 flex gap-2 p-2 bg-white cursor-pointer md:pl-4">
<img
onClick={toggleOpen}
src="/hamburger-menu-red.png" className="w-10" alt="menu"
/>
{props.showLogo && (
<Link to="/">
<img
src="/cooken-logo.png" alt="cooken-logo" className="w-20 cursor-pointer" />
</Link>
)}
</nav>
Is it because I don't specify the height of the hamburger icon or is it some compatibility issue with Safari? Any help would be greatly appreciated.
Update based on Seth's input
<nav className="fixed sticky top-0 z-10 flex items-center h-12 gap-2 p-2 bg-white md:pl-4">
<button
onClick={toggleOpen}
>
<img
src="/hamburger-menu-red.png" className="w-10 h-8" alt="menu"
/>
</button>
{props.showLogo && (
<Link to="/">
<img
src="/cooken-logo.png" alt="cooken-logo" className="w-16 h-8"
/>
</Link>
)}
</nav>
Because it is the child of a flex item and the default align-items property of flex items is stretch.
However, there are other issues that are more of concern with your code, it is invalid. Neither an image of a hamburger or a site logo are justifiable nav items. A nav element should contain navigation links to site pages.
You should not attach a click event to an image. An image element is just for showing an image, nothing else. If it goes somewhere use a link, if it does something use a button element.
You don't need to put cursors on links, they already have them; images don't because they are not interactive elements.
I would suggest that the best approach is to use a button elemement (which already comes with clicky behaviours built in) to reveal a list of links (which come with linky behaviours built in).

Resources