How to make a div fill its parent div completely in React? - html

I am trying to create a react app using create-react-app. Following is my app function which is supposed to render a component thread inside my main app.
function App() {
return (
<div className="App">
<header className="App-header">
<div style={{ width: "280px", height: "320px", borderWidth:"5",borderColor:"white" }}>
<Thread threadId={"my-thread-id"} />
</div>
</header>
</div>
);
}
and here is the thread component
function Thread() {
return (
<div className="thread">
<h1 className="text-3xl font-bold underline ">Hello world!</h1>
</div>
);
}
export default Thread;
I just want my thread component's div with class "thread" to fill entire height and width inside the div of 280px:320px w:h in the main app. I am only getting a height of ~70px now.
I'm trying to change height, width, minHeight, minWidth parameters in the header class but to no avail. I am very bad at CSS so I would really appreciate the help. Thanks!

In order to achieve this you need to give the element with thread a class of h-full (height:100%) to fill the height of the container (which has a height of 320px).
function App() {
return (
<div className="App">
<header className="App-header">
<div style={{ width: "280px", height: "320px", borderWidth:"5",borderColor:"white" }}>
<Thread threadId={"my-thread-id"} />
</div>
</header>
</div>
);
}
function Thread() {
return (
<div className="thread h-full">
<h1 className="text-3xl font-bold underline">Hello world!</h1>
</div>
);
}
const rootElement = document.getElementById("app");
ReactDOM.render(<App />, rootElement);
<div id="app"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>

give a class to Thread Component and style it
React:
<Thread className="t" />
CSS:
.t {
postion: absolute;
width: 100%;
height: 100%;
}

Related

Is there a Quasar equivalent to Semantic UI's pointing label?

I tried using the span pointing property <span class="label pointing-up bg-primary text-white">up</span> and QChip's pointing property as explained in the docs, but the pointing part doesn't work. I tried it in different projects, but the property doesn't work. Is there any other alternative?
You can use the quasar tooltip component I think.
Check out this codepen and see if it is any helpful to you.
const { ref } = Vue
const app = Vue.createApp({
setup () {
return {
showing: true
}
}
})
app.use(Quasar, { config: {} })
app.mount('#q-app')
<script src="https://cdn.jsdelivr.net/npm/quasar#2.7.7/dist/quasar.umd.prod.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue#3/dist/vue.global.prod.js"></script>
<link href="https://cdn.jsdelivr.net/npm/quasar#2.7.7/dist/quasar.min.css" rel="stylesheet"/>
<div id="q-app" style="min-height: 100vh;">
<div class="q-pa-md">
<div
style="width: 200px; height: 70px;"
class="bg-purple text-white rounded-borders row flex-center q-mt-md"
>
Hover here or click buttons
<q-tooltip v-model="showing">Tooltip text</q-tooltip>
</div>
</div>
</div>

react-window giving a class to innermost div

I can't find how to give a class to innermost div in react-window. In my case a have a flex wrapper containing list of data divs. But because react-window's innermost div separates my wrapper and list items I cannot properly align my list items. Is there a workaround either to access to innermost div and change it's class or directly to manipulate it's style.
Here is what react-window produces me as html.
<div style="position: relative; height: 600px; width: 100%; overflow: auto; will-change: transform; direction: ltr;">
<div style="height: 31900px; width: 100%;"> // ***here is where I want to style or give a class because there should be a flex wrapper here***
<div id="0" class="card product-card"><a class="product-title" href="/">
</div>
<div id="1" class="card product-card"><a class="product-title" href="/">
</div>
<div id="2" class="card product-card"><a class="product-title" href="/">
</div>
<div id="3" class="card product-card"><a class="product-title" href="/">
</div>
</div>
Thanks!
You can customize inner element and rows of each element
const Row = ({ index, style }) => (
<div
className={index % 2 === 0 ? "RowEven" : "RowOdd"}
style={{
...style,
top: `${parseFloat(style.top) + PADDING_SIZE}px`
}}
>
item {index}
</div>
);
const Example = () => (
<List
className="List"
height={150}
innerElementType={innerElementType}
itemCount={51}
itemSize={ITEM_SIZE}
width={300}
>
{Row}
</List>
);
const innerElementType = forwardRef(({ style, ...rest }, ref) => (
<div
ref={ref}
style={{
...style,
height: `${parseFloat(style.height) + PADDING_SIZE * 2}px`
}}
{...rest}
className="innerClass"
/>
));
here is Code sandbox example

Closing out html tags in ReactJS

I'm learning Reactjs and am wondering about JSX parsing. It looks like I'm getting the error "Unterminated JSX Comments" because I'm not closing out each open tag within it's respective class. Is this true? And if so, what would be an elegant way of correctly placing my <html></html> tag in a modular way? I'd prefer not to place it directly in App.
class App extends Component {
render() {
return (
<div className="App">
<Header/>
<Body/>
<Footer/>
</div>
);
}
}
Header Class:
class Header extends Component{
render(){
return(
<html> {/* <!-- HTML tag is OPENED --> */}
<head>
<title>
Data Uploader
</title>
</head>
<body>
<div class="content">
<div class="nav blue">
<div class="logo">
<img SRC="./images/logo.png"/>
</div>
<div class="title">
Data Uploader
</div>
{/* End of nav */}
</div>
);
}
}
Body Class: {Use your imagination. Some content goes here}
Footer Class:
class Footer extends Component{
render(){
return(
<div class="footer">
<div class="footer_text">Data Uploader | Copyright 2017 | Developed by Me</div>
{/* <End of footer */}
</div>
{/* End of content */}
</div>
</body>
{/* <!-- HTML (and body) tag is CLOSED--> */}
</html>
);
}
}

Moving buttons to the bottom of an element

I am using Material UI to create cards that take an argument Actions which is a list of buttons.
The length of the Card is relative to the text I enter, but all Cards will be the same height.
I am very new to CSS and still wrapping my mind around position: fixed, relative, absolute.
This is the code that renders the Card:
export function ViewCurrentPitches2(props) {
const actions = [
<FlatButton
label="Cancel"
primary={true}
onClick={props.closeEditPitch}
/>,
<FlatButton
label="Save"
primary={true}
keyboardFocused={true}
onClick={props.savePitchBeingEdited}
/>,
];
return (
props.state.savedPitches.map((pitch, i) => {
return(
<Card key={pitch.id} className = 'form-margin card-width' zDepth={3}>
<CardText>{pitch.subject} </CardText>
<CardText className='card'>{pitch.pitch}</CardText>
<CardActions>
<FlatButton label="Edit" onClick={(e) => {props.toggleEdit(e, pitch); console.log(props.state.pitchBeingEdited)}}/>
<Dialog
className="dialogBox"
title="Test"
modal={false}
actions={actions}
open={props.state.editPitch}
contentStyle={customContentStyle}
autoScrollBodyContent={true}
>
<TextFieldExampleCustomize currentValue = {props.state.pitchBeingEdited} updateNewPitch = {props.updatePitchBeingEdited} />
</Dialog>
<FlatButton label="Delete" onClick={(e) => {props.deletePitch(e, pitch)}} />
</CardActions>
</Card>
)
})
)
}
<div className='card-parent'>
<ViewCurrentPitches2
state= {this.state}
deletePitch = {this.deletePitch}
handleSave={this.dialogBoxSave}
toggleEdit = {this.toggleEdit}
closeEditPitch = {this.closeEditPitch}
updatePitchBeingEdited = {this.updatePitchBeingEdited}
savePitchBeingEdited = {this.savePitchBeingEdited}
/>
</div>
This is what it looks like:
Can anyone explain to me
1.) When I'm adding in the CSS position: relative | fixed | absolute ...etc what is happening? I assign that to the child correct?
2.) If I want to move the buttons to the bottom of the Card, Card is the parent and I put the styling on the button? How would I go about doing this?
Generally speaking, you would assign relative to the parent and absolute to the child. The child is being positioned absolutely, relative to the parent.
Refer to full documentation for more details.
.card{
display:inline-block;
width:200px;
height: 100px;
border: 1px solid red;
position: relative;
}
.buttons{
position: absolute;
bottom: 0;
border: 1px solid blue;
width: 100%;
}
<div class="parent">
<div class="card">
<div class="buttons">
<button>Edit</button>
<button>Delete</button>
</div>
</div>
<div class="card">
<div class="buttons">
<button>Edit</button>
<button>Delete</button>
</div>
</div>
<div class="card">
<div class="buttons">
<button>Edit</button>
<button>Delete</button>
</div>
</div>
<div>

How to set Image Slider

var Home = React.createClass({
render: function() {
return (
<div>
<img src="images/12.jpg" />
<img src="images/11.jpg" />
<img src="images/13.jpg" />
<img src="images/14.jpg" />
</div>
)
}
})
I need these 4 images as a slider can anyone give me the code using react or html with CSS
Use ready-made library, here example
https://github.com/jossmac/react-images
https://github.com/xiaolin/react-image-gallery
http://kenwheeler.github.io/slick/
First that is not the way to ask a question. Check here how to ask good question.
You can use some of all made React Slider Components, but if you want to do it on your own you can do something like this :
This is only to get the idea :
class Test extends React.Component {
constructor(){
super();
this.state = {
marginLeft: 0
}
}
componentDidMount(){
this.interval = setInterval(this.changeSlide.bind(this), 2000);
}
changeSlide(){
let totalSlides = document.getElementById("inner").children.length - 1;
let getWidth = document.getElementById("slide1").offsetWidth;
let marginLeft = this.state.marginLeft;
if((totalSlides * -getWidth) >= this.state.marginLeft){
marginLeft = 0
}else{
marginLeft = this.state.marginLeft - getWidth
}
this.setState({marginLeft})
}
render(){
return (
<div className="outter">
<div id="inner" className="inner" style={{marginLeft: this.state.marginLeft}}>
<img src="https://cdn.pixabay.com/photo/2016/12/29/16/12/eiskristalle-1938842_960_720.jpg" style={{maxWidth: "100%"}} id="slide1"/>
<img src="https://cdn.pixabay.com/photo/2014/10/16/09/15/frost-490807_960_720.jpg" style={{maxWidth: "100%"}} id="slide2"/>
<img src="https://cdn.pixabay.com/photo/2015/03/01/07/24/winter-654442_960_720.jpg" id="slide3"/>
</div>
</div>
)
}
}
ReactDOM.render(<Test />, document.getElementById('container'));
.outter{
width: 500px;
overflow: hidden;
}
.inner{
width: 1000%;
float:left;
margin-left: 0;
transition: all 1s ease;
}
.inner img{
max-width: 500px;
width: 500px;
float:left;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
In componentDidMount set interval to call the function to change the slide every 2 seconds (in this case).
In function changeSlide first you need to get total slides and the width of the first one (because all have the same width).
Then if it's the last slide set margin-left to 0 and if it's not then subtract the photo width of the current margin-left in the state. At the end update the state.
Hope that this will give you the idea how you can do it.
Here is the fiddle.