My bootstrap column classes are not working.
It's coming in a single line.
My code:
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import axios from 'axios';
class PLPMenu extends Component {
state = {
shoeCategory: []
}
componentDidMount() {
const url = 'GirlShoeCategory'
axios.get(`http://localhost:3030/${url}`)
.then(res => {
console.log(res.data.express.catalogEntryView);
this.setState({
shoeCategory: res.data.express.catalogEntryView
})
})
}
render() {
const { shoeCategory } = this.state;
return (
<div>
{
shoeCategory.map(shoeList => (
<div className="container">
<div className="row">
<div className="col-md-4">
<h2 key={shoeList.uniqueID}></h2>
<Link to="/PDP"><p className="pdp">{shoeList.name}</p></Link>
</div>
</div>
</div>
))
}
</div>
)
}
}
export default PLPMenu;
index.css
.header{
display:inline-flex;
vertical-align: top;
list-style-type: none;
}
.header .dropbtn {
font-size: 16px;
border: none;
color: #111;
padding: 14px 16px;
margin: 0;
background: inherit;
}
.header:hover .dropbtn {
background-color: #00b5cc;
}
.dropdown-content {
list-style-type: none;
margin: 0px;
padding: 0px;
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content li a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content li a:hover {
background-color: #ddd;
}
.header:hover .dropdown-content {
display: block;
}
.drop-button {
font-size: 16px;
border: none;
color: #111;
padding: 14px 16px;
margin: 0;
background: inherit;
}
.sub-menu{
list-style-type: none;
display:none;
}
.dropdown-content:hover .submenu{
background-color: red;
}
.dropdown-content li:hover .sub-menu {
display: block;
}
.pdp{
height:200px;
background-color: #ddd;
width: 350px;
}
img{
width:100%;
}
I have imported bootstrap classes in the App.js file
import "../node_modules/bootstrap/dist/css/bootstrap.min.css";
but still the bootstrap columns classes are not working. Can anybody please help me on this. I'm not able to figure it out.
I think your error here is that when you map your data, you include the .row div. You might want to try this:
<div>
<div className="container">
<div className="row">
{
shoeCategory.map(shoeList => (
<div className="col-md-4">
<h2 key={shoeList.uniqueID}></h2>
<Link to="/PDP"><p className="pdp">{shoeList.name}</p></Link>
</div>
))
}
</div>
</div>
</div>
Related
my button can't compile and the mistake is:"./src/components/Button.js
Line 2: 'React' must be in scope when using JSX react/react-in-jsx-scope". Does anybody know the problem? pls help! Thank you!
"This is my Header.js:
import PropTypes from 'prop-types';
import Button from './Button'
const Header = ({title}) => {
return (
<header className="header">
<h1>{title}</h1>
<Button />
</header>
)
}
Header.defaultProps ={
title:'Task Tracker '
}
Header.propTypes={
title:PropTypes.string.isRequired,
}
// css in js
// const headingStyle = {
// color:'red',
// backgroundColor:'blue'
// }
export default Header
This is my Button.js:
const Button = () => {
return <button className="btn">Add</button>
}
export default Button
My Header.js and Button.js are inside my components folder which is inside my src folder
This is my index.css which is inside my src folder too:
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#300;400&display=swap');
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Poppins', sans-serif;
}
.container {
max-width: 500px;
margin: 30px auto;
overflow: auto;
min-height: 300px;
border: 1px solid steelblue;
padding: 30px;
border-radius: 5px;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.btn {
display: inline-block;
background: #000;
color: #fff;
border: none;
padding: 10px 20px;
margin: 5px;
border-radius: 5px;
cursor: pointer;
text-decoration: none;
font-size: 15px;
font-family: inherit;
}
.btn:focus {
outline: none;
}
.btn:active {
transform: scale(0.98);
}
.btn-block {
display: block;
width: 100%;
}
.task {
background: #f4f4f4;
margin: 5px;
padding: 10px 20px;
cursor: pointer;
}
.task.reminder {
border-left: 5px solid green;
}
.task h3 {
display: flex;
align-items: center;
justify-content: space-between;
}
.add-form {
margin-bottom: 40px;
}
.form-control {
margin: 20px 0;
}
.form-control label {
display: block;
}
.form-control input {
width: 100%;
height: 40px;
margin: 5px;
padding: 3px 7px;
font-size: 17px;
}
.form-control-check {
display: flex;
align-items: center;
justify-content: space-between;
}
.form-control-check label {
flex: 1;
}
.form-control-check input {
flex: 2;
height: 20px;
}
footer {
margin-top: 30px;
text-align: center;
}
try this code :
export const Button = () => {
return <button className="btn">Add</button>
}
import {Button} from './Button'
adding on to Vuk Vucic comment:
Vucic mentioned that you need to import React when using functional components, but as of React 17 (if compiled using babel), top line import React from 'react' is no longer needed. You now only need to import react-specific hooks
like import { useEffect() } from 'react';
However, if it isn't comiled via Babel, you need to import React.
in this case, it looks like you do need to import React from 'react';
helpful article
https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html
I am trying to make a box appear that starts at the bottom of the green buttons. For now, it's red. I made the top navbar with CSS Grid, but not the red box. How do make it overlap the navbar?
Here is more (pointless) words it forced me to add since my post is "mostly code". What an absolute joke.
Navbar.js
import React from 'react';
import { BsFillPersonFill } from 'react-icons/bs';
import { FiMail } from 'react-icons/fi';
import { FaPlus, FaSearch } from 'react-icons/fa';
import { AiTwotoneBell, AiOutlineSearch } from 'react-icons/ai';
import './navbar.css';
function Navbar() {
return (
<div>
<nav id="nav-bar">
<div className="container">
<h2 className="homeBtn">VIZZEY</h2>
<div className="search">
<input type="search" placeholder="Search" className="form-control" />
<button className="searchBtn"><AiOutlineSearch /></button>
</div>
<ul className="ugh-buttons">
<li className="btn">
<button className="icon-btn">
<FiMail /></button>
</li>
<li className="btn">
<button className="icon-btn"><FaPlus /></button>
</li>
<li className="btn">
<button className="icon-btn"><AiTwotoneBell /></button>
</li>
<li className="btn">
<button className="icon-btn"><BsFillPersonFill /></button>
</li>
</ul>
</div>
</nav>
<div>
<div className="container">
<h2 className="homeBtn hide"></h2>
<div className="search">
</div>
<div className="container col-sm-4" xs={6}>
<div className="card" style={{width: "200px", height: "300px", padding: "20px"}}>
<h5 className="text-center" > </h5>
<a className="text-center">
</a>
<p className="text-center"></p>
</div>
</div>
{/* <li className="btn">
<div className="dropdown">lol</div>
</li> */}
</div>
</div>
</div>
)
}
export default Navbar;
navbar.css
* {
margin:0;
padding:0;
box-sizing:border-box;
}
ul {
list-style: none;
display: flex;
}
li {
list-style: none;
}
a {
text-decoration: none;
color: #fff;
}
.homeBtn {
text-align: center;
justify-content: center;
padding-left: 25%;
color:#00ce7f;
}
#nav-bar {
background-color: #626466;
overflow: hidden;
}
.container {
display: grid;
grid-template-columns: 1fr 6fr 1fr;
align-items: center;
height: 55px;
}
.form-control {
background-color: rgb(255, 255, 255);
border-color: rgb(133, 133, 133);
border-top-left-radius: 5px !important;
border-bottom-left-radius: 5px !important;
height: 38px;
width: 70%;
border: none;
padding-left: 10px;
font-size: 20px;
}
.search {
padding-left: 15%;
}
.btn {
padding-right: 10px;
}
.ugh-buttons {
padding-right: 20px;
}
.icon-btn {
height: 40px;
width: 40px;
border-radius: 5px;
background-color: #00ce7f;
color: white;
border: none;
font-size: x-large;
}
button:active {
outline: none !important;
box-shadow: none !important;
background-color: rgb(111, 0, 255);
}
button:focus {
outline: none !important;
box-shadow: none !important;
}
button:hover {
cursor: pointer;
}
.searchBtn {
color: #fff;
background-color: #00ce7f;
height: 38px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
width: 40px;
border: none;
font-size: large;
}
.buttons {
color: #fff;
background-color: #00ce7f;
height: 38px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
width: 40px;
border: none;
}
[type="search"]::-webkit-search-cancel-button,
[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
appearance: none;
}
input {
outline: none;
}
.profileSettings {
background-color: red;
padding-left: 50px;
padding-right: 50px;
text-align: center;
width: 100px;
border: rgb(111, 0, 255);
border-style: solid;
}
.hide {
visibility: hidden;
}
.dropdown {
height: 120px;
width: 40px;
border-radius: 5px;
background-color: #00ce7f;
color: white;
border: none;
font-size: x-large;
}
.card {
background-color: red;
}
In this case, I would like to make the sidebar fixed. This will also make sure that the sidebar will overlap over the navbar, and you will have the full-screen sidebar.
The following snippet should work for you.
.sidebar { position: fixed; top: 0; right: 0; height: 100vh; width: 350px; background: red; z-index: 1; }
I have this html:
<div class="banner-right">
<img src="images/circle-icon.png" alt="">
<p class="rotate mt-40">和小物</p>
<p class="rotate mta">和小物</p>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
</div>
I want to select the first and last p element so that I can increase it's font size to 20px and 15px
My scss code:
.banner-right {
width: 122px;
max-width: 100%;
display: flex;
align-items: center;
flex-direction: column;
padding-top: 15px;
margin: 0 auto;
img {
width: 25px;
}
.swiper-pagination {
position: relative;
}
.swiper-pagination-bullet {
border-radius: 0;
margin-right: 5px;
background-color: transparent;
border: 1px solid #000;
&.swiper-pagination-bullet-active {
background-color: #000;
outline: 0;
}
}
&:first-of-type {
p {
font-size: 20px;
}
}
&:last-of-type {
p {
font-size: 15px;
}
}
}
But doesn't work :(
At the moment, your Sass will compile to:
.banner-right:first-of-type p
But you want it to be:
.banner-right p:first-of-type
So change your Sass as follows:
.banner-right {
p:first-of-type {
font-size: 20px;
}
p:last-of-type {
font-size: 15px;
}
}
Problem
cannot add navigation menu to my project because css3 not need to
define why ?
it display with green lines in all css file why
How to solve this problem ?
my code
<head>
<link href="~/Content/menu.css" rel="stylesheet" />
</head>
<div class="grid">
<div class="grid__item">
<nav class="header">
☰ menu
<ul>
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
</div>
</div>
I create menu.css file in content folder i add following code :
css3
#import "compass/css3";
$base-font-size: 16px!default;
$base-line-height: 24px!default;
$base-spacing-unit: $base-line-height!default;
body {
background: grey;
color: #555;
}
.header {
width: 100%;
background-color: #4C8FEC;
height: $base-line-height * 2;
margin-top: $base-line-height;
}
a {
color: black;
text-decoration: none;
font-weight: bold;
&:hover {
color: white;
}
}
.current {
color: white;
}
.menu-icon1 {
display:inline-block;
width: 100%;
height: $base-line-height * 2;
color: black;
line-height: $base-line-height * 2;
text-align: center;;
}
nav ul, nav:active ul {
display: none;
position: relative;
padding: 0 $base-spacing-unit;
background: #4C8FEC;
width: 100%;
list-style: none;
}
nav li {
text-align: left;
width: 100%;
padding: 10px 0;
margin: 0;
}
nav:hover ul {
display: block;
}
/*MEDIA QUERY*/
// #include media-query(desk){
#media screen and (min-width: 600px) {
nav {
float: left;
.menu-icon1 {
display: none;
}
}
nav ul, nav:active ul {
display: inline;
padding: 0;
width: 100%;
}
nav li {
display: inline-block;
width: auto;
padding: 0 $base-spacing-unit;
line-height: $base-line-height * 2;
}
}
image to my problem
In the below code everything functions OK, except that after clicking on the button second time after dropdown opens, the color won't turn from red to blue. Any solutions to this please?
Thanks,
CP
function dropdown_one() {
document.getElementById("menu_list").classList.toggle("dcontent");
}
window.onclick = function(event) {
if (!event.target.matches('.button')) {
var menu = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < menu.length; i++) {
var open_list = menu[i];
if (open_list.classList.contains('dcontent')) {
open_list.classList.remove('dcontent');
}
}
}
}
.button {
background-color: blue;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.button:hover {
background-color: green;
}
.button:focus {
background-color: red;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: relative;
background-color: #efefef;
min-width: 160px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
right: 0;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown a:hover {
background-color: grey
}
.dcontent {
display: block;
}
<div class="dropdown">
<button onclick="dropdown_one()" class="button">Dropdown</button>
<div id="menu_list" class="dropdown-content">
Home
About
Contact
</div>
</div>
The problem is that you're using the focus pseudo-class to set the background color to red. Clicking on an element that has focus doesn't remove focus from that element. You could potentially blur the element when it's clicked, but you'd have to have a way to determine if the click is activating the button or deactivating it.
An easier solution would be to just use a normal class rather than trying to leverage the focus pseudo-class in this way. Since you already have a JS click event handler, you can just put code in there to toggle a class on the button specifying if it's been clicked or not, and then use that class to set the red background. You'll need to remove that class from the button in the window click handler as well, since just removing the focus will no longer revert the button's background color. You might want to look at how I did this for some hints on how you might improve the code you already had in the window click handler, as well.
function dropdown_one(btn) {
document.getElementById("menu_list").classList.toggle("dcontent");
btn.classList.toggle("button-selected");
}
window.onclick = function(event) {
if (!event.target.matches('.button')) {
var menu = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < menu.length; i++) {
var open_list = menu[i];
if (open_list.classList.contains('dcontent')) {
open_list.classList.remove('dcontent');
}
}
let selected = document.getElementsByClassName("button-selected");
for (let i = 0, len = selected.length; i < len; i++) {
selected[i].classList.remove("button-selected");
}
}
}
.button {
background-color: blue;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.button:hover {
background-color: green;
}
.button-selected,
.button-selected:hover {
background-color: red;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: relative;
background-color: #efefef;
min-width: 160px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
right: 0;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown a:hover {
background-color: grey
}
.dcontent {
display: block;
}
<div class="dropdown">
<button onclick="dropdown_one(this)" class="button">Dropdown</button>
<div id="menu_list" class="dropdown-content">
Home
About
Contact
</div>
</div>
.button {
background-color: blue;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
font-family: sans-serif;
}
.button:hover {
background-color: green;
}
.button:focus {
background-color: red;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: relative;
background-color: #efefef;
min-width: 160px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
right: 0;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown a:hover {
background-color: grey
}
.dcontent {
display: block;
}
#butt {
display: none;
}
label {
display: inline-block;
}
#butt:checked ~ label .button {
background-color: red;
}
#butt:checked ~ .dropdown-content {
display: block;
}
<div class="dropdown">
<input type="checkbox" id="butt">
<label for="butt">
<div class="button">Dropdown</div>
</label>
<div id="menu_list" class="dropdown-content">
Home
About
Contact
</div>
</div>
function dropdown_one() {
document.getElementById("menu_list").classList.toggle("dcontent");
if ( document.getElementById("menu_list").offsetParent !== null ) {
document.querySelector(".button").style.backgroundColor = "red";
} else {
document.querySelector(".button").style.backgroundColor = "";
}
}
and then can remove this from CSS:
.button:focus {
background-color: red;
}
Here is CodePen example.
or change your HTML so that the effect can be achieved using pure CSS.