Dropdown menu not going over div - css

I'm following this tutorial https://blog.campvanilla.com/reactjs-dropdown-menus-b6e06ae3a8fe to make a dropdown in my React app.
The click/open function works fine except the menu, which is inside of its own component is not going beyond the header container:
Here is the css for my Header:
#inner-header {
background-color: #f1c40f;
font-family: "Rubik", sans-serif;
font-weight: 700;
display: flex;
width: 100%;
flex-direction: space-between;
height: 60px;
align-items: center;
padding: 15px 0 15px 2.5%;
align-items: top;
}
The tutorial didn't show CSS for the dropdown so I created my own:
.drop-down {
z-index: 1000;
overflow-y: visible;
width: 300px;
background-color: white;
display: block;
box-shadow: 0 20px 30px 0 rgba(0, 0, 0, 0.1), 0 4px 4px 0 rgba(0, 0, 0, 0.15);
}
The only difference between my code and the tutorial is that I've imported the <Card /> component into my header in a React Component:
import React from 'react'
import {Link} from 'react-router-dom'
import logo from '../images/logo.svg'
import Card from '../components/Card'
export default function InnerHeader() {
return (
<>
<div id="inner-header">
<div className="logo">
<Link to="/dashboard"><img src={logo} height="50px" alt="snack-page" /></Link>
</div>
<Card />
</div>
</>
)
}
I thought that giving the dropdown a z-index would allow it to go over the header but that wasn't the case. What is the best way to display the dropdown while it's in its own component? I'm not sure what the solution would be in this case?

I was able to resolve this by making two changes to the code based on the answers here (slightly modified)
First, the flex-direction needed to be set to row.
Next, justify-content needed to be set to space-between as #JoeLloyd pointed out in my typo.
Finally, the z-index is now set to 3 and was given a position of relative
#inner-header {
background-color: #f1c40f;
font-family: "Rubik", sans-serif;
font-weight: 700;
display: flex;
width: 100%;
height: 75px;
justify-content: space-between;
flex-direction: row;
padding: 15px 0 15px 2.5%;
align-items: top;
}
.menu-button {
padding-right: 15px;
float: right;
}
.drop-down {
z-index: 3;
margin-right: 12px;
position: relative;
width: 200px;
height: 200px;
display: inline-block;
background-color: white;
box-shadow: 0 20px 30px 0 rgba(0, 0, 0, 0.1), 0 4px 4px 0 rgba(0, 0, 0, 0.15);
}

flex direction is wrong
Set it to column if you want your content to go into a column and not a row. There's no such thing as flex-direction: space-between;
flex-direction: column;

Related

Want to reduce the unnecessary gaps between html tags

I was creating my custom toast notification using react but there is unnecessary gaps between the tag because of which the size in to big
React Code
import React from 'react'
import './CustomToast.css'
import {BsFillBellFill} from 'react-icons/bs'
import {ImCross} from 'react-icons/im'
function useCustomToast(title,message){
const close = () =>{
alert('closed')
}
return(
<div className="notification">
<div className="topPart">
<div className="iconPoision">
<p><BsFillBellFill/></p>
</div>
<div className="notifiData">
<p><b>{title}</b></p>
</div>
<div className="crossPosition">
<p><button onClick={close} className="closeButton"><ImCross/></button></p>
</div>
</div>
<div className="downPart">
<p>{message}</p>
</div>
</div>
)
}
The Code's CSS
.notification{
top: 5px;
right: 5px;
background-color: rgba(0, 255, 234, 0.726);
color: rgb(255, 255, 255);
box-shadow: 2px 2px rgba(255, 255, 255, 0.562);
box-sizing: border-box;
position: fixed;
border-radius: 5px;
display: grid;
grid-row-gap:2px;
grid-template-rows: auto auto;
}
.topPart{
display: grid;
grid-column-gap: 2px;
grid-template-columns: 22px auto 25px;
}
.downPart{
display: grid;
grid-column: auto;
grid-template-columns: auto;
text-align: right;
}
.notifiData{
text-align: left;
}
.iconPoision{
text-align: center;
}
.closeButton{
background-color: transparent;
border: transparent;
color: rgb(255, 255, 255);
transition:ease-out;
}
.crossPosition{
text-align: center;
}
So, if i remove the space between them the notification panel will be some small and which looks like a notification type only
See so much of empty space between top and bottom row
Just add to your './CustomToast.css' and modify it as needed.
p {
padding: 0 0;
margin: 0 0;
}
Change p with any other tag as div, span etc

react.js text div wont scale with my page but the image div will

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;
}

Inner flexbox overrules flex-grow on outer flexbox

// jsx in React.js
<Table>
<StyledTableBody>
{tradeInData.map(dataRow => {
return (
<FlexTableRow key={dataRow.productId}>
<StyledTableCell style={{flex : "3 1 auto !important"}}>
<ProductNameDiv>
<p>{dataRow.productName} ({dataRow.quantity})</p>
{showDeleteIcon && <DeleteOutline
style={{ cursor : "pointer" }}
/>}
</ProductNameDiv>
<SecondaryText>Id: {dataRow.productId}</SecondaryText>
</StyledTableCell>
<StyledTableCell style={{flex : "1 1 auto !important"}}
>{dataRow.price}</StyledTableCell>
</FlexTableRow>
)}
)}
</StyledTableBody>
</Table>
I want the flexbox on FlexTableRow to show the 2 elements below it at a 3:1 size ratio. You can see it's about 9:1 right now.
Looks like the flexbox on ProductNameDiv is consuming all the space. I can't set it to display: inline-block since it is also a flexbox.
I tried inline-block on the SecondaryText div and that seemed to overwrite the auto margins anyways.
What is the solution to this that will 1) preserve horizontal centering of text, 2) display the 2 children of FlexTableRow at roughly 3:1 horizontally?
// styled components
const StyledTableBody = styled(TableBody)`
* {
text-align: center;
}
`;
const FlexTableRow = styled(TableRow)`
display: flex;
> * {
border: 2px solid goldenrod !important;
}
`;
const StyledTableCell = styled(TableCell)`
border: 1px solid rgba(200, 200, 200, .6);
border-radius: 4px;
padding: 0 !important;
margin: 0 !important;
`;
const ProductNameDiv = styled.div`
border: 2px dashed lightgreen;
display: flex;
justify-content: center;
align-items: center;
`;
const SecondaryText = styled.p`
display: inline-block;
border: 2px dotted lightcoral;
font-style: italic;
font-size: .9rem;
margin: -12px auto 0 auto;
`;
As I was recreating the issue in a Codepen I found that Material UI's table elements caused the issue. I simply replaced them with standard HTML elements and the inner flexbox no longer fought against its own flex-grow setting:
const ReviewTable = styled.table`
max-width: 100vw;
`;
const FlexTableRow = styled.tr`
border: 1px solid rgba(200, 200, 200, .6);
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
`;
const StyledTableCell = styled.td`
border-radius: 4px;
padding: 0 !important;
margin: 0 !important;
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
`;
const ProductInfoCell = styled(StyledTableCell)`
flex-grow: 3;
`;
const ProductPriceCell = styled(StyledTableCell)`
flex-grow: 1;
margin: 0 auto;
padding: 5px 0 !important;
`;

Angular items in flex don't have fixed height after making them component

I am making my portfolio in angular and doing skill page now, I have list of skills grouped in category each category has their own box, and few skills with progress and amount of skills differs for each category. The thing is that since skill section wasn't separate component everything was ok, because height of boxes was fixed and if one box had less skills than another in the row empty space was added to adjust elements in row to have same height, now when I turned div into component all items(components) in row have diffrent heights according to their content.
skill page before:
<div class="flex-container">
<div class="skill-section">
<h3> Skill title</h3>
<app-skill-progress></app-skill-progress>
<app-skill-progress></app-skill-progress>
<app-skill-progress></app-skill-progress>
</div>
<div class="skill-section">
<h3> Skill title</h3>
<app-skill-progress></app-skill-progress>
<app-skill-progress></app-skill-progress>
</div>
</div>
skill page after:
<div class="flex-container">
<app-skill-section></app-skill-section> // has 3 skills inside
<app-skill-section></app-skill-section> // has 2 skills inside
</div>
here are styles for classes:
.flex-container {
display: flex;
flex-wrap: wrap;
}
.skill-section {
width: 560px;
margin-bottom: 35px;
margin-right: 30px;
border-radius: 8px;
padding: 24px 16px;
background-color: #fff;
box-shadow: 0px 5px 20px -1px rgba(0, 0, 0, 0.55);
position: relative;
}
The .skill-section class is now nested inside the new component element, so it's no longer an immediate child of the .flex-container. I recommend changing the selector from the .skill-section class to the app-skill-section element and adding display: block.
Like so:
.flex-container {
display: flex;
flex-wrap: wrap;
}
app-skill-section {
width: 560px;
margin-bottom: 35px;
margin-right: 30px;
border-radius: 8px;
padding: 24px 16px;
background-color: #fff;
box-shadow: 0px 5px 20px -1px rgba(0, 0, 0, 0.55);
position: relative;
display: block;
}
Alternatively, you could apply these styles directly to the :host element in the CSS for the new component:
:host {
width: 560px;
margin-bottom: 35px;
margin-right: 30px;
border-radius: 8px;
padding: 24px 16px;
background-color: #fff;
box-shadow: 0px 5px 20px -1px rgba(0, 0, 0, 0.55);
position: relative;
display: block;
}

css - remove white space below anchor tag

See if i can get it working here: https://codepen.io/canovice/pen/pVoBXJ
I have searched a bit for this answer but have had no luck resolving the issue. Here is a screenshot of an anchor tag in a react component of mine:
Notice the 3px margin (orange) and 3px padding (green), and also notice that below the text is a massive amount of white space that I would like to get rid of, but am struggling to do so. Any help is appreciated.
*Note: I've tried the suggestions at this link here with no luck...
*Edit: let me know if theres more i can share on my app, ie. the current stylings, that will help.
Javascript for the React component:
import React from 'react';
import FaTwitter from 'react-icons/lib/fa/twitter';
import './TopPageHeader.css'
const TopPageHeader = () =>
<div className="top-page-container">
Canova's Analytics Dashboards
<div className="social-links">
<a href="https://twitter.com/SmokeyCanova">
<FaTwitter />
</a>
</div>
</div>
export default TopPageHeader;
and CSS:
.top-page-container {
padding: 15px 20px;
margin: 0;
min-height: 30px;
height: auto;
width: 100%;
border-bottom: 1px solid #000;
display: flex;
justify-content: space-between;
}
.top-page-container a {
/*display: block;*/
/*height: auto;*/
vertical-align: bottom;
padding: 3px;
margin: 3px;
font-size: 1.75em;
/*padding: 15px 0px;*/
color: #000;
}
.top-page-container .social-links {
font-size: 1.75em;
/*padding: 15px 0px;*/
}
Lastly, here's what the component looks like on the top of my page. Canova Analytics Dashboard is not centered, but rather offcenter up a bit (due to this extra white space below the anchor tag)... Ideally, the vertical center of the text, and the vertical center of the twitter logo, would both be vertically centered on the div they are contained in.
Here's what the component is contained within...
This is a top page header component, and hence nothing before it. I don't think the css is being impacted anywhere else, but i could be wrong.
You're using flexbox on your .top-page-container element, with a min-height. This is then correctly forcing the child element to occupy the full container height.
Add the align-items property of .top-page-content with something like flex-start, center, etc.
.top-page-container {
padding: 15px 20px;
margin: 0;
min-height: 30px;
height: auto;
width: 100%;
border-bottom: 1px solid #000;
align-items: flex-start; // <-- add this
display: flex;
justify-content: space-between;
}
.top-page-container a {
/*display: block;*/
/*height: auto;*/
vertical-align: bottom;
padding: 3px;
margin: 3px;
font-size: 1.75em;
/*padding: 15px 0px;*/
color: #000;
}
.top-page-container .social-links {
font-size: 1.75em;
/*padding: 15px 0px;*/
}
<div class="top-page-container">
Canova's Analytics Dashboards
<div class="social-links">
<a href="https://twitter.com/SmokeyCanova">
<FaTwitter />
</a>
</div>
</div>
Play with the line-height CSS property.
For example set it to 1 or 0.
You haven't provide any example code though.

Resources