Expand Elements to occupy entire width

My CSS skills are still in the early stages. I haven't delved too deeply into it.

I have a query regarding how to achieve full width for an element. I've included my code below, but the basic approach I tried using 'width: 100%' didn't yield the desired result.

In my React Native code, components are nested hierarchically. The higher-level code acts as the parent of the subsequent code blocks. I want the elements in RideCard.js (each ride card) to expand fully alongside DateDay.js. Upon removing flexDirection: row from oneDayContainer in MonthBody.js, I noticed that the elements expanded as intended. However, I wish to maintain the existing design.

Thank you in advance.

MonthBody > DateDay + RideList >

MonthBody.js

import { StyleSheet } from "react-native";
import { View } from "react-native";
import { useFirestoreContext } from "../../contexts/FirestoreContext";
import { DateDay } from "./DateDay";
import { RideList } from "./RideList";


export const MonthBody = ({ monthYear }) => {

  const { rides } =
      useFirestoreContext();

  return (
    <View style={styles.monthBodyContainer}>
      {Object.keys(rides[monthYear]).map((dateDay, j) => {
        return (
          <View style={styles.oneDayContainer}>
            <DateDay dateDay={dateDay} />
            <RideList monthYear={monthYear} dateDay={dateDay}  />
          </View>
        );
      })}
    </View>
  );
}



const styles = StyleSheet.create({
  monthBodyContainer: {
    display: "flex",
    flexDirection: "column",
  },
  oneDayContainer: {
    display: "flex",
    flexDirection: "row",
    alignItems: "flex-start",
  },
});

DateDay.js

import { StyleSheet, Text, View } from "react-native";

export const DateDay = ({dateDay}) => {
  return (
    <View style={styles.dateDayContainer}>
      <Text style={styles.dayText}>{dateDay.split("-")[1]}</Text>
      <Text style={styles.dateText}>{dateDay.split("-")[0]}</Text>
    </View>
  );
};

const styles = StyleSheet.create({
  dateDayContainer: {
    display: "flex",
    flexDirection: "column",
    alignItems: "center",
    justifyContent: "center",
    width: 50,
    marginRight: 20,
    marginTop: 10,
  },
  dateText: {
    fontSize: 16,
    textAlign: "center",
  },
  dayText: {
    fontSize: 12,
    textAlign: "center",
  },
});

RideList.js

import { StyleSheet, Text, View } from "react-native";
import { COLOR } from "../../assets/variables";
import { useFirestoreContext } from "../../contexts/FirestoreContext";
import { RideCard } from "./RideCard";
export const RideList = ({ monthYear, dateDay }) => {
  const { rides } = useFirestoreContext();

  return (
    <View style={styles.rideList}>
      {rides[monthYear][dateDay].map((ride, k) => {
        // return <RideCard key={k} ride={ride} />;
        return <RideCard key={k} ride={ride} />;
      })}
    </View>
  );
};

const styles = StyleSheet.create({
  rideList: {
    marginBottom: 5,
  },
});

RideCard.js

import { StyleSheet, Text, View } from "react-native";
import { COLOR } from "../../assets/variables";

export const RideCard = ({ ride }) => {
  console.log("RideCard", ride);
  return (
    <View
      style={[
        styles.container,
        ride.boardType === "NEED"
          ? { backgroundColor: COLOR.lightGreen, borderWidth: .3, borderColor: COLOR.green }
          : { backgroundColor: COLOR.lightBlue, borderWidth: .3, borderColor: COLOR.blue },
      ]}
    >
      <View style={styles.places}>
        <Text style={styles.placeText}>{ride.cityFrom}</Text>
        <Text> - </Text>
        <Text style={styles.placeText}>{ride.cityTo}</Text>
      </View>
      <View>
        <Text style={styles.dateText}>
          {ride.leavingHour}:{ride.leavingMinutes}
        </Text>
      </View>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    padding: 10,
    marginBottom: 5,
    borderRadius: 10,
  },
  places: {
    display: "flex",
    flexDirection: "row",
    alignItems: "center",
    marginBottom: 5,
  },
});

Answer №1

For the styling of CardList, make sure to include the property flex: 1 in the definition of rideList.

const styles = StyleSheet.create({
  rideList: {
    marginBottom: 5,
    flex: 1,
  },
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating an npm module using an external JavaScript API script

I am currently in the process of creating an npm package using code from this repository. In my possession is the "minified" js file called http_www.webglearth.com_v2_api.js, which is automatically downloaded by IntelliJ when the <script src=""> tag ...

Adjust the dimensions of the icon

My current project involves creating a sidebar with icons and associated text to represent each icon. However, I encountered an issue while trying to adjust the size of the icons within the sidebar using the "useStyles()" method. For some reason, the size ...

Caution: It is important to provide a unique "key" prop for each child in a list in my React Native application

When creating a Custom Side Menu for the Drawer menu in React Native, I passed some props but encountered a warning message: Warning: Each child in a list should have a unique "key" prop. CustomSideMenu.js /* eslint-disable prettier/prettier */ import R ...

react variable is not defined in render

I am facing a perplexing issue where I am unable to retrieve a state value in my renderer. Initially, I suspected it might be a scoping problem, but even after switching to 'var', the variable remains undefined. constructor(props) { super ...

I am looking for a solution on how to validate a token issued by Auth0 in a nodejs backend using jwt, but I keep

My React frontend uses Auth0 for user authentication. Once a user is logged in, I retrieve the token using getAccessTokenSilently() and send it to the backend like this: const { user, isAuthenticated, getAccessTokenSilently } = useAuth0() useEffect(() =&g ...

Why does the HTML and CSS slider fail to load upon page refresh, yet works perfectly when the next or previous button is clicked?

There seems to be an issue with the slider images not loading on page refresh. Oddly enough, they appear only after clicking the next button. However, upon refreshing the page again, the images disappear. <div class="slide-banner"> < ...

Hiding the dropdown icon in a React Semantic UI list can be done by using

Is it possible to remove the dropdown icon from a dropdown menu option in react semantic ui? import React from 'react' import { Dropdown, Menu } from 'semantic-ui-react' const DropdownExamplePointing = () => ( <Menu> < ...

Fixed positioning upon scrolling begins prior to reaching the uppermost point (top div)

Currently, I have implemented a feature where #filter (the white select list in my sidebar) becomes fixed when it reaches the top of the page and stays there while scrolling until it reaches the footer and is released. However, I encountered an issue wit ...

React: Unable to locate an index signature with a parameter of type 'string' on type N

While working with a React component, I encountered an issue when trying to access a property from my component state using a key. My editor showed the following warning: Element implicitly has an 'any' type because expression of type 'str ...

Modify JSON from using single quotes to double quotes using JavaScript

Received a JSON from the backend to the front end that uses single quotes throughout, causing issues with a Magento 2 widget. The JSON structure is as follows: { 'mood': 'happy', 'reason': 'why shouldn't I?'} T ...

Responsive HTML5 audio player adjusts size when viewed on mobile devices

I am facing a challenge with an HTML5 Audio player. It looks fine on desktop but behaves strangely on mobile devices. While the width remains intact, it repositions itself and floats over the element it is contained within. How can I prevent this repositio ...

Is it possible for node-java to accept anonymous functions as parameters in Java?

I am looking to pass an anonymous function from JavaScript to Java using node-java (https://github.com/joeferner/node-java). Below is a snippet of the Java code for reference: public class Example { public Example() { } public interface Callb ...

css readonly input textbox not changing background color when set

I've come across an old Classic ASP form that requires additional functionality, and I'm currently using IE11. To address this, I decided to include a doctype like so (even though I'm unsure of its necessity): <!DOCTYPE html> In my C ...

How React & Redux Infinite Scroll Triggered a Dispatch Error: Understanding the "Dispatch is not a Function" TypeError

Currently utilizing the react-infinite-scroll-component package for implementing infinite scrolling on my website. However, after setting it up with Redux and everything, when I reach the bottom of the page, I encounter an error in my action method: TypeEr ...

Issues with implementation of map and swiper carousel functionality in JavaScript

I am trying to populate a Swiper slider carousel with images from an array of objects. However, when I use map in the fetch to generate the HTML img tag with the image data, it is not behaving as expected. All the images are displaying in the first div a ...

Sending information from ngRoute resolve to the controller

I am currently working on an application that utilizes ngRoute to create a Single Page Application. One of the requirements is to ensure that the view is not loaded until the data has been successfully fetched from the database. While I have managed to ach ...

Why does 1&&2&&3 result in 3? Could someone clarify this for me?

During a recent interview, I was presented with this question about JavaScript evaluation order. My understanding is that in JavaScript, evaluation proceeds from left to right. So would 1 && 2 result in false? I came across another discussion where it w ...

A Guide to Sorting Nested Lists with SortableJS and jQuery

I have been experimenting with SortableJS and jQuery SortableJS Binding in order to create a nested list, capture the new order of the list and its children (resembling a hierarchical structure) using console.log(). I attempted the solution provided in th ...

Guide to summing the values in an input box with TypeScript

https://i.stack.imgur.com/ezzVQ.png I am trying to calculate the total value of apple, orange, and mango and display it. Below is the code I have attempted: <div class="row col-12 " ngModelGroup="cntMap"> <div class="form-group col-6"> ...

Mongoose is struggling to locate the expected result

I currently have three different schemas set up. User.js: const mongoose = require("mongoose"); const bcrypt = require("bcryptjs"); const userSchema = new mongoose.Schema({ name: { type: String, required: true, }, email: { type: String, ...