I'm having an issue where the grid columns in my React component are showing up on separate rows in Safari 13. Numerous Google searches have come up with nothing and I'm really hoping somebody here can help. Here is the code of my React component (I've left out a bunch of state stuff and functions that aren't relevant):
import React, { useState, useRef } from 'react'
import classNames from 'classnames'
import SlideToggle from 'react-slide-toggle'
import styles from './shoppingListItem.module.css'
const ShoppingListItem = ({
itemId,
listTitle,
canEdit,
description,
quantity,
notes
}) => {
const [currentQuantity, setCurrentQuantity] = useState(quantity)
return(
<div className={styles.root}>
<button className={styles.button} onClick={toggleDetails}>
<span ref={headerRef} className={classNames(styles.header, { [styles.headerEditable]: canEdit })}>
{canEdit &&
<span className={styles.editIcons} ref={iconsRef}>
<div className={styles.icon} ref={deleteRef} onClick={destroyItem}><FontAwesomeIcon className={classNames(styles.fa, styles.destroyIcon
)} icon={faTimes} /></div>
<div className={styles.icon} ref={editRef} onClick={showEditForm}><FontAwesomeIcon className={styles.fa} icon={faEdit} /></div>
</span>}
<h4 className={styles.description}>{description}</h4>
</span>
<span className={styles.quantity}>
{canEdit && <div className={styles.icon} ref={incRef} onClick={incrementQuantity}>
<FontAwesomeIcon className={styles.fa} icon={faAngleUp} />
</div>}
<div className={styles.quantityContent}>
{currentQuantity}
</div>
{canEdit && <div className={styles.icon} ref={decRef} onClick={decrementQuantity}>
<FontAwesomeIcon className={styles.fa} icon={faAngleDown} />
</div>}
</span>
</button>
<SlideToggle toggleEvent={toggleEvent} collapsed>
{({ setCollapsibleElement }) => (
<div className={styles.collapsible} ref={setCollapsibleElement}>
<p className={styles.notes}>{notes || 'No details available'}</p>
</div>
)}
</SlideToggle>
</div>
)
}
The relevant CSS is:
.root {
font-family: 'Quattrocento Sans', Arial, Helvetica, sans-serif;
background-color: var(--main-color);
border-bottom: 1px solid var(--border-color);
}
.root:hover {
background-color: var(--hover-color);
}
.button {
width: 100%;
background: none;
border: none;
border-bottom: 1px solid var(--border-color);
text-align: left;
cursor: pointer;
padding: 0;
display: grid;
grid-template-columns: 2fr 1fr;
}
.fa {
color: var(--title-text-color);
}
.destroyIcon {
margin-right: 8px;
}
.header {
display: inline-block;
padding: 32px 16px;
border-right: 1px solid var(--border-color);
}
.headerEditable {
display: flex;
align-items: flex-start;
}
.editIcons {
display: flex;
flex-direction: row;
margin: auto 12px auto 0;
}
.quantity {
font-family: 'Quattrocento Sans', Arial, Helvetica, sans-serif;
font-size: 1rem;
color: var(--title-text-color);
display: inline-block;
margin: auto 0;
padding: 32px 8px;
display: flex;
justify-content: space-between;
}
.quantityContent {
margin: auto;
}
.icon {
display: inline-block;
padding: 4px;
cursor: pointer;
}
.description {
display: inline-block;
font-family: 'Quattrocento Sans', Arial, Helvetica, sans-serif;
font-size: 1.025rem;
color: var(--title-text-color);
margin: auto 0;
line-height: 1.25;
}
This is what the list item .button element/its children look like in Chrome (i.e., the way it's supposed to look):
This is the way the element looks in Safari (i.e., how it's not supposed to look):
The issue here turned out to be that I was using the button element incorrectly as the slide-toggle trigger and Chrome didn't mind but Safari didn't like it. I had made it a button because of accessibility reasons but I guess that was the wrong way to go. Changing the slide-toggle trigger into a div made it look the same in both Chrome and Safari.
Related
Hi I think this is very simple question so I apologize in advance for not being able to resolve it myself. I'm trying to make tag disappear by media query when width of window becomes less than 1200px. But it doesn't disappear. I think it's a matter of inheritance. I'd appreciate if you let me know how to solve this.
this is NaviSearch.jsx file. I want to make top tag disappear
import React from "react";
import "../navi.css";
import pencil from "./images/pencil.png";
import { Link } from "react-router-dom";
function NaviRecent (props) {
return (
<Link to="/login" style={{textDecoration : 'none'}}>
<button id="NaviRecent">
<img src={pencil} id="NaviRecentImage"/>
<span id="NaviRecentText">최근강의</span>
</button>
</Link>
);
}
export default NaviRecent;
and this file is css file. I only brought what seemed relevant
#Navi {
position: sticky;
background-color: #fff;
width: 100%;
height: 64px;
top: -1px;
z-index: 5;
box-shadow: 0 2px 4px 0 hsl(0deg 0% 81% / 50%);
width: 1263.330;
height: 64px;
display: flex;
align-items: center;
justify-content: space-between;
}
#NaviRecent {
border: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
position: relative;
right: 20px;
width: 100px;
height: 30px;
padding: 8px;
background: #00c471;
color: #fff;
border-radius: 4px;
}
#NaviHiddenLogo {
display: none;
}
#NaviRecentText {
box-sizing: border-box;
color: white;
cursor: pointer;
font-family: Pretendard,-apple-system,BlinkMacSystemFont,system-ui,Roboto,Helvetica Neue,Segoe UI,Apple SD Gothic Neo,Noto Sans KR,Malgun Gothic,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,sans-serif;
font-size: 16px;
font-weight: 600;
margin-left: 4px;
}
#NaviRecentImage {
width: 15px;
height: 15px;
}
#media screen and (max-width: 1020px) {
#NaviRecent {
display: none;
}
}
you should wrap into a tag like this :
import React from "react";
import "../navi.css";
import pencil from "./images/pencil.png";
import { BrowserRouter as Router, Link } from "react-router-dom";
function NaviRecent(props) {
return (
<Router>
<Link to="/login" style={{ textDecoration: "none" }}>
<button id="NaviRecent">
<img src={pencil} id="NaviRecentImage"/>
<span id="NaviRecentText">최근강의</span>
</button>
</Link>
</Router>
);
}
export default NaviRecent;
Be carefull, in your css file max-width is 1020px and not 1200px as you mentioned in your statement.
Hope it will help.
I'm new to next.js but I can't figure out why this doesn't work. (I've just started using from the latest v12.0.0)
I written in the terminal the following things:
npx create-next-app secondapp
cd secondapp
npm run dev
And did nothing else. But an error still shows:
../../nextjs try#2/secondapp/styles/globals.css
Global CSS cannot be imported from files other than your Custom . Due to the Global nature of stylesheets, and to avoid conflicts, Please move all first-party global CSS imports to pages/_app.js. Or convert the import to Component-Level CSS (CSS Modules).
Read more: https://nextjs.org/docs/messages/css-global
Location: ....\nextjs try#2\secondapp\pages_app.js
I checked the code, also using "find" tool in VScode, but there is only one file that imports the global.css, which is _app.js. Hoping someone could help me out.
These are my files:
//pages/_app.js
import '../styles/globals.css'
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
export default MyApp
//pages/index.js
import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'
export default function Home() {
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.main}>
<h1 className={styles.title}>
Welcome to Next.js!
</h1>
<p className={styles.description}>
Get started by editing{' '}
<code className={styles.code}>pages/index.js</code>
</p>
<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h2>Documentation →</h2>
<p>Find in-depth information about Next.js features and API.</p>
</a>
<a href="https://nextjs.org/learn" className={styles.card}>
<h2>Learn →</h2>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>
<a
href="https://github.com/vercel/next.js/tree/canary/examples"
className={styles.card}
>
<h2>Examples →</h2>
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>
<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className={styles.card}
>
<h2>Deploy →</h2>
<p>
Instantly deploy your Next.js site to a public URL with Vercel.
</p>
</a>
</div>
</main>
<footer className={styles.footer}>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
<span className={styles.logo}>
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
</span>
</a>
</footer>
</div>
)
}
//styles/global.css
html,
body {
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}
a {
color: inherit;
text-decoration: none;
}
* {
box-sizing: border-box;
}
//styles/Home.module.css
.container {
padding: 0 2rem;
}
.main {
min-height: 100vh;
padding: 4rem 0;
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.footer {
display: flex;
flex: 1;
padding: 2rem 0;
border-top: 1px solid #eaeaea;
justify-content: center;
align-items: center;
}
.footer a {
display: flex;
justify-content: center;
align-items: center;
flex-grow: 1;
}
.title a {
color: #0070f3;
text-decoration: none;
}
.title a:hover,
.title a:focus,
.title a:active {
text-decoration: underline;
}
.title {
margin: 0;
line-height: 1.15;
font-size: 4rem;
}
.title,
.description {
text-align: center;
}
.description {
margin: 4rem 0;
line-height: 1.5;
font-size: 1.5rem;
}
.code {
background: #fafafa;
border-radius: 5px;
padding: 0.75rem;
font-size: 1.1rem;
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
Bitstream Vera Sans Mono, Courier New, monospace;
}
.grid {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
max-width: 800px;
}
.card {
margin: 1rem;
padding: 1.5rem;
text-align: left;
color: inherit;
text-decoration: none;
border: 1px solid #eaeaea;
border-radius: 10px;
transition: color 0.15s ease, border-color 0.15s ease;
max-width: 300px;
}
.card:hover,
.card:focus,
.card:active {
color: #0070f3;
border-color: #0070f3;
}
.card h2 {
margin: 0 0 1rem 0;
font-size: 1.5rem;
}
.card p {
margin: 0;
font-size: 1.25rem;
line-height: 1.5;
}
.logo {
height: 1em;
margin-left: 0.5rem;
}
#media (max-width: 600px) {
.grid {
width: 100%;
flex-direction: column;
}
}
I have JSX which renders a card-like component:
{userResourceGuides && userResourceGuides.map((guide) => (
<div className='UserResourceGuides' key={guide.id}>
<div className='UserResourceGuides__col-1'>
<h2>{guide.file_label}</h2>
<p>From: {guide.service_name}</p>
</div>
<div className='UserResourceGuides__col-2'>
<div>
<a href={guide.file_url} target='_blank' rel='noreferrer'>
<span><AiOutlineLink /></span>
</a>
<p>View</p>
</div>
<div>
<span><AiOutlineDelete /></span>
<p>Delete</p>
</div>
</div>
</div>
))}
UserResourceGuides is the parent class. How can I apply a :not(:last-child) selector to this class?
SCSS
.UserResourceGuides {
display: flex;
justify-content: space-between;
margin: 1rem;
&:not(:last-child) {
border: 1px solid red; // all entries have border styling applied
}
&__col-1 {
margin-left: 2rem;
h2 {
color: $color-blue-subheader;
font-size: 1.8rem;
}
p {
color: black;
font-weight: 300;
font-size: 1.2rem;
}
}
&__col-2 {
display: flex;
align-items: center;
margin-right: 1rem;
...
The current styling I have still renders all entries with the border styling applied, and does not exclude the last-child. Not my desired result. What is my error here?
The spent text with the teal background is meant to be a tag, and I want the tag to appear above the todo bar...kind of like this:
Like a small rectangle on top of a big one. So the tag would be on the top left corner of the todo bar. How would I achieve this? I've tried doing margin to the tag, but that did not work out at all.
CSS for the tag (style.css)
.tag {
color: white;
font-size: 15px;
font-weight: 400;
letter-spacing: 2px;
text-transform: uppercase;
background: #36d1dc;
padding: 3px;
border-radius: 5px;
border-bottom-left-radius: 0px;
border-bottom-right-radius: 0px;
}
React JS code for the tag part (Todo.js)
<li className={`todo-item${todo.completed ? "completed" : ""}`}>
{isSpent && <p className="tag">Spent</p>}
{isReceived && <p className="tag">Received</p>} ${text}
</li>
In case anyone needs the whole of the todo.css file: https://pastecode.io/s/s5XZ9e3DRW
If you need anymore information, or if my question was poorly phrased, please tell me. Any help is very much appreciated. Thank you!
I think if yow will separate the tag and the navbar to two different div tags and put them on main div something like:
<div id="wrapper">
<div id="top-left">top left div</div>
<div id="down">down side div</div>
</div>
and the css will be something like (using grid on the main div):
#wrapper {
display: grid;
}
#top-left {
background: green;
width: 250px;
float:left;
margin-right: 20px;
}
#down {
background: blue;
float:left;
width: 500px;
}
the result is:
I would go with something like this, where input:focus could be a class set on on .container, for example, if the input has any values.
I couldn't understand why you used li and p in your original code, because you need to override so much stuff to make it look nice.
Using "rem" over a fixed pixel value is also preferred if you want to create a responsive site, where you just override the font-size in the body to make everything scale.
.container {
position: relative;
display: flex;
}
body,
input {
padding: 1rem;
}
.container.selected > .todo-item,
input:focus ~ .todo-item {
transform: translateY(-1rem);
}
.todo-item {
position: absolute;
left: 1rem;
transform: translateY(1rem);
transition: transform 400ms;
}
.tag {
color: white;
font-size: 15px;
font-weight: 400;
letter-spacing: 2px;
text-transform: uppercase;
background: #36d1dc;
padding: 3px;
border-radius: 5px;
border-bottom-left-radius: 0px;
border-bottom-right-radius: 0px;
}
<div class="container">
<input type="number">
<div class="todo-item"><span class="tag">Spent</span></div>
<div style="padding-top: 1rem"><-- select this input</div>
</div>
<div class="selected container" style="padding-top: 2rem">
<input type="number">
<div class="todo-item"><span class="tag">Spent</span></div>
</div>
body {
background-color: #48AEE0;
}
.container {
height: 200px;
width: 500px;
display: flex;
flex-direction: column;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.tag {
color: white;
font-size: 15px;
font-weight: 400;
letter-spacing: 2px;
text-transform: uppercase;
background: #36d1dc;
padding: 3px;
width: 80px;
text-align: center;
border-radius: 5px;
border-bottom-left-radius: 0px;
border-bottom-right-radius: 0px;
}
.other {
margin: 0;
display: inline-flex;
flex-direction: column;
}
input {
height: 30px;
width: 200px;
border: white;
margin: 0;
}
<div class="container">
<div class="tag">spent</div>
<div class="others">
<input type="text">
</div>
</div>
I am doing this website for my full stack web development course but I am having a bit of trouble with my css. I am wondering how I can get the text Div to scale with the page.
the div looks like this zoomed in,
and it looks like this zoomed out,
the text div always wants to stay the same size.
the css is
.waitingMainDiv {
width: 70%;
display: flex;
justify-content: center;
align-items: center;
margin: auto;
padding-top: 80px;
padding-bottom: 80px;
}
.waitingLeftDiv {
width: 100%;
height: auto;
}
.waitingLeftDivImage {
width: 100%;
height: auto;
}
.waitingRightDiv {
width: 100%;
height: auto;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.waitingTextDiv {
width: 85%;
color: grey;
}
.waitingTextDiv h2 {
font-family: nunito;
font-weight: 700;
font-size: 2.3em;
margin: 4%;
}
.waitingTextDiv h3 {
font-family: nunito;
margin: 30px;
}
.waitingTextDiv p {
font-family: nunito;
margin: 30px;
font-size: 1.2em;
}
.waitingButtonDiv {
display: flex;
justify-content: flex-start;
width: 85%;
margin-left: 50px;
}
.waitingButtonDiv button {
width: 180px;
border-radius: 8px;
box-shadow: 0px 2px 5px rgb(0, 0, 0, 0.4);
font-family: nunito;
font-weight: 800;
}
.waitingEnquireButton {
border: 2px solid #43c0f6;
background-color: white;
color: #707070;
margin-right: 100px;
}
.waitingSignUpButton {
border: 2px solid #f91c85;
background-color: #f91c85;
color: white;
}
and the react.js is
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js">
import teacherPicture from "../../../../img/teacherPicture.png";
import React, { useState } from "react";
import "./Waiting.css";
import NavModal from "../../../Nav/NavModal";
export default function Waiting() {
const [open, setOpen] = useState(false);
const handleOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<div className="waitingMainContainer">
<div className="waitingMainDiv">
<div className="waitingLeftDiv">
<img className="waitingLeftDivImage" src={teacherPicture} alt="" />
</div>
<div className="waitingRightDiv">
<div className="waitingTextDiv">
<h2>What are you waiting for?</h2>
<h3>Start teaching Digital Technologies today.</h3>
<p>
If you need more information, we are happy to answer any questions
you may have.
</p>
</div>
<div className="waitingButtonDiv">
<button className="waitingEnquireButton">ENQUIRE NOW</button>
<button
onClick={() => handleOpen()}
className="waitingSignUpButton"
>
SIGN UP
</button>
<NavModal open={open} handleClose={handleClose} />
</div>
</div>
</div>
</div>
);
}
</script>
Thankyou to those who review my code, its definitely a simple fix but im driving myself crazy over it.
Give your main div a width, not %;
.waitingMainDiv {
width: 70vw; //changed
display: flex;
justify-content: center;
align-items: center;
margin: auto;
padding-top: 80px;
padding-bottom: 80px;
}