CSS - How to change scrollbar height - html

I have a block that has a property "overflow: scroll" I want to change the height of my scroll from https://ibb.co/gFyfDwT to this https://ibb.co/SsByRXB
Lesson.jsx
import React from 'react';
import less from "./css/lesson.module.css";
import "./css/betaLesson.css";
export class Lessons extends React.Component {
render() {
return (
<>
<div className="abc">
<div className={less.wrapper}>
<div>
<div className={less.sidebar}>
<div>
{listLessons}
</div>
</div>
</div>
</div>
</div>
</>
);
}
}
style.css
const sidebar: {
width: 240px;
overflow: scroll;
height: 100%;
background: #ffffff;
padding: 15px 0px;
position: fixed;
}

You could add another class inside the div with all the lessons and than add a height inside depending on your requirements, which might be 300%.
import React from 'react';
import less from "./css/lesson.module.css";
import "./css/betaLesson.css";
export class Lessons extends React.Component {
render() {
return (
<>
<div className="abc">
<div className={less.wrapper}>
<div>
<div className={less.sidebar}>
<div className={less.lessons}>
{listLessons}
</div>
</div>
</div>
</div>
</div>
</>
);
}
}
const sidebar: {
width: 240px;
overflow: scroll;
height: 100%;
background: #ffffff;
padding: 15px 0px;
position: fixed;
}
const lessons: {
height: 300% // or 2000px...
}

Related

Unable to add background image using semantic-ui-react in a component

I have tried to add background Image in my application using inline CSS styling but I'm unable to add in semantic-ui-react component and also the div.
Tried by backgroundImage:url(${https://wallpapercave.com/wp/wp2449777.png}) using this in my div and also the component called in semantic-ui-react
import React,{Component} from 'react';
import {Container,Image,Segment} from 'semantic-ui-react';
import Certificate from '../ethereum/certificate';
import web3 from '../ethereum/web3';
class certificateHere extends Component{
static async getInitialProps(props){
const numberofCertificates = await Certificate.methods.getCertificateCount().call();
const recentCertificate = await Certificate.methods.certificates(numberofCertificates-1).call();
return { numberofCertificates , recentCertificate};
}
render(){
const { numberofCertificates , recentCertificate}= this.props;
return (
<div className='main'
style={{
textAlign:'center',
backgroundImage:`url(${https://wallpapercave.com/wp/wp2449777.png})`
}}
>
<Segment >
<div className='sub'>
<h1><b>Blockchain Certification</b></h1>
<h3 >This is to certify that</h3><br/>
<p><b>{recentCertificate.CandidateName} has successfully completed his {recentCertificate.CourseName} developer Program which<br/>
is of 14 hrs online course: Build projects using solidity on {recentCertificate.DateOfCompletion}.</b></p>
</div>
<Image src='' size='small' style={{ marginLeft: 'auto', marginRight: 'auto'}} />
<div style={{ position: 'absolute',
bottom: '8px',
left: '16px'}}
>
<h4 className='issued'style={{textAlign:'left', textDecoration: 'underline'}}>Issued by:{recentCertificate.InstituteName}</h4>
<h4 className='location'style={{textAlign:'left',textDecoration: 'underline'}}>Location:{recentCertificate.Location}</h4>
</div>
<div style={{ position: 'absolute',
bottom: '8px',
right: '16px'}}>
<h4 className='issuer'style={{textAlign:'right',textDecoration: 'underline'}}>Issuer Name:{recentCertificate.IssuerName}</h4></div>
<style jsx>{`
h1 {
color: orange;
font-style: oblique;
font-size: 50px;
}
h3{
font-size: 40px;
color:orange;
padding-top: 25px;
}
p{
font-size: 20px;
color: orange;
padding:30px;
}
h4.issued{
color: orange;
padding-bottom: 25px;
}
h4.location{
padding-bottom: 100px;
}
h4.issuer{
padding-bottom: 100px;
}
.main{
backgroundColor:green;
}
`}</style>
</Segment>
</div>
);
}
}
export default certificateHere;
I just want the background image for this component covering the entire page.
Try using backgroundImage: ‘url(https://wallpapercave.com/wp/wp2449777.png)’

How do I make a content div scrollable? React and CSS

Learning React.js framework and need some pointers on styling. CSS isn't my forte.
How do I style the static content div in the middle and make it scrollable only within the div?
No styling:
https://i.imgur.com/26wNAfH.jpg
How to style this?
https://i.imgur.com/c5nYCOz.jpg
Here's the scroll function:
https://storage.googleapis.com/hatchways-app.appspot.com/assessments/data/frontend/part%202.mp4
app.css
.name {
font-weight: bold;
font-size: 20px;
}
.centered {
margin: auto;
width: 50%;
border: 3px solid green;
padding: 10px;
}
.center {
position: fixed;
width: 500px;
height: 200px;
top: 50%;
left: 50%;
margin-top: -100px; /* Negative half of height. */
margin-left: -250px; /* Negative half of width. */
}
.content {
text-align: center;
border: 2px solid grey;
border-radius: 5px;
position: fixed;
/* center the div */
right: 0;
left: 0;
margin-right: auto;
margin-left: auto;
/* give it dimensions */
min-height: 10em;
width: 90%;
/* just for example presentation */
top: 5em;
background-color: white;
}
Output: https://i.imgur.com/Eyv6hab.png
HTML:
import React, { Component } from "react";
import "../App.css";
import "../../node_modules/bootstrap/dist/css/bootstrap.min.css";
const API = "https://www.hatchways.io/api/assessment/students";
class App extends Component {
constructor(props) {
super(props);
this.state = {
students: [],
isLoading: false,
error: null
};
}
componentDidMount() {
this.setState({ isLoading: true });
fetch(API)
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error("Something went wrong ...");
}
})
.then(data =>
this.setState({ students: data.students, isLoading: false })
)
.catch(error => this.setState({ error, isLoading: false }));
}
render() {
const { students, isLoading, error } = this.state;
if (error) {
return <p>{error.message}</p>;
}
if (isLoading) {
return <p>Loading ...</p>;
}
return (
<body>
<div className="content">
<div>
{students.map(student => (
<div key={student.id}>
<p>
<img src={student.pic} />
</p>
<p className="name">
{student.firstName} {student.lastName}
</p>
<p>Email: {student.email}</p>
<p>Company: {student.company}</p>
<p> Skill: {student.skill}</p>
<p>Average: {student.grades}</p>
</div>
))}
</div>
</div>
{/* <div class="card mb-3">
{students.map(student => (
<div class="row no-gutters">
<div class="col-md-4">
<img src={student.pic} class="card-img" alt="..." />
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">
{student.firstName} {student.lastName}
</h5>
<p class="card-text">
<p>Email: {student.email}</p>
<p>Company: {student.company}</p>
<p> Skill: {student.skill}</p>
<p>Average: {student.grades}</p>
</p>
</div>
</div>
</div>
))}
</div> */}
</body>
);
}
}
export default App;
This might not help I am unfamiliar with that JS framework. I am only posting this because nobody has answered and maybe this can help.
<style>
scroll
{
max-height: 400px;
overflow-y: scroll;
}
</style>
<div class="scroll">

circular border-radius artifacts in css

I am using react and have a circle component that I want to map on the screen. The problem is at certain view sizes I get small artifacts in the circles. Flat ends and only on certain rows of circles.
Circles have flat sides at view width 980px
ball hitbox
container hitbox
.ballholder{
display:flex;
flex-wrap: wrap;
justify-content: space-evenly;
background-color:rgb(206,35,212);
padding:0.5vw;
border-radius: 5%;
border:2px solid black;
}
.aball{
background-image: linear-gradient(to bottom right, white, whitesmoke, rgb(150,150,150));
color:black;
border-radius:50%;
display:flex;
justify-content:center;
align-items:center;
width:2vw;
height:2vw;
padding:0.05vw;
margin:0.20vw;
font-size:1.3vw;
}
Here's the parent component:
import React, { Component } from "react";
import { Switch, Route, Redirect, Link } from "react-router-dom";
import Ball from "./Ball";
import "../App.css";
export default class Ballswitch90 extends Component {
constructor(props) {
super(props);
this.state = {
};
}
render() {
const balls = this.state.balls.map((a, i) =>
a ? (
<Ball p={{ num: i + 1, clicked: false }} />
) : (
<Ball p={{ num: i + 1, clicked: true }} />
)
);
return <div className="ballholder">{balls}</div>;
}
}
Ball component:
import React, { Component } from 'react';
import { Switch, Route, Redirect, Link } from "react-router-dom"
import '../App.css'
export default class Ball extends Component {
constructor(props) {
super(props)
this.state = {
num:props.p.num,
clicked:props.p.clicked
}
}
render() {
return (
<div>
{this.state.clicked
?
<div className="aball">{this.state.num}</div>
:
<div className="aballred">{this.state.num}</div>
}
</div>
)
}
}
I've tried adding a padding and margin but that only changed the size at which the flats show up.
Probably the css rules with height and width make some problems.
You can see this snippet that works well:
https://codesandbox.io/embed/n6jrm1k2l
aball {
border-radius: 50%;
background-color: white;
border: 1px solid darkred;
padding: 1em;
/* Center the text contents */
display: inline-flex;
align-items: center;
justify-content: center;
color: black;
}
.aball:after {
content: "";
display: block;
/* Ensure the element is a square */
height: 0;
width: 100%;
padding-bottom: 100%;
}
.aball__value {
/* Set the height to 0 and overflow to visible to not interfere with the square styles */
overflow: visible;
height: 0;
/* Vertically center text since we set its height to 0 */
margin-top: -1em;
}

Scroll Event is not firing in Angular-6

I know this question is asked before, but none of the solutions worked for me.
I am working on the Angular-6 project. I am trying to get Window-Scroll event in one of the components named SectionComponent.
Styles of html and body tag:
html, body {
overflow: auto;
position: relative;
margin: 0;
height: 100%;
}
Below is the hierarchy of components which explains how components are managed.
My AppComponent:
HTML:
<div id="wrapper">
<router-outlet></router-outlet>
</div>
CSS:
#wrapper {
width: 100vw;
height: 100vh;
position: relative;
overflow: auto;
}
app.component.ts:
#HostListener('window:scroll', [])
onWindowScroll() {
console.log('scroll');
}
AppComponent loads component named HomeComponent in the router-outlet tag. This HomeComponent loads SectionComponent by using is selector.
My HomeComponent:
HTML:
<div class="home-wrapper">
<div>
<!-- Some content more that window height -->
</div>
<app-section></app-section>
</div>
CSS:
.home-wrapper {
position: relative;
overflow-y: auto;
height: 100%;
}
home.component.ts:
#HostListener('window:scroll', [])
onWindowScroll() {
console.log('scroll');
}
My SectionComponent
HTML:
<div class="section-wrapper">
<!-- Some content more than window height -->
</div>
CSS:
.section-wrapper {
position: relative;
height: 2241px;
}
section.component.ts:
#HostListener('window:scroll', [])
onWindowScroll() {
console.log('scroll');
}
I only want to use Window-Scroll in SectionComponent. But none of the components are firing the event. What am I doing wrong?
import { ScrollDispatcher } from '#angular/cdk/scrolling';
constructor(private scrollDispatcher: ScrollDispatcher) {
this.scrollDispatcher.scrolled().subscribe(x => console.log('I am scrolling'));
}
in tempalte:
<div cdkScrollable>
<div *ngFor="let one of manyToScrollThru">
{{one}}
</div>
</div>
In Your SectionComponent after the class declaration just use
#HostListener('window:scroll', ['$event']) onScrollEvent($event){
var element = document.getElementsByClassName('section-wrapper')[0];
var rect = element.getBoundingClientRect();
// the above code will return the CSS border-boxe associated with the element.
// so on scroll you will have readonly left, top, right, bottom, x, y, width, and height properties .
//on behalf of these properties you can manipulate the DOM section-wrapper div.
}

Slide a div from the bottom underneath another div with angular animations

As you can see in the screenshot below, I hava a tab on the bottom of my page. When I click on it, I want it to slide underneath the <div> containing "Test" using angular animations. The problem is, that the pagesize should be responsive and therefore I cannot use px-values. I tried percentage as well, but that value refers to my tab-div, not the overall height.
Screenshot
My component:
#Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss'],
animations: [
trigger('tabState', [state('default', style({
transform: 'translateY(0)'
})
),
state('open', style({
transform: 'translateY(-100%)'
})),
transition('default <=> open', animate(500))
])
]})
export class TestComponent {
state = 'default';
onComeIn() {
this.state === 'default' ? this.state = 'open' : this.state = 'default';
}
}
My HTML:
<div class="mainContainer">
<mat-toolbar color="primary">
<div class="d-flex align-items-center justify-content-between">
<span>Test</span>
</div>
</mat-toolbar>
<div class="mainContentContainer">
<div class="d-flex flex-column" style="height: 100%">
<div>content</div>
<div class="mt-auto">
<div class="tabContainer" [#tabState]="state">
<div class="tab" (click)="onComeIn()">Tab</div>
</div>
</div>
</div>
And finally the css:
.tab {
box-sizing: border-box;
height: 4.2em;
width: 33%;
background-color: white;
padding: 1em 1.2em 0.45em 1.2em;
border-radius: 0.5em 0.5em 0 0;
box-shadow: 0 0.05em #b7b7b7;
}
.mainContainer {
width: 100%;
display: flex;
flex-direction: column;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.mainContentContainer {
flex: 1;
background-color: #455864;
}
The issue is more about css :
I changed the initial value of the tabContainer class to this :
.tabContainer {
position: fixed;
bottom: 0;
width: 100%;
}
Then in the animation definition, removed the bottom and added the top one :
state('open', style({
bottom: 'initial',
top: '20px'
})),
Here is the running example in editor.