When click on sidebar menu in right side routes page display - css

I have sideNavbar and when click on side bar menu return menu componetns on the right side.
Below i have mention the image just look same output want.
Sandboxlink:https://m7tqt3.csb.app/
SideNavbar.js
---
import "./SideNavBar.css";
const SideNavBar = () => {
const menuItems = [
{
text: "Dashboard",
icon: "icons/grid.svg",
},
{
text: "Admin Profile",
icon: "icons/user.svg",
},
{
text: "Messages",
icon: "icons/message.svg",
},
{
text: "Analytics",
icon: "icons/pie-chart.svg",
},
{
text: "File Manager",
icon: "icons/folder.svg",
},
{
text: "Orders",
icon: "icons/shopping-cart.svg",
},
{
text: "Saved Items",
icon: "icons/heart.svg",
},
{
text: "Settings",
icon: "icons/settings.svg",
},
];
return (
<div
className={
"side-nav-container"
}
>
<div className="nav-upper">
<div className="nav-heading">
(
<div className="nav-brand">
<img src="icons/Logo.svg" alt="" srcset="" />
<h2>Showkart</h2>
</div>
)
</div>
<div className="nav-menu">
{menuItems.map(({ text, icon }) => (
<a
className={ "menu-item"}
href="#"
>
<img className="menu-item-icon" src={icon} alt="" srcset="" />
{ <p>{text}</p>}
</a>
))}
</div>
</div>
</div>
);
};
export default SideNavBar;
SideNavbar.css
/* NX = not expanded */
.side-nav-container {
background-color: var(--dark);
width: 300px;
height: 100vh;
position: relative;
color: var(--light);
transition: 0.4s;
}
.side-nav-container-NX {
width: 85px;
}
.nav-upper,
.nav-heading,
.nav-menu,
.menu-item,
.nav-footer {
/* border: 2px solid white; */
display: grid;
}
.nav-heading {
grid-template-columns: 2fr 1fr;
grid-template-rows: 1fr;
height: 75px;
}
.nav-brand {
display: flex;
color: var(--light);
}
.nav-brand img {
width: 40px;
padding: 0 10px;
}
.hamburger {
background: none;
border: none;
cursor: pointer;
margin: auto;
}
.hamburger span {
display: block;
margin-top: 5px;
background-color: var(--light);
border-radius: 15px;
height: 5px;
width: 35px;
transition: 0.4s;
}
.hamburger:hover span {
background-color: var(--primary);
}
.hamburger-in:hover span:nth-child(1) {
width: 25px;
transform: translateY(4px) rotate(-25deg);
}
.hamburger-in:hover span:nth-child(2) {
width: 40px;
}
.hamburger-in:hover span:nth-child(3) {
width: 25px;
transform: translateY(-4px) rotate(25deg);
}
/* ///////////////////// */
/* ///////////////////// */
/* ///////////////////// */
/* ///////////////////// */
.hamburger-out {
margin-left: 24px;
}
.hamburger-out:hover span:nth-child(1) {
width: 25px;
transform: translate(14px, 4px) rotate(-155deg);
}
.hamburger-out:hover span:nth-child(2) {
width: 40px;
}
.hamburger-out:hover span:nth-child(3) {
width: 25px;
transform: translate(14px, -4px) rotate(155deg);
}
.nav-menu {
grid-template-rows: repeat(7, 1fr);
margin-top: 50px;
}
.menu-item {
height: 57px;
display: flex;
color: var(--light);
text-decoration: none;
text-transform: uppercase;
margin: auto 20px;
border-radius: 10px;
}
.menu-item-NX {
margin: auto;
}
.menu-item:hover {
background-color: var(--primary);
}
.menu-item img {
width: 30px;
padding: 0 20px;
}
.nav-footer {
width: 100%;
height: 87px;
position: absolute;
bottom: 0;
grid-template-rows: 1fr;
grid-template-columns: 2fr 1fr;
}
.nav-details {
display: flex;
}
.nav-details img {
width: 50px;
padding: 0 20px;
}
.nav-footer-user-name {
font-size: 18px;
font-weight: 900;
}
.nav-footer-user-position {
margin-top: -15px;
color: var(--gray);
}
.logout-icon {
width: 30px;
margin: auto;
border-radius: 90px;
padding: 20px;
margin-left: 5px;
}
.logout-icon:hover {
background-color: var(--primary);
}
Notes: React router dom version: 5.3.1.
Output look like:
enter image description here
Routes to another components on right side

Firstly, if I undestand your question, you want a side navbar which allows you to navigate to different pages with your react app. If so:
<div className="nav-menu">
{menuItems.map(({ text, icon }) => (
<a <--- The problem is here
className={ "menu-item"}
href="#"
>
<img className="menu-item-icon" src={icon} alt="" srcset="" />
{ <p>{text}</p>}
</a>
))}
</div>
You are using anchor tag which will redirect you out of react router. You should use Link tag which allows to redirect to different pages within your react app.
const menuItems = [
{
text: "Dashboard",
icon: "icons/grid.svg",
navLink:'/dashboard'
},
{
text: "Admin Profile",
icon: "icons/user.svg",
navLink:'/admin'
},...]
<div className="nav-menu">
{menuItems.map(({ text, icon, navlink }) => (
<Link
className={ "menu-item"}
to={navlink}
>
<img className="menu-item-icon" src={icon} alt=""
srcset=""
/>
{ <p>{text}</p>}
</Link>
))}
</div>
Likewise you need to step up your App.js with BrowserRouter, Routes and Route to move between pages.

Related

Converting a react made responsive navbar into nextjs navbar

I am trying to convert a react made responsive navbar component into next js navbar component. I don't know much about next js. Can anyone help with this code.The responsiveness works just fine. However, I cannot close the hamburger menu once I clicked it. The issue is with close Hamburger menu button. Here is the navbar component code converted from React js app:
import React from 'react';
import React from 'react';
import { GiHamburgerMenu } from 'react-icons/gi';
import { MdOutlineRestaurantMenu } from 'react-icons/md';
import Image from "next/image";
import styles from "../styles/Navbar.module.css"
const Navbar = () => {
const [toggleMenu, setToggleMenu] = React.useState(false);
return (
<nav className={styles.app__navbar}>
<div className={styles.app__navbar_logo}>
<Image src="/img/ephielogo.png" alt="app__logo" />
</div>
<ul className={styles.app__navbar_links}>
<li className={styles.p__opensans}>Home</li>
<li className={styles.p__opensans}>About</li>
<li className={styles.p__opensans}>Menu</li>
<li className={styles.p__opensans}>Awards</li>
<li className={styles.p__opensans}>Contact</li>
</ul>
<div className={styles.app__navbar_login}>
<a href="#login" className={styles.p__opensans}>Log In / Registration</a>
<div />
<a href="/" className={styles.p__opensans}>Book Table</a>
</div>
<div className={styles.app__navbar_smallscreen}>
<GiHamburgerMenu color="#fff" fontSize={27} onClick={() => setToggleMenu(true)} />
{toggleMenu && (
<div className={styles["app__navbar_smallscreen_overlay"] + " " + styles["flex__center"] + styles["slide_bottom"]}>
<MdOutlineRestaurantMenu fontSize={27} className="overlay__close" onClick={() => setToggleMenu(false)} />
<ul className={styles.app__navbar_smallscreen_links}>
<li><a href="#home" onClick={() => setToggleMenu(false)}>Home</a></li>
<li><a href="#about" onClick={() => setToggleMenu(false)}>About</a></li>
<li><a href="#menu" onClick={() => setToggleMenu(false)}>Menu</a></li>
<li><a href="#awards" onClick={() => setToggleMenu(false)}>Awards</a></li>
<li><a href="#contact" onClick={() => setToggleMenu(false)}>Contact</a></li>
</ul>
</div>
)}
</div>
</nav>
);
};
export default Navbar;
Here is my Navbar.Module.css code.
.app__navbar {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
background: var(--color-black);
padding: 1rem 2rem;
}
.app__navbar_logo {
display: flex;
justify-content: flex-start;
align-items: center;
}
.app__navbar_logo img {
width: 150px;
}
.app__navbar_links {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
color: var(--color-white);
list-style: none;
}
.app__navbar_links li {
margin: 0 1rem;
cursor: pointer;
}
.app__navbar_links li:hover {
color: var(--color-grey);
}
.app__navbar_login {
display: flex;
justify-content: flex-end;
align-items: center;
}
.app__navbar_login a {
margin: 0 1rem;
text-decoration: none;
transition: .5s ease;
color: var(--color-white)
}
.app__navbar_login a:hover {
border-bottom: 1px solid var(--color-golden);
}
.app__navbar_login div {
width: 1px;
height: 30px;
background: var(--color-grey);
}
.app__navbar_smallscreen {
display: none;
}
.app__navbar_smallscreen_overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background: var(--color-black);
transition: .5s ease;
flex-direction: column;
z-index: 5;
}
.app__navbar_smallscreen_overlay .overlay__close {
font-size: 27px;
color: var(--color-golden);
cursor: pointer;
position: absolute;
top: 20px;
right: 20px;
}
.app__navbar_smallscreen_links {
list-style: none;
}
.app__navbar_smallscreen_links li {
margin: 2rem;
cursor: pointer;
color: var(--color-golden);
font-size: 2rem;
text-align: center;
font-family: var(--font-base);
}
.app__navbar_smallscreen_links li:hover {
color: var(--color-white);
}
#media screen and (min-width: 2000px) {
.app__navbar_logo img {
width: 210px;
}
}
#media screen and (max-width: 1150px) {
.app__navbar_links {
display: none;
}
.app__navbar_smallscreen {
display: flex;
}
}
#media screen and (max-width: 650px) {
.app__navbar {
padding: 1rem;
}
.app__navbar_login {
display: none;
}
.app__navbar_logo img {
width: 110px;
}
}

I need to toggle between an X button and hamburger menu with Bootstrap. I'm using React.js

I'm using the latest version of Bootstrap and want to toggle between the famous X icon and hamburger menu. I don't know if I can actually change the 3 lines of the menu since it's by default, but these 2 icons presently overlap each other.
So there are 2 questions here:
How can I toggle these two icons?
When the menu is clicked, it should have a complete white background (right now it doesn't completely cover the screen in white)
Sorry I don't have a sandbox example for you right now.
Thanks for your input!
/*JSX code*/
import React from 'react';
import { NavigationBarStyled } from './style';
import { Nav, Navbar } from 'react-bootstrap';
//IMAGES
import logo from '../../images/adyslogo.png';
import Image from 'react-bootstrap/Image';
import { GrCart } from 'react-icons/gr';
import CloseButton from '../../images/closebutton.svg';
const NavigationBar = () => {
return (
<NavigationBarStyled>
<Navbar expand='sm' fixed='top'>
<Navbar.Brand href='/'><Image src={logo} className='logo'/></Navbar.Brand>
<div className='close-button'>
<button type="button" className="x-closebutton" aria-label="Close">
<img src={CloseButton} className='x-button' alt="close configuration" draggable="false" />
</button>
<Navbar.Toggle aria-controls='basic-navbar-nav' className='hamburger-menu'/>
</div>
<Navbar.Collapse id='basic-navbar-nav'>
<Nav className='mr-auto'>
<Nav.Item><Nav.Link href='/' className="middle-menu">HOME</Nav.Link></Nav.Item>
<Nav.Item><Nav.Link href='/about' className="middle-menu">ABOUT</Nav.Link></Nav.Item>
<Nav.Item><Nav.Link href='/menu' className="middle-menu">MENU</Nav.Link></Nav.Item>
<Nav.Item><Nav.Link href='/gallery' className="middle-menu">GALLERY</Nav.Link></Nav.Item>
<Nav.Item><Nav.Link href='/contact' className="middle-menu">CONTACT</Nav.Link></Nav.Item>
</Nav>
<Nav className='ml-auto'>
<Nav.Item><Nav.Link href='/cart'><GrCart size='25px' className='cart'/></Nav.Link></Nav.Item>
</Nav>
</Navbar.Collapse>
</Navbar>
</NavigationBarStyled>
)
}
export default NavigationBar;
/*CSS*/
import styled from 'styled-components';
export const NavigationBarStyled = styled.nav`
.navbar {
background-color: #FFF;
height: 80px;
}
.navbar-brand, .navbar-nav .nav-link {
color: #273746 ;
font-size: 1rem;
font-weight: 600;
&:hover {
color: rgb(255, 20, 147);
}
}
.logo {
max-height: 60px;
max-width: 60px;
}
.middle-menu {
margin: 20px;
}
.cart {
margin-right: 50px;
}
.close-button {
display: flex;
align-items: flex-start;
justify-content: flex-start;
}
.x-closebutton {
display: flex;
align-items: flex-start;
justify-content: flex-start;
border: none;
background-color: #fff;
margin-right: -54px;
}
.x-button {
display: flex;
width: 45px;
height: 45px;
cursor: pointer;
}
.hamburger-menu {
border: none;
color: #000;
}
.mr-auto {
display: flex;
align-items: center;
background-color: white;
min-width: 100vw;
min-height: 100vh;
}
`;
It's actually rather easy to toggle state but, keep in mind you won't have the graceful height calculation which comes with Bootstrap.
I'll comment out what doesn't seem important to this answer...
import React, { Component } from "react";
//import { Link } from "gatsby";
//import Image from "./image";
import "../../scss/molecules/_topnav.scss";
//const helpers = require("../../helpers");
class Nav extends Component {
state = { collapse: true };
/*
componentDidMount() {
helpers.useIntersect(".navbar-collapse", "navbar-collapsed");
}
*/
constructor(props) {
super(props);
this.brandLogo = this.props.brandLogo;
this.listItems = this.props.pages
//.sort((a, b) => (a.node.navigationOrder || 100) - (b.node.navigationOrder || 100))
.map((page) => page.node.slug && page.node.pageName && !page.node.hideInNavigation && (
<li className="nav-item" key={page.node.id}>
<Link to={`${page.node.slug}`} className="nav-link" title={page.node.pageName}>{page.node.pageName}</Link>
</li>)
);
}
render() {
return (
<>
<nav className={[
"navbar",
"navbar-expand-lg",
"navbar-light",
"fixed-top",
this.state.collapse ? "" : "active"].join(" ")}
>
<a className="navbar-brand" href="/"><Image fluid={this.brandLogo} /></a>
<button
className="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#topnav"
aria-controls="topnav"
aria-expanded={!this.state.collapse}
aria-label="Toggle navigation" onClick={() => {
this.setState({ collapse: !this.state.collapse });
}
}>
<span className="navbar-toggler-icon"></span>
</button>
<div
className={[
"collapse",
"navbar-collapse",
"fade",
!this.state.collapse ? "show" : "",
].join(" ")} id="topnav">
<ul className="navbar-nav ml-lg-auto">{this.listItems}</ul>
</div>
</nav>
</>
);
}
}
export default Nav;
SCSS solution to cover state and mobile -vs- desktop navigation
A simple toggle between display "none" and "block". You can transition transforms to counter the missing height calculation.
We'll use the proper content characters to cover the icons.
It's a bit too much but I'll leave this file complete.
#import "../variables";
#import "../functions";
#import "../vendor/bootstrap/functions";
#import "../vendor/bootstrap/variables";
#import "../vendor/bootstrap/mixins";
#import "../vendor/bootstrap/transitions";
.navbar {
&.navbar-light {
transition: all ease 0.2s;
.navbar-brand {
transition: all ease 0.2s;
.image {
height: auto;
width: rem-value(142);
}
}
.nav-item {
align-items: center;
display: flex;
}
.nav-link {
font-family: $font-family-monospace;
font-size: rem-value(20);
}
#include media-breakpoint-up(md) {
.navbar-collapse {
&:not(.show) {
opacity: 1;
}
}
.nav-item {
margin: auto 1rem;
}
}
#include media-breakpoint-up(lg) {
.nav-item {
&:last-child {
.nav-link {
background-color: $primary;
border-radius: rem-value(3);
color: $white;
margin-left: 1.5rem;
&:hover,
&:active,
&:focus {
background-color: $brand-primary-headings;
}
}
}
}
}
#include media-breakpoint-down(md) {
background-color: $white;
box-shadow: 0 0 1px 1px $gray-300;
padding-top: 0;
padding-bottom: 0;
.navbar-brand {
transform: scale(0.65);
transform-origin: left;
padding-top: 0;
padding-bottom: 0;
}
.navbar-collapse {
&.collapse {
background: white;
margin: 0 -1rem;
height: 0;
transform: scale(0);
transform-origin: top center;
transition: all ease 0.5s;
padding: 1rem;
position: relative;
&.show {
height: calc(100vh - 80px);
transform: scale(1);
}
}
}
.navbar-toggler {
&[aria-expanded="true"] {
.navbar-toggler-icon {
background-image: none;
position: relative;
&:before {
content: "\00d7";
font-family: sans-serif;
font-size: rem-value(40);
line-height: 0.8;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
}
}
}
.nav-item {
border-bottom: 1px solid $gray-300;
margin: 0;
position: relative;
&:before {
content: "\203A";
line-height: 1.2;
font-size: rem-value(30);
color: $brand-primary-headings;
position: absolute;
right: 0.5rem;
width: rem-value(40);
height: rem-value(40);
text-align: center;
}
}
.nav-link {
line-height: 1.8;
width: 100%;
}
}
#at-root .scrolled & {
background-color: $white;
box-shadow: 0 0 1px 1px $gray-300;
padding-top: 0;
padding-bottom: 0;
.navbar-brand {
transform: scale(0.65);
padding-top: 0;
padding-bottom: 0;
}
}
}
}
Example can be seen at devlab.career
Hopefully with this example you can implement this too.

CSS Grid - Content overlapping issue

Is it possible to create the following layout using CSS grid?
The layout itself is pretty straightforward. Here's what I have so far:
HTML:
<div class="sidebar__wrapper">
<div class="sidebar__item mb-1" [class.mt-3]="item.options.length"
*ngFor="let item of sidebarItems; let first = first;">
<div class="sidebar__icon ark-cursor-pointer" [class.align-self]="item.options.length" (click)="item.isExpand = !item.isExpand">
<img [src]="item.icon" alt="icon" [class.valign--middle]="item.options.length">
</div>
<div class="sidebar__label font--14">
<div *ngIf="!showItemTitle"></div>
<a class="sidebar__header pl-1" [routerLink]="item.stateName" [class.font--light]="!item.options.length" [ngClass]="{'font--11 text-uppercase sidebar__header--blue' : item.options.length}" (click)="item.isExpand = !item.isExpand"
*ngIf="showItemTitle">{{ 'Sidebar.' + item.property + '.Title' | translate}}</a>
<ng-container *ngFor="let subItem of item.options; let first = first">
<a class="sidebar__subheader pl-1" [routerLink]="subItem.stateName" [class.mt-2]="first"
*ngIf="showItemTitle && item.isExpand" [ngClass]="hasActiveChild(subItem)"><span>{{ 'Sidebar.' + item.property +'.'+ subItem.subtitle | translate}}</span></a>
</ng-container>
</div>
</div>
CSS:
.sidebar__wrapper,
.sidebar__item,
.sidebar__label {
display: grid;
}
.sidebar__wrapper {
align-items: flex-start;
grid-template-columns: 100%;
}
.sidebar__item {
/* grid-template-columns: 20px auto 20px; */
grid-template-columns: 20px auto;
margin: 0 15px 0 8px;
align-items: center;
column-gap: 5px;
}
.sidebar__label {
align-items: center;
row-gap: .5rem;
grid-template-columns: 100%;
grid-auto-rows: 23px;
}
.font--14 {
font-size: 14px;
}
.font--11 {
font-size: 11px;
}
.sidebar__header {
font-weight: var(--bold-font-weight);
}
.sidebar__subheader {
font-weight: var(--light-font-weight);
}
.sidebar__icon {
justify-self: center;
}
.sidebar__icon img {
height: 15px;
width: auto;
vertical-align: unset;
}
#side-bar a {
text-decoration: none;
list-style-type: none;
color: #FFFFFF;
}
#side-bar .active-text-bold {
background-color: rgba(104, 131, 158, 0.31);
border-radius: 5px;
padding: .25em .125rem;
width: calc(100% + 5px);
}
.align-self {
align-self: flex-start;
}
.valign--middle {
vertical-align: middle !important;
}
.sidebar__header--blue {
color: rgba(111,140,169, 0.8) !important;
}
The object sidebarItems looks as such:
const sidebarItems = [
{
icon: 'assets/images/icon/sidebar_time.png',
isExpand: false,
title: 'Gestion du temps',
property: 'TimeManagement',
stateName: '/time/stats',
options: [
{
subtitle: 'AccountChart',
stateName: '/accounting/accounts'
}
]
},
{
icon: 'assets/images/icon/sidebar_contacts.png',
property: 'Contact',
isExpand: true,
stateName: '/contacts/list',
options: []
}
];
hasActiveChild(item) {
let className = '';
if (location.pathname.includes(item.stateName)) {
className = 'active-text-bold';
}
return className;
}
The above code creates the following layout:
However, I'm unable to re-create the spacing on the left of each sub-item.
I've tried to name the grid lines and set the grid-column: 2/4. It somehow messes up the layout.
If you have some ideas on how I can solve this issue, please let me know. Thank you.
Thanks.
Please look into the CSS padding property.
In your case, adding a left padding to the links should do.
Try this:
.sidebar__item {
/* grid-template-columns: 20px auto 20px; */
grid-template-columns: 20px auto;
margin: 0 15px 0 8px;
align-items: center;
column-gap: 5px;
padding-left: 5px;
}

I have a VueJs 3 menu component and need to set cursor for selected element on render

I'm so far really pleased with how simple it was to setup a menu that has a sliding cursor to show where you are hovering:
<template>
<div class="menu">
<div class="logo">
<span>**Logo Here **</span>
</div>
<div class="menuBar" ref="menuBar">
<ul>
<li v-for='topLevel in menu' :key='topLevel.id' :ref='topLevel.id' v-on:mouseover="moveCursor(topLevel.id)" >
<span><a :href="/topLevel.link/">{{ topLevel.text }}</a></span>
<ul>
<li v-for='child in topLevel.children' :key='child.text'>
<span><a :href="/child.link/">{{ child.text }}</a></span>
</li>
</ul>
</li>
</ul>
<div class="cursor" :style="{ left: cursorPosition, width: cursorWidth, visibility: cursorVisible }" ></div>
</div>
</div>
</template>
<script>
import { ref } from 'vue';
export default {
name: 'Header',
setup() {
const cursorPosition = ref('0px');
const cursorWidth = ref('0px');
const cursorVisible = ref('visible');
const menu = ref([
{
text: 'Device Access',
id: 'device_access',
children: [
{
text: 'Interactive',
link: '/connection_center'
},{
text: 'Reservation',
link: '/reserve_probe'
}, {
text: 'Reservation Vue',
link: '/reservation.html'
}
]
}, {
text: 'Automation',
id: 'automation',
children: [
{
text: 'Builder',
link: '/builder',
},{
text: 'Execution Results',
link: '/test_suite_execution_results'
},
]
}, {
text: 'Site Admin',
id: 'site_admin',
children: [
{
text: 'Accounts',
link: '/admin_accounts',
},{
text: 'Settings',
link: '/admin_settings',
}
]
},{
text: 'Reporting',
id: 'reporting',
children: [
{
text: 'Administrative',
link: '/administrative_reporting'
},{
text: 'Historical',
link: '/historical_reporting'
},
]
}, {
text: 'Help',
id: 'help',
children: [
{
text: 'User Documentation',
link: '/docs/'
},{
text: 'API Documentation',
link: '/apidocsindex'
}
]
}
]);
return {
menu,
cursorPosition,
cursorWidth,
cursorVisible
}
},
methods: {
mouseover: function(refId) {
this.moveCursor(refId);
},
selectCurrent: function() {
this.moveCursor(this.selectedMenuRef);
},
moveCursor: function(refId) {
var menuRect = this.$refs.menuBar.getBoundingClientRect();
var refItem = this.$refs[refId];
var width = refItem.offsetWidth;
var itemRect = refItem.getBoundingClientRect();
this.cursorPosition = (itemRect.left - menuRect.left) + "px";
this.cursorWidth = width + "px";
}
}
// {
// link: '/Session/logout', text: 'Logout',
// [
// { link: '#' event='preferences', text: 'Preferences',
// ]
// }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
#import "../styles/_colors.scss";
div.menu {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 65px;
background: $headerBackground;
border-bottom: 3px solid $headerBorder;
> .logo {
height: 72px;
padding-left: 10px;
padding-top: 3px;
float: left;
}
> .menuBar {
float: left;
height: calc(100% - 20px);
width: 900px;
margin: 15px 0 0 50px;
float: left;
position: relative;
> .cursor {
position: absolute;
height: 3px;
background: $menuCursor;
transition: left 0.2s ease-in-out, width 0.3s ease-in-out;
}
ul {
list-style-type: none;
display: block;
padding: 0;
margin: 0;
}
> ul {
width: 100%;
display: block;
> li {
float: left;
display: block;
text-indent: none;
position: relative;
margin: 0;
padding: 12px 25px 18px 15px;
&::after {
position: absolute;
top: 21px;
right: 10px;
width: 4px;
height: 4px;
border-bottom: 1px solid #000000;
border-right: 1px solid #000000;
content: "";
transform: rotate(45deg);
transition: border-color 0.2s ease;
}
&:hover {
> span > a {
color: $menuHover;
}
> ul {
height: auto;
transition: all;
transition-duration: 0.1s;
border: 1px solid $menuBorder;
border-top: none;
}
}
> span {
text-align: left;
font-size: 14px;
line-height: 16px;
> a {
text-decoration: none;
color: $menuText;
text-transform: uppercase;
}
}
> ul {
height: 0;
position: absolute;
top: 50px;
left: 0;
width: 175px;
background: $headerBackground;
border: none;
overflow: hidden;
margin: 0;
padding: 0;
> li {
margin: 0;
display: block;
padding: 0px 5px 10px 20px;
> span {
text-align: left;
font-size: 14px;
line-height: 16px;
> a {
text-decoration: none;
color: $menuText;
}
}
&:hover > span > a {
color: $menuHover;
}
}
}
}
}
}
}
</style>
I want to run the method selectCurrent after the menu is rendered to have the cursor hover over the current selected menu option, but everything I've tried so far blows up in undefined refs.
Call the method in the onMounted hook in setup().
onMounted(() => {
console.log('mounted!');
call the selectCurrent method here
})
Don't forget to import it:
import { onMounted, ref} from 'vue'

Make Parent Div Wrap Around Dynamic Absolute Child Div (Tabs + Content)

I need the content below the (tabs+selected-content) to respect the space of the absolute selected-content currently being displayed on the page within the parent container of relative. Anyone have any ideas how to do this?
code sandbox: https://codesandbox.io/s/tabs-content-space-respected-m0gql
Files
App.js
import "./styles.css";
import TabsWithContent from "./Components/TabsWithContent.js";
export default function App() {
return (
<div>
<TabsWithContent />
<h1 style={{textAlign: "center"}}>I am the next content, please respect my space</h1>
</div>
);
}
Components\TabsWithContent.js
import React, { useState } from "react";
// Data from backend
import { tabOneContent, tabTwoContent, tabThreeContent } from '../BackendData/TabsContent.js';
const TabsWithContent = () => {
// Variables
const [tabSelected, setTabSelected] = useState(1);
// Functions
const changeTab = (ev, tabNum) => {
ev.preventDefault();
setTabSelected(tabNum);
};
// Render
return (
<div className="div-tabs-with-content">
<div className="page-container-content">
<h2>Tabs Example</h2>
<div className="div-tabs">
<button onClick={ev => changeTab(ev, 1)} style={tabSelected === 1 ? {color: "#ffffff", backgroundColor: "#003478"} : {}}>Tab One</button>
<button onClick={ev => changeTab(ev, 2)} style={tabSelected === 2 ? {color: "#ffffff", backgroundColor: "#003478"} : {}}>Tab Two</button>
<button onClick={ev => changeTab(ev, 3)} style={tabSelected === 3 ? {color: "#ffffff", backgroundColor: "#003478"} : {}}>Tab Three</button>
</div>
<div className="div-tabs-content-container">
<section className={tabSelected === 1 ? "div-tabs-content active" : "div-tabs-content"}>
{tabOneContent.map((content, index) =>
<div key={index}><i className="fa fa-check"></i><p>{content}</p></div>
)}
</section>
<section className={tabSelected === 2 ? "div-tabs-content active" : "div-tabs-content"}>
{tabTwoContent.map((content, index) =>
<div key={index}><i className="fa fa-check"></i><p>{content}</p></div>
)}
</section>
<section className={tabSelected === 3 ? "div-tabs-content active" : "div-tabs-content"}>
{tabThreeContent.map((content, index) =>
<div key={index}><i className="fa fa-check"></i><p>{content}</p></div>
)}
</section>
</div>
</div>
</div>
);
};
export default TabsWithContent;
BackendData\TabsContent.js
const tabOneContent = ["Content One", "Content Two", "Content Three"];
const tabTwoContent = ["Content One", "Content Two", "Content Three", "Content Four", "Content Five", "Content Six"];
const tabThreeContent = ["Content One", "Content Two", "Content Three", "Content Four", "Content Five", "Content Six", "Content Seven", "Content Eight"];
export {
tabOneContent,
tabTwoContent,
tabThreeContent
}
index.css
.App {
font-family: sans-serif;
}
.page-container-content {
display: block;
position: relative;
width: 100%;
max-width: 1200px;
padding: 0 25px 0 25px;
margin: 0 auto;
}
.div-tabs-with-content {
display: block;
width: 100%;
margin-bottom: 60px;
}
.div-tabs-with-content h2 {
margin-bottom: 20px;
color: #003478;
font-family: sans-serif;
font-size: 2.8rem;
font-weight: 700;
line-height: 36px;
text-align: center;
}
.div-tabs {
display: flex;
justify-content: space-around;
margin-bottom: 2rem;
}
.div-tabs button {
height: 50px;
width: 210px;
color: #003478;
background-color: #ffffff;
border: none;
font-family: sans-serif;
font-size: 2.4rem;
font-weight: 600;
line-height: 3.6rem;
outline: none;
cursor: pointer;
}
.div-tabs button:hover {
opacity: 0.7;
color: white;
background-color: #003478;
transition: 0.2s ease-in;
}
.div-tabs-content-container {
display: block;
position: relative;
width: 100%;
}
.div-tabs-content {
position: absolute;
left: 26%;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
width: 100%;
max-width: 600px;
visibility: hidden;
opacity: 0;
}
.div-tabs-content-container .active {
transition: opacity 0.75s;
visibility: visible;
opacity: 1;
}
.div-tabs-content div {
display: flex;
align-items: center;
width: 200px;
}
.div-tabs-content i {
width: 24px;
height: 24px;
font-size: 1.6rem;
padding: 2.5px;
margin-right: 10px;
font-weight: 300;
color: #003478;
border: 2px solid #003478;
border-radius: 50%;
}
.div-tabs-content p {
color: #000000;
font-size: 1.6rem;
font-weight: 300;
line-height: 26px;
}
Check the working solution - https://codesandbox.io/s/tabs-content-space-respected-forked-lzrkh
.div-tabs-content-container .active {
transition: opacity 0.75s;
visibility: visible;
opacity: 1;
position: relative; /* you can use unset also */
}
I think it solved your problem.

Resources