media query not working int the below code - Recact js - reactjs

In the below code the media query not working. Please help if any mistake I did.
I used paragraph media query the below. When I checked in mobile mode t is not working.
/* eslint-disable react/jsx-no-target-blank /
/ eslint-disable react/no-unescaped-entities */
import React from 'react'
import { DropdownButton, Dropdown } from 'react-bootstrap'
const ProfileInfo = () => {
const paragraph = {
position: 'absolute',
top: '66px',
right: '108px',
'#media screen and (min-width: 610px)': {
position: 'static'
}
}
return (
<div className="container-fluid">
<div className="row clearfix">
<div className="col-md-6 col-sm-12"> </div>
<div className="col-md-6 col-sm-12"> </div>
</div>
<div className="row" style={{ margin: 'auto', width: '50%' }}>
<div className="alert alert-success col-md-12 col-sm-12">
<h5 className="alert-heading">Aktive meldinger</h5>
<p>
Hahahahahhhhhfgdfgf gdfgdfgffgdfggfhgh fgdfgdfgfgfg
</p>
</div>
</div>
<div className="row clearfix">
<div className="col-md-6 col-sm-12">
<div className="card mb-3 shadow-sm p-3 bg-white rounded" >
<h5 className="card-title" style={{ color: '#009540' }}><strong>Profile: </strong> </h5>
<p className="card-text"><strong>Navn: </strong> Bengt Nilsfors</p>
<p className="card-text"><strong>Kontaktinformasjon: </strong> 95833897, nilsfors#gmail.com</p>
<DropdownButton id="dropdown-basic-button" variant="outline-primary"
title="Address">
<Dropdown.Item href="#/action-1">Address1 </Dropdown.Item>
<Dropdown.Item href="#/action-2">Address2</Dropdown.Item>
<Dropdown.Item href="#/action-3">Address3</Dropdown.Item>
</DropdownButton>
<p className="card-text"><strong>Adresse: </strong> Nøkken 7 H0101, 9016 Tromsø</p>
<p className="card-text"><strong>Passord: </strong> ***********</p>
<button className="btn btn-success">Rediger</button>
</div>
</div>
<div className="col-md-6 col-sm-12">
<div className="card mb-3 shadow-sm p-3 bg-white rounded" >
<h5 className="card-title" style={{ color: '#009540' }} ><strong>Nettverksanalyse</strong></h5>
<img className="card-img" variant="top" src="../images/testimg.png" style={{ width: '152px' }} />
<div style= { paragraph }>17:58:55: Henter nettverskinfo...<br/>
18:00:31: Nettverkstatus ok. Ingen feil funnet.</div>
<button className="btn btn-warning mt-2 text-center">See details</button>
</div>
</div>
</div>
<div className="row">
<div className="col-md-4 mt-5 text-center">
<div className="card mb-3 shadow-sm p-3 bg-white rounded" >
<div className="card-body">
<h5 className="card-title" style={{ color: '#009540' }}>Abonnement</h5>
<p className="card-text"><strong>Internett</strong></p>
<p className="card-text">Giga (1000/1000) Kr 699,- per mnd.</p>
Oppgrader
</div>
</div>
</div>
<div className="col-md-4 mt-5 text-center">
<div className="card mb-3 shadow-sm p-3 bg-white rounded">
<div className="card-body">
<h5 className="card-title" style={{ color: '#009540' }}>Faktura</h5>
<ul className="list-group" style= {{ float: 'left' }}>
<li><a className="card-link" href="https://www.homenet.no/" target="_blank" style={{ color: '#009540' }}>Mars 2021</a></li>
<li><a className="card-link" href="https://www.homenet.no/" target="_blank" style={{ color: '#009540' }}>Desember 2020</a></li>
<li><a className="card-link"href="https://www.homenet.no/" target="_blank" style={{ color: '#009540' }}>Februar 2021</a></li>
</ul><ul className="list-group" style={{ float: 'right' }}>
<li><a className="card-link" href="https://www.homenet.no/" target="_blank" style={{ color: '#009540' }}>Desember 2020</a></li>
<li><a className="card-link" href="https://www.homenet.no/" target="_blank" style={{ color: '#009540' }}> November 2020</a></li>
<li><a className="card-link" href="https://www.homenet.no/" target="_blank" style={{ color: '#009540' }}>Oktober 2020</a></li>
</ul>
<div style={{ marginTop: '76px' }}> Se alle</div>
</div>
</div>
</div>
<div className="col-md-4 mt-5 text-center">
<div className="card mb-3 shadow-sm p-3 bg-white rounded">
<div className="card-body">
<h5 className="card-title" style={{ color: '#009540' }}>Kontakt oss</h5>
<p className="card-text">Kontakt oss via chat eller telefon 38 99 01 00.</p>
Chat
</div>
</div>
</div>
</div>
</div>
)
}
export default ProfileInfo

t's not the problem with react its with the CSS code. If you apply two rules that collide to the same elements, it will choose the last one that was declared. So put the #media queries to the end of the CSS page. i.e
.footer
.column
.social-column-container
.logo {
width: 100px;
height: auto;
display: inline-block;
margin-left: 50px;
}
#media only screen and (min-width: 900px) {
.footer
.column
.social-column-container
.logo {
display: none;
}
}

Related

prevent resizing of parent by child

I allow myself to post my problem because I can't find a solution and I'm starting to pull my hair out.
I would like to make my second column the same height as my first column.
Concern is that since the content is larger than the initial size, it enlarges the parent div and therefore increases the content of the page.
I specify that I use Boostrap 5
My code:
<div className="row g-2">
<div className="col-md-5">
<div className='border border-primary border-4 bg-secondary' style={{ height: 400 + "px" }}></div>
</div>
<div className="col-md-7">
<div className='border border-primary border-4 bg-dark p-2 h-100 overflow-auto'>
<div className="bg-danger" style={{ height: 800 + "px" }}>
<span className="text-white fs-1">Hello World </span>
</div>
</div>
</div>
</div>
The problem in question
Here is what I want
Adding fixed height to parent element can be a solution. Also don't forget overflow class to parent.
<div className="row g-2 overflow-hidden" style={{ height: '400px' }}>
<div className="col-md-5">
<div
className="border border-primary border-4 bg-secondary"
style={{ height: 400 + 'px' }}
></div>
</div>
<div className="col-md-7">
<div className="border border-primary border-4 bg-dark p-2 h-100 overflow-auto">
<div className="bg-danger" style={{ height: 800 + 'px' }}>
<span className="text-white fs-1">Hello World </span>
</div>
</div>
</div>
</div>
Update:
What I'm really looking for is that column two is the same height as column one (its height will be automatic with the content).
You can achieve this by making second column relative and its child absolute. Also add top, bottom, left and right to 0
<div className="row g-2">
<div className="col-md-5">
<div
className="border border-primary border-4 bg-secondary"
style={{ height: 400 + 'px' }}
></div>
</div>
<div className="col-md-7 position-relative">
<div className="border position-absolute top-0 start-0 end-0 bottom-0 border-primary border-4 bg-dark p-2 h-100 overflow-auto">
<div className="bg-danger" style={{ height: 800 + 'px' }}>
<span className="text-white fs-1">Hello World </span>
</div>
</div>
</div>
</div>

Display divs one above the other

import React from "react";
export default function Example() {
return (
<div>
<div
className="grid"
style={{
gridTemplateColumns: "1.75rem repeat(288, minmax(0, 1fr)) auto",
}}
>
<div
className="mt-px inline-grid grid-cols-1 sm:col-start-3"
style={{ gridColumn: "74 / span 12" }}
>
<a href="#" className="rounded-lg bg-blue-50 p-2 text-xs">
<p className="order-1 font-semibold text-blue-700">Breakfast</p>
<p className="text-blue-500 group-hover:text-blue-700">
<time dateTime="2022-01-12T06:00">6:00 AM</time>
</p>
</a>
</div>
<div
className="mt-px inline-grid grid-cols-1 sm:col-start-3"
style={{ gridColumn: "76 / span 12" }}
>
<a href="#" className="rounded-lg bg-blue-50 p-2 text-xs">
<p className="order-1 font-semibold text-blue-700">Breakfast</p>
<p className="text-blue-500 group-hover:text-blue-700">
<time dateTime="2022-01-12T06:00">6:30 AM</time>
</p>
</a>
</div>
</div>
</div>
);
}
If you want both the tiles over one another , add absolute w-1/4 right-4 class to both the divs.
import React from "react";
export default function Example() {
return (
<div>
<div
className="grid"
style={{
gridTemplateColumns: "1.75rem repeat(288, minmax(0, 1fr)) auto",
}}
>
<div
className="absolute w-1/4 right-4 mt-px inline-grid grid-cols-1 sm:col-start-3"
style={{ gridColumn: "74 / span 12" }}
>
<a href="#" className="rounded-lg bg-blue-50 p-2 text-xs">
<p className="order-1 font-semibold text-blue-700">Breakfast</p>
<p className="text-blue-500 group-hover:text-blue-700">
<time dateTime="2022-01-12T06:00">6:00 AM</time>
</p>
</a>
</div>
<div
className="absolute w-1/4 right-4 mt-px inline-grid grid-cols-1 sm:col-start-3"
style={{ gridColumn: "76 / span 12" }}
>
<a href="#" className="rounded-lg bg-blue-50 p-2 text-xs">
<p className="order-1 font-semibold text-blue-700">Breakfast</p>
<p className="text-blue-500 group-hover:text-blue-700">
<time dateTime="2022-01-12T06:00">6:30 AM</time>
</p>
</a>
</div>
</div>
</div>
);
}
you can adjust right and width as per your requirement .

Dropdown values not showing when I click dropdown button - Reactjs

Dropdown values not showing in Address section. I used bootstrap 4 code.
I am not getting any error, when I am clicking dropdown it's not showing dropdown values.
I have added bootstrap 4 dropdown on this page but it's not working dropdown.
Please help with this.
Here is the code for review and I am a beginner at the react js. Please help
import React from 'react'
const ProfileInfo = () => {
return (
<div className="container-fluid">
<div className="row clearfix">
<div className="col-md-6 col-sm-12"> </div>
<div className="col-md-6 col-sm-12"> </div>
</div>
<div className="row clearfix">
<div className="col-md-6 col-sm-12">
<div className="card mb-3 shadow-sm p-3 bg-white rounded" >
<h5 className="card-title" style={{ color: '#009540' }}><strong>Profile: </strong> </h5>
<p className="card-text"><strong>Navn: </strong> Bengt Nilsfors</p>
<p className="card-text"><strong>Kontaktinformasjon: </strong> 95833897, nilsfors#gmail.com</p>
<div className="dropdown">
<button className="btn btn-info dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Address
</button>
<div className="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a className="dropdown-item" href="#">Address1</a>
<a className="dropdown-item" href="#">Address2</a>
</div>
</div><br/>
<p className="card-text"><strong>Adresse: </strong> Nøkken 7 H0101, 9016 Tromsø</p>
<p className="card-text"><strong>Passord: </strong> ***********</p>
<button className="btn btn-success">Rediger</button>
</div>
</div>
<div className="col-md-6 col-sm-12">
<div className="card mb-3 shadow-sm p-3 bg-white rounded" >
<h5 className="card-title" style={{ color: '#009540' }} ><strong>Nettverksanalyse</strong></h5>
<img className="card-img" variant="top" src="../images/testimg.png" style={{ width: '152px' }} />
<div style= {{ position: 'absolute', top: '66px', right: '108px' }}>17:58:55: Henter nettverskinfo...<br/>
18:00:31: Nettverkstatus ok. Ingen feil funnet.</div>
<button className="btn btn-warning mt-2 text-center">See details</button>
</div>
</div>
</div>
<div className="row">
<div className="col-md-4 mt-5 text-center">
<div className="card mb-3 shadow-sm p-3 bg-white rounded" >
<div className="card-body">
<h5 className="card-title" style={{ color: '#009540' }}>Abonnement</h5>
<p className="card-text"><strong>Internett</strong></p>
<p className="card-text">Giga (1000/1000) Kr 699,- per mnd.</p>
Oppgrader
</div>
</div>
</div>
<div className="col-md-4 mt-5 text-center">
<div className="card mb-3 shadow-sm p-3 bg-white rounded">
<div className="card-body">
<h5 className="card-title" style={{ color: '#009540' }}>Faktura</h5>
<ul className="list-group" style= {{ float: 'left' }}>
<li><a className="card-link" href="https://www.homenet.no/" target="_blank" style={{ color: '#009540' }}>Mars 2021</a></li>
<li><a className="card-link" href="https://www.homenet.no/" target="_blank" style={{ color: '#009540' }}>Desember 2020</a></li>
<li><a className="card-link"href="https://www.homenet.no/" target="_blank" style={{ color: '#009540' }}>Februar 2021</a></li>
</ul><ul className="list-group" style={{ float: 'right' }}>
<li><a className="card-link" href="https://www.homenet.no/" target="_blank" style={{ color: '#009540' }}>Desember 2020</a></li>
<li><a className="card-link" href="https://www.homenet.no/" target="_blank" style={{ color: '#009540' }}> November 2020</a></li>
<li><a className="card-link" href="https://www.homenet.no/" target="_blank" style={{ color: '#009540' }}>Oktober 2020</a></li>
</ul>
<div style={{ marginTop: '76px' }}> Se alle</div>
</div>
</div>
</div>
<div className="col-md-4 mt-5 text-center">
<div className="card mb-3 shadow-sm p-3 bg-white rounded">
<div className="card-body">
<h5 className="card-title" style={{ color: '#009540' }}>Kontakt oss</h5>
<p className="card-text">Kontakt oss via chat eller telefon 38 99 01 00.</p>
Chat
</div>
</div>
</div>
</div>
</div>
)
}
export default ProfileInfo
I think you need to use an html table. Then your code will look like this :
<button className="btn btn-info dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Address
</button>
<ul className="dropdown-menu" aria-labelledby="dropdownMenuButton">
<li><a className="dropdown-item" href="#">Address1</a></li>
<li><a className="dropdown-item" href="#">Address2</a></li>
</ul>
</div>
But with React you have a specific bootstrap components. You should use these components : https://react-bootstrap.github.io/components/dropdowns/

How to make cards slide in React using buttons?

I want buttons to slide different cards on the screen currently it is moving by clicking on cards.
I tried using jquery ComponentDidMount but I'm unable to make it work and I'm stucked here.
this is my code In App class
<div className="flex flex-wrap sm:-m-4 -mx-4 -mb-10 -mt-4">
<div className="md:w-1/4 py-64 md:mb-0 mb-6 flex flex-col text-center items-center">
<div className="w-20 h-20 inline-flex items-center justify-center rounded-full bg-orange-100 text-orange-500 mb-5 flex-shrink-0">
<img
id="pre-btn"
alt="logo"
className="h-10 pr-0"
src={back}
></img>
</div>
</div>
<div className="md:w-2/4 md:mb-0 mb-6 flex flex-col text-center items-center">
<section
id="slider"
className="w-16 h-20 inline-flex items-center justify-center mb-5 flex-shrink-0"
>
<input type="radio" name="slider" id="s1" defaultChecked="false"/>
<input type="radio" name="slider" id="s2" defaultChecked="true"/>
<input type="radio" name="slider" id="s3" defaultChecked="false"/>
<label htmlFor="s1" id="slide1">
{/* <img className="fea" src="./assets/img/img1.jpg" height="100%" width="100%"/> */}
</label>
<label htmlFor="s2" id="slide2">
{/* <img className="fea" src="./assets/img/img2.jpg" height="100%" width="100%"/> */}
</label>
<label htmlFor="s3" id="slide3">
{/* <img className="fea" src="./assets/img/img3.jpg" height="100%" width="100%"/> */}
</label>
</section>
</div>
<div className="md:w-1/4 py-64 md:mb-0 mb-6 flex flex-col text-center items-center">
<div className="w-20 h-20 inline-flex items-center justify-center rounded-full bg-orange-100 text-orange-500 mb-5 flex-shrink-0">
<img
id="nex-btn"
alt="logo"
className="h-10 pr-0"
src={front}
></img>
</div>
</div>
</div>
this is my css part
[type=radio] {
display: none;
}
#slider {
height: 30vw;
width: 40vw;
margin: 0 auto;
left: -10%;
position: relative;
perspective: 1000px;
transform-style: preserve-3d;
}
#slider label {
margin: auto;
background-color: aliceblue;
width: 60%;
height: 100%;
border-radius: 4px;
position: absolute;
left: 0; right: 0;
cursor: pointer;
transition: transform 0.4s ease;
}
#s1:checked ~ #slide3, #s2:checked ~ #slide1,
#s3:checked ~ #slide2 {
box-shadow: 0 6px 10px 0 rgba(0,0,0,.3), 0 2px 2px 0 rgba(0,0,0,.2);
transform: translate3d(-50%,0,-100px);
}
#s1:checked ~ #slide1, #s2:checked ~ #slide2,
#s3:checked ~ #slide3 {
box-shadow: 0 13px 25px 0 rgba(0,0,0,.3), 0 11px 7px 0 rgba(0,0,0,.19);
transform: translate3d(0,0,0);
}
#s1:checked ~ #slide2, #s2:checked ~ #slide3,
#s3:checked ~ #slide1 {
box-shadow: 0 6px 10px 0 rgba(0,0,0,.3), 0 2px 2px 0 rgba(0,0,0,.2);
transform: translate3d(50%,0,-100px);
}
this is my jquery code
componentDidMount() {
var i=Number(2) ;
var dam = "#s" + i ;
$("#pre-btn").click(function(){
// console.log(dam);
$(dam).prop('defaultChecked', "false") ;
if(i>1){
i-- ;
}
$(dam).prop('defaultChecked', "true") ;
}) ;
$("#nex-btn").click(function(){
$(dam).prop('defaultChecked', "false") ;
if(i<3){
i++ ;
}
$(dam).prop('defaultChecked', "true") ;
}) ;
}
I think that states in react must be used but I don't know how to use that's why I used jquery.
Here is what i can propose you, without jquery (I usually try to avoid it) :
import React, { Component } from "react";
import { render } from "react-dom";
import Hello from "./Hello";
import "./style.css";
const App = () => {
const [selectedIndex, setSelectedIndex] = React.useState(0);
const checkNext = () => {
const labels = document.querySelectorAll('#slider label');
const nextIndex = selectedIndex === (labels.length - 1) ? 0 : selectedIndex + 1;
setSelectedIndex(nextIndex);
}
const check = index => setSelectedIndex(index);
return (
<div>
<div className="flex flex-wrap sm:-m-4 -mx-4 -mb-10 -mt-4">
<div className="md:w-1/4 py-64 md:mb-0 mb-6 flex flex-col text-center items-center">
<div className="w-20 h-20 inline-flex items-center justify-center rounded-full bg-orange-100 text-orange-500 mb-5 flex-shrink-0">
<button onClick={checkNext}>{'<'}</button>
</div>
</div>
<div className="md:w-2/4 md:mb-0 mb-6 flex flex-col text-center items-center">
<section
id="slider"
className="w-16 h-20 inline-flex items-center justify-center mb-5 flex-shrink-0"
>
<input
type="radio"
name="slider"
id="s1"
checked={selectedIndex === 0}
onClick={() => check(0)}
/>
<input
type="radio"
name="slider"
id="s2"
checked={selectedIndex === 1}
onClick={() => check(1)}
/>
<input
type="radio"
name="slider"
id="s3"
checked={selectedIndex === 2}
onClick={() => check(2)}
/>
<label htmlFor="s1" id="slide1">
<img className="fea" src="https://picsum.photos/200/200" height="100%" width="100%"/>
</label>
<label htmlFor="s2" id="slide2">
<img className="fea" src="https://picsum.photos/200/300" height="100%" width="100%"/>
</label>
<label htmlFor="s3" id="slide3">
<img className="fea" src="https://picsum.photos/300/300" height="100%" width="100%"/>
</label>
</section>
</div>
<div className="md:w-1/4 py-64 md:mb-0 mb-6 flex flex-col text-center items-center">
<div className="w-20 h-20 inline-flex items-center justify-center rounded-full bg-orange-100 text-orange-500 mb-5 flex-shrink-0">
<button onClick={checkNext}>{'>'}</button>
</div>
</div>
</div>
</div>
);
}
render(<App />, document.getElementById("root"));
I didn't change your css at all and used it to do the switch, as before. I just created a state containing the index of the checked element, which allow you to defined wether or not an input is checked. When the value changes, it trigger your css and do the switch.
Here is a repro on stackblitz.

Align items horizontally bootstrap

I have a bootstrap grid layout in my web app I want to align all on the same line. For example, when loading in full screen, the cards look as follows:
However, when the page is resized, the cards appear as follows
I need to make them look like the first image regardless of how the page is resized, jut not sure how to go about doing this.
Below is my code:
<div className="d-flex col-sm-6">
<div className="" style={{backgroundColor: 'white', borderRadius: 5, border: '1px solid #EAE8E8'}}>
<div className="row">
<div className="d-flex col-md-8">
<div className="row" style={{paddingTop: 20, paddingBottom: 20, paddingLeft: 40}}>
<h4>
<b>{this.props.restaurant.name}</b>
{this.props.restaurant.dietaryRestrictions.map(function(dietaryRestriction, index) {
return(<div key={index}><span className="badge-sm badge-secondary" style={{color: 'white', backgroundColor: '#DA9550', fontSize: 9}}>{dietaryRestriction}</span> </div>);
})}
</h4>
{this.props.restaurant.description}
<br /><br />
<span className="munchtime pointer"><i className="fas fa-check"></i> <b>Add to Cart</b></span><br /><br />
<b><s>${this.props.restaurant.price}</s></b> <span className="discount"><b>${this.props.restaurant.price * this.props.restaurant.restaurant.discount}</b></span>
</div>
</div>
<div className="d-flex col-md-4">
<img src={this.props.restaurant.images[0]} style={{width: '100%', height: 250, objectFit: 'cover'}} />
</div>
</div>
</div>
</div>
just divide the grid in 5 by 3 manner for all views (xs, sm, md) as container total width is 8.
media queries breakpoints : grid-media-queries
example is below with the
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="d-flex col-md-8">
<div class="" style="background-color: 'white', border-radius: 5, border: '1px solid #EAE8E8'">
<div class="row">
<div class="d-flex col-xs-5 col-sm-5 col-md-5">
<div class="row" style="padding-top: 20, padding-bottom: 20, padding-left: 40">
<h4>
<b> restaurant name</b>
<div key=1><span class="badge-sm badge-secondary" style="color: 'white', background-color: '#DA9550', font-size: 9">dietaryRestriction</span> </div>
</h4>
restaurant description
<br /><br />
<span class="munchtime pointer"><i class="fas fa-check"></i> <b>Add to Cart</b></span><br /><br />
<b><s>$2000</s></b> <span class="discount"><b>20%</b></span>
</div>
</div>
<div class="d-flex col-xs-3 col-sm-3 col-md-3">
<img src='https://picsum.photos/200/300
' style="width: '100%', height: 250, objectFit: 'cover'" />
</div>
</div>
</div>
</div>
In your code, you are using col-md-8 which will work from min-width of 992px. you can replace md with xs, so that it will work for all resolutions.
<div className="d-flex col-sm-6">
<div className="" style={{backgroundColor: 'white', borderRadius: 5, border: '1px solid #EAE8E8'}}>
<div className="row">
<div className="d-flex col-xs-8">
<div className="row" style={{paddingTop: 20, paddingBottom: 20, paddingLeft: 40}}>
<h4>
<b>{this.props.restaurant.name}</b>
{this.props.restaurant.dietaryRestrictions.map(function(dietaryRestriction, index) {
return(<div key={index}><span className="badge-sm badge-secondary" style={{color: 'white', backgroundColor: '#DA9550', fontSize: 9}}>{dietaryRestriction}</span> </div>);
})}
</h4>
{this.props.restaurant.description}
<br /><br />
<span className="munchtime pointer"><i className="fas fa-check"></i> <b>Add to Cart</b></span><br /><br />
<b><s>${this.props.restaurant.price}</s></b> <span className="discount"><b>${this.props.restaurant.price * this.props.restaurant.restaurant.discount}</b></span>
</div>
</div>
<div className="d-flex col-xs-4">
<img src={this.props.restaurant.images[0]} style={{width: '100%', height: 250, objectFit: 'cover'}} />
</div>
</div>
</div>
</div>
You should only have to adjust the "col" className so that it is always 8 and 4 on any breakpoint.

Resources