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>
Related
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%;
}
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
I tried to set an onClick event to open a flexbox in react using tsx. The button and the flexbox is shown properly but vscode shows a problem with the onClick event. I cant figure out whats wrong but maybe you can. I am new to the field and tried some ideas from the stack community but it didnt work for me.
The console tells me I have to assign 'string' but it doesnt work either.
//Function to change visibility of the flexBox
document.getElementById("OpenProfiles")
.addEventListener("click", ProfilesOpn);
function ProfilesOpn () {
var a = document.querySelectorAll(".ProfilesOpen")[0];
var b = document.querySelectorAll(".ProfilesClose")[0];
a.style.visibility = "hidden"
b.style.visibility = "visible";
}
//the button code inside the flexbox
<div className={"Profiles"}>
<div className={"Profile1"}>
<div className={"Profile1P"}></div>
<h3 className={"ProfileH3"}>Profile1</h3>
</div>
<div className={"Profile2"}>
<div className={"Profile2P"}></div>
<h3 className={"ProfileH3"}>Profile2</h3>
</div>
<div className={"Profile3"}>
<div className={"Profile3P"}></div>
<h3 className={"ProfileH3"}>Profile3</h3>
</div>
<div className={"Profile4"}>
<div className={"Profile4P"}></div>
<h3 className={"ProfileH3"}>Profile4</h3>
</div>
<h3 className={"EndCoPro"}>Are you missing any profiles?</h3>
<button id="OpenProfiles" onClick="return(ProfilesOpn());">
<div className={"ProfilesOpen"}><img src={ProfilesOpen} alt="Open Profiles"/></div>
</button>
</div>
//the code in sass for the styling
.Profiles {
position: absolute;
display: flex;
left: 0px;
bottom: 0px;
width: 300px;
height: 900px;
flex-direction: column;
justify-content: flex-start;
align-items: space-between;
background-color: #292929;
box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.2);
border-top-right-radius: 25px;
border-bottom-right-radius: 25px;
visibility: hidden;
}
Code Sandbox: https://codesandbox.io/s/dazzling-bouman-62hgi?file=/src/App.js:0-1850
Here are 2 approaches to what you are trying to accomplish using react hooks:
The ProfilesOpn function uses a ref to set DOM properties.
The reactWayToShowCat function sets the showCat status using internal component state.
import React, { useState, useRef } from "react";
import "./styles.css";
export default function Explorer() {
const a = useRef(null);
const b = useRef(null);
const [showCat, toggleShowCat] = useState(true);
const ProfilesOpn = () => {
a.current.style.visibility = "hidden";
b.current.style.visibility = "visible";
};
const reactWayToShowCat = () => {
toggleShowCat(!showCat);
};
return (
<div className="Profiles">
{Array(4)
.fill("")
.map((_, i) => {
const num = i + 1;
return (
<div className={`Profile${num}`} key={num}>
<div className={`Profile${num}P`}></div>
<h3 className="ProfileH3">{`Profile${num}`}</h3>
</div>
);
})}
<h3 className="EndCoPro">Are you missing any profiles?</h3>
<button id="OpenProfiles" onClick={ProfilesOpn}>
<div className={"ProfilesOpen"} ref={a}>
<img src="https://placekitten.com/200/300" alt="Open Profiles" />
<p>
Click to see solution that uses refs to accomplish what you were
doing
</p>
</div>
</button>
<button id="CloseProfiles" onClick={reactWayToShowCat}>
<div className={"ProfilesClose"} ref={b}>
<>
{showCat && (
<img src="https://placekitten.com/200/300" alt="Close Profiles" />
)}
<p>
Click to see one react way to show and hide the cat (no styling)
</p>
</>
</div>
</button>
</div>
);
}
The main issue in original code was that onClick needs to be set with this syntax:
<button id="OpenProfiles" onClick={ProfilesOpn}>
Hope this helps!
How can I move the green text from the image attached under the image icon?
I need to move it just under the image. I am using ReactJS and HTML. The text appears when a therapist has paid for their account.
<Link to={`/therapist/profile/${this.therapist.id}`} target="_blank" onClick={this.props.handleViewProfileGuest.bind(this, this.props.therapist.id)}>
<li key={this.props.index} className="tc-list-item">
{/* Avatar Container */}
<div className="tc-image-container">
<img src={this.getAvatarUrl(this.therapist)} alt='therapist-avatar' />
</div>
{/* User Profile Container */}
<div className="tc-info-container">
{/* Name & Title */}
<div className="tc-main-info">
<span className="tc-u-name">{`${this.therapist.firstName} ${this.therapist.lastName}, `}</span>
<span className="tc-u-title"> { ` ${this.therapist.title || 'Therapist'}` }</span>
</div>
<div className="flags-row">
{this.renderVerifiedFlag()}
{this.renderInsuranceFlag()}
</div>
{/* Details */}
<div className="tc-details-info">
{/* Email */}
<div className="tr-reviews-row">
<Rating placeholderRating={this.therapist.avgScore || 0}
emptySymbol={<img src={ratingStarEmpty} className="icon" alt="ratingEmpty"/> }
placeholderSymbol={<img src={ratingStarFull} className="icon" alt="ratingFull" />}
readonly/>
<span className="tr-reviews-value">{ `(${this.therapist.reviewCnt} reviews)` }</span>
</div>
{/* Phone */}
{this.renderContactInfo()}
</div>
</div>
<ReactTooltip type="info" place="right"/>
</li>
</Link>
and here is the css part
& .tc-image-container {
width: 130px;
height: 130px;
border-radius: 15px;
overflow: hidden;
}
& .tc-image-container img {
width: 100%;
height: 100%;
}
& .tc-info-container {
//margin-left: 140px;
flex: 1;
padding-left: 50px;
}
If I'm understanding your question correctly, its very simple... just move the div to the correct location in your html.
<Link to={`/therapist/profile/${this.therapist.id}`} target="_blank" onClick={this.props.handleViewProfileGuest.bind(this, this.props.therapist.id)}>
<li key={this.props.index} className="tc-list-item">
{/* Avatar Container */}
<div className="tc-image-container">
<img src={this.getAvatarUrl(this.therapist)} alt='therapist-avatar' />
</div>
<!-- Moved it to here -- >
<div className="flags-row">
{this.renderVerifiedFlag()}
{this.renderInsuranceFlag()}
</div>
{/* User Profile Container */}
<div className="tc-info-container">
{/* Name & Title */}
<div className="tc-main-info">
<span className="tc-u-name">{`${this.therapist.firstName} ${this.therapist.lastName}, `}</span>
<span className="tc-u-title"> { ` ${this.therapist.title || 'Therapist'}` }</span>
</div>
<!-- text was here -->
{/* Details */}
<div className="tc-details-info">
{/* Email */}
<div className="tr-reviews-row">
<Rating placeholderRating={this.therapist.avgScore || 0}
emptySymbol={<img src={ratingStarEmpty} className="icon" alt="ratingEmpty"/> }
placeholderSymbol={<img src={ratingStarFull} className="icon" alt="ratingFull" />}
readonly/>
<span className="tr-reviews-value">{ `(${this.therapist.reviewCnt} reviews)` }</span>
</div>
{/* Phone */}
{this.renderContactInfo()}
</div>
</div>
<ReactTooltip type="info" place="right"/>
</li>
Try moving the flag row to the left column:
// Add a new div with the class name "left-col"
<div className="left-col">
<div className="tc-image-container">
<img src={this.getAvatarUrl(this.therapist)} alt="therapist-avatar" />
</div>
// Move the flags-row div from its original place to here
<div className="flags-row">
{this.renderVerifiedFlag()}
{this.renderInsuranceFlag()}
</div>
</div>
<div className="tc-info-container">
...the rest of your DOM remains unchanged
</div>
// Give .left-col div the same width as the current image-container.
& .left-col {
width: 130px;
}
You might need to fiddle with the CSS a bit. But the general idea is here.
Moving the verified provider text code directly under the img code will do the trick.
Might just have to adjust bottom margin for the img for spacing.
I am having trouble trying to have a responsive grid of 3 boxes with some aligned content inside using the library Bulma. I would like to make it work still maintaining the level inside a box if possible.
Any help would be appreciated.
This is the result I expect:
But when decreasing the width, it breaks:
This is the code I am using:
<div className="columns sub">
{this.props.options.map(option => (
<div className="column is-one-third" key={option.id}>
<div
name={option.id}
className={
`box ` +
(this.props.optionToBeChosen === option.id
? "box-is-active"
: "")
}
onClick={() => this.props.onClick(option.id)}
>
<div className="level is-mobile">
<div className="level-item level-left">
<div>
<p className="box-text-title">{option.title}</p>
<p className="box-text-small">{option.description}</p>
<p className="box-text-small">{option.description2}</p>
</div>
</div>
<div className="level-item level-right has-text-right">
<div>
<p className="box-text-demo">{option.cta}</p>
</div>
</div>
</div>
</div>
</div>
))}
</div>
The Bulma levels are explicitly told not to shrink
.level-left, .level-right {
flex-basis: auto;
flex-grow: 0;
flex-shrink: 0;
}
You'll have to override that to get the levels to not break out of the .box elements.
Rather than overriding ALL level items, I suggest you add a custom class to those levels that you want to be able to shrink.
Something like
<div class="level is-mobile level-is-shrinkable">
Level items here...
</div>
<style>
.level-is-shrinkable .level-left,
.level-is-shrinkable .level-right {
flex-shrink: 1;
}
</style>
In my case, I had to add a third styling condition for centered level-item elements:
.level-is-shrinkable .level-left,
.level-is-shrinkable .level-item,
.level-is-shrinkable .level-right {
flex-shrink: 1;
}
Many thanks to just-a-web-designer for his|her answer.