set child element to be 100% width of parent - html

I have a main element which is divided into a grid of 3 columns.
in the middle column I am displaying some listings.
each listing is a div element and has a react bootstrap card inside it.
I am trying to get the card to span 100% of the parent but that doesn't seem to be working for me.
React component
<div className="backfill">
<Row key={Listing_Id}>
<Card style={{ cursor: 'pointer' }} border="light" className="text-center fullCard" >
<Card.Body>
<Card.Title className="Title">
{Listing_Name}
<hr />
<Button className="Button" variant="outline-success" onClick={() => props.handleLikeDisLike(Listing_Id, 'Listing_Likes', Listing_Location)}> <Twemoji options={options} text=":+1:" /></Button>
<Badge className="Badge" variant="light">{Listing_Likes}</Badge>
<Button className="Button" variant="outline-danger" onClick={() => props.handleLikeDisLike(Listing_Id, 'Listing_DisLikes', Listing_Location)}><Twemoji options={options} text=":-1:" /></Button>
<Badge className="Badge" variant="light">{Listing_DisLikes}</Badge>
<hr />
<Button className="Button" variant="outline-info" ><Twemoji text=":pushpin:" /></Button>
<Badge className="Badge" variant="light">{Listing_Location}</Badge>
</Card.Title>
<Card.Text className="Listing" onClick={() => handleClick(Listing_Id)} >
<hr />
{ListingBody}
<ModalLayout
Listing_Location={Listing_Location}
Listing_Likes={Listing_Likes}
Listing_DisLikes={Listing_DisLikes}
Listing_Name={Listing_Name}
Listing_Id={Listing_Id}
handleLikeDisLike={props.handleLikeDisLike}
handleClose={closeModal}
show={showModal} />
</Card.Text>
</Card.Body>
</Card>
</Row>
<br />
</div >
CSS for div and Card elements
.backfill {
background-color: aqua;
}
.fullCard {
width:'100%';
}
I currently end up with the UI looking like this. Please can you help me sort this out. I want to get the card to be 100% of its parent div.

Just had to remove the single quotes from the CSS
.fullCard {
width:'100%';
}
had to become
.fullCard {
width:100%;
}

Related

How to fix badge position in menu header React with ant design

im trying to put an element Badge to the right of header menu in my page, but I don't know how do that, currently de Menu element of ant design push to another position the badge (bell icon):
The code:
const HeaderComp = (props) => {
let navigation = useNavigate()
const root= AppConfig.BucciaratiRoot.length>0 ? "/"+AppConfig.BucciaratiRoot:"/"
return (
<Layout>
<Header className="header" style={{position:'fixed', zIndex: 1, width: '100%'}}>
<div style={{float:'left', marginRight:'5%'}}>
<img style={{width: 120, height:31}} src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Suzuki_Motor_Corporation_logo.svg/2560px-Suzuki_Motor_Corporation_logo.svg.png"/>
</div>
<Menu theme="dark" mode="horizontal" defaultSelectedKeys={['1']} >
<Menu.Item key="1" onClick={()=>navigation(root)}>Home</Menu.Item>
<Menu.Item key="3">About</Menu.Item>
</Menu>
<div style={{float:'right', marginLeft:'5%'}}>
<Badge dot>
<BellOutlined />
</Badge>
</div>
</Header>
</Layout>
)
}
How cain I put the badge to the right of the header menu ?
You can use flex instead of float, and then but every element you want to be at the right in a div and every element to the left in another div, and using some justify-content:"space-between" property in flex you can make the space left in the navbar to be in between those to divs.
See more on FlexBox
your code should look like:
return (
<Layout>
<Header
className='header'
style={{
position: "fixed",
zIndex: 1,
width: "100%",
display: "flex", // make the header flex
justifyContent: "space-between", // put all the space between the left and right sections of the menu
}}
>
<div className='header-left'>
{/* The left side of the menu */}
<div style={{ /* remove float */ marginRight: "5%" }}>
<img
style={{ width: 120, height: 31 }}
src='https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Suzuki_Motor_Corporation_logo.svg/2560px-Suzuki_Motor_Corporation_logo.svg.png'
/>
</div>
<Menu
theme='dark'
mode='horizontal'
defaultSelectedKeys={["1"]}
>
<Menu.Item key='1' onClick={() => navigation(root)}>
Home
</Menu.Item>
<Menu.Item key='3'>About</Menu.Item>
</Menu>
</div>
<div className='header-right'>
{/* The right side of the menu */}
<div style={{ /* remove float */ marginLeft: "5%" }}>
<Badge dot>
<BellOutlined />
</Badge>
</div>
</div>
</Header>
</Layout>
);
<Layout>
<Header
className="header"
style={{
position: 'fixed',
zIndex: 1,
width: '100%',
display: 'flex',
justifyContent: 'space-between',
}}
>
<div>
<div style={{ marginRight: '5%' }}>
<img
style={{ width: 120, height: 31 }}
src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Suzuki_Motor_Corporation_logo.svg/2560px-Suzuki_Motor_Corporation_logo.svg.png"
/>
</div>
<Menu theme="dark" mode="horizontal" defaultSelectedKeys={['1']}>
<Menu.Item key="1" onClick={() => navigation(root)}>
Home
</Menu.Item>
<Menu.Item key="3">About</Menu.Item>
</Menu>
</div>
<div style={{ marginLeft: '5%' }}>
<Badge dot>
<BellOutlined />
</Badge>
</div>
</Header>
</Layout>;

How can I make elements on my web page be on opposite sides of their container instead of right next to each other?

The words, and buttons are right next to each other to the left. How can I make the words stay on the left and the buttons stay on the right?
The picture of the page is below.
This is a page written in React.
The issue is somewhere in the Accordian.Header container. If you remove it, the elements stay on opposite sides of their container as desired.
<MainScreen title='Welcome Back Anthony!'>
<Button style={{ marginLeft: 10, marginBottom: 6 }} size='lg'>
Create New Note
</Button>
{notes.map((note) => (
<Accordion>
<Accordion.Item>
<Card style={{ margin: 10 }} key={note._id}>
<Accordion.Header style={{ width: '100%'}}>
<Card.Header style={{ display: 'flex' }}>
<span
style={{
color: 'black',
textDecoration: 'none',
flex: 1,
cursor: 'pointer',
alignSelf: 'center',
fontSize: 18,
}}
>
<div as={Card.Text}
variant='link'
eventKey='0'>
{note.title}
</div>
</span>
<div>
<Button href={`/note/${note._id}`}>Edit</Button>
<Button
variant='danger'
className='mx-2'
onClick={() => deleteHandler(note._id)}
>
Delete
</Button>
</div>
</Card.Header>
</Accordion.Header>
<Card.Body>
<Accordion.Body>
<h4>
<Badge variant='success'>
Category - {note.category}
</Badge>
</h4>
<blockquote className='blockquote mb-0'>
<p>
{note.content}
</p>
<footer className='blockquote-footer'>
Created on - date
</footer>
</blockquote>
</Accordion.Body>
</Card.Body>
</Card>
</Accordion.Item>
</Accordion>
))}
</MainScreen>

How can I move the green text under the image?

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.

How we can make a div placed inside a link tag to be non-navigated

I am having a tile. Clicking anywhere on it should redirect to a new page.I have kept my complete code inside Link tag so that whenever i will click on any part of that div, it will navigate to the new page. But inside that Link tag, there is a subdiv, clicking on which i don't want to perform redirection.
The problem i am facing is that if i will close the link tag before that particular div on which i don't want to perform redirection then, remaining area of the parent div is also becoming non-clickable except the written p tags. How i can make only that particular div non-redirectable.
<Link to={{ pathname: '/demo_summary/'>
<div className="ctd-tile" style={{ margin: "10px", height"260px" }}>
<p>VERSION: {i.version}</p><br />
<p>Complexity: {i.complexity}</p><br />
<div className="col-md-4">}}>
<img src={require("../images/icon1.png")} title="DEMO PLAN" /></Link>
</div>
<div className="col-md-4">
<input type="image" title="View HTML" src={require("../images/viewAsHtml.png")} style={{width: "40%", cursor: "pointer"}} onClick={(e) => { e, that.openReport(e, i.demoName) }}/>
</div>
<div className="col-md-4">
<Download file={i.name} content={text}>
<img src={require("../images/download.png")} title="DOWNLOAD" style={{ width: "25%", cursor: "pointer" }} />
</Download>
</div>
</div>
</Link>
I want to make second div having title as "View HTML" to be non-redirectable.
Pass the history to your component as prop then use push to redirect or stop the event with
e.stopPropagation();
Example:
const navigation = ({ history }) => {
return (
<div>
<a
onClick={() => {
history.push("/cool");
}}
>
rediction
<span
onClick={e => {
e.stopPropagation();
}}
>
none redirection
</span>
</a>
</div>
);
};
You need to use event.stopPropagation on the onClick of the div you want to stop redirecting.
When you have nested tags, if you click on one tag, you will trigger the onClick of the tag and the parent onClick too.
function App() {
return (
<div onClick={() => console.log('parent onClick')} >
<button onClick={() => console.log('button click')}>Click me</button>
</div>
)
}
const rootElement = document.getElementById("app");
ReactDOM.render(<App />, rootElement);
<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>
<div id="app"></div>
But if you use event.stopPropagation on the children div. The parent tag wont have it onClick event triggered.
function App() {
return (
<div onClick={() => console.log('parent onClick')} >
<button onClick={e => {
e.stopPropagation()
console.log('button onClick')
}}>Click me</button>
</div>
)
}
const rootElement = document.getElementById("app");
ReactDOM.render(<App />, rootElement);
<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>
<div id="app"></div>
So now you know that, just add e.stopPropagation() to the onClick of the div you don't want to trigger the Link's onClick.
Edit:
Your code have something very weird
onClick={(e) => { e, that.openReport(e, i.demoName) }} // ????
But what you should do is
onClick={(e) => {
e.stopPropagation();
that.openReport(e, i.demoName);
}}
Here is the full code
<div className="col-md-4"
onClick={(e) => {
// added stopPropagation in the correct place
e.stopPropagation();
that.openReport(e, i.demoName);
}}
>
<input
type="image"
title="View HTML"
src={require("../images/viewAsHtml.png")}
style={{width: "40%", cursor: "pointer"}}
onClick={(e) => {
// added stopPropagation in the correct place
e.stopPropagation();
that.openReport(e, i.demoName);
}}
/>
</div>

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>