CSS problem with padding and width

Currently, I'm working on a conditional rendering issue where I want to give a div full width but due to padding applied to its parent, it's not expanding to the container's full width.

Here is the snippet of the code:

import Image from "next/image";

// Other imports...

interface TextBody {
  content: string;
  sent: boolean;
  time: string;
  replyReference: any;
}

const TextMessage = (props: TextBody) => {
  return (
    <div className="flex flex-col items-end w-[332px] ml-[52px] mr-[20px] mb-[18px]">
      // More JSX components inside...
    </div>
  );
};

export default TextMessage;

I'm currently seeing this output:

https://i.sstatic.net/MCxVg.png

This is what I aim to achieve:

https://i.sstatic.net/QkF8r.png

Answer №1

Make sure to transfer the classes

pr-[14px] pl-[14px] pt-[8px] pb-[8px]
to the reply-gradient and h1 elements.

Additionally, include rounded-l-[16px] rounded-b-[0] in the reply-gradient for consistent border styles with the parent component.

import Image from "next/image";
import DoubleTickIcon from "../PersonalChatAssets/DoubleTick.png";
import SingleTickIcon from "../PersonalChatAssets/SingleTick.png";
import { useRef, useEffect } from "react";
interface textbody {
  content: string;
  sent: boolean;
  time: string;
  replyReference: any;
}

const TextMessage = (props: textbody) => {
  console.log("Referece::::", props.replyReference);
  return (
    <div className="flex flex-col items-end w-[332px] ml-[52px] mr-[20px] mb-[18px]">
      <div className="flex justify-center items-center">
        <Image src={props.sent ? DoubleTickIcon : SingleTickIcon} alt="" />
        <h1 className="font-normal text-[12px] mb-0 font-[#787580]">
          {props.time}
        </h1>
      </div>

//this is its parent
      <div className="flex flex-col justify-center items-center bg-[#F7CA16] rounded-l-[16px] font-inter font-[14px] rounded-b-[16px] min-h-[40px] max-w-[340px] min-w-[60px] break-words">

//This is Conditional rendring part 
        {props.replyReference?.message !== undefined && (
          <div className="h-[52px] reply-gradient p-2 pr-[14px] pl-[14px] pt-[8px] pb-[8px] rounded-l-[16px] rounded-b-[0]">  
            <div className="-space-y-3 overflow-ellipsis truncate border-l-[4px] border-solid border-[#1F1D25] pl-2">
              <h1 className="">to {props.replyReference?.author}</h1>
              <p className="max-w-[230px] truncate ">
                {props.replyReference?.message}
              </p>
            </div>
          </div>
        )}

        <h1 className="flex justify-center item-center w-full h-full mb-0 pr-[14px] pl-[14px] pt-[8px] pb-[8px]">{props.content}</h1>
      </div>
    </div>
  );
};

export default TextMessage;

For demonstration purposes, you can explore this interactive tool

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

CSS Selector for when a radio button is selected

I'm currently using images in place of radio buttons: <label class="radio-inline thumbs"><input type="radio" id="type_nee" name="type" value="nee" onkeyup="validate()" onclick=" ...

ReactJS implementation for selecting names from a dropdown menu

Hello, I am new to using React. I have a dropdown form with a search engine in it that is working perfectly as I need. The only issue is that when I type, for example, AR in the Symbol field, it shows me ARDRBTC as expected, but I am unable to click on it ...

Is Window.navigator malfunctioning on different browsers in Mac OS?

I'm attempting to access the navigator function in my project to share a specific URL, but I'm facing difficulties accessing it on Mac OS when using browsers other than Safari. Is there a solution to this issue? Below is the function I created f ...

What is the best way to transfer data from one .tsx file to another using useState?

Seeking assistance with passing data between different .tsx files in React Native. Can someone provide guidance on how to achieve this? Below is a snippet of the code I have been working on: ToggleSettings.tsx interface ToggleSettingProps { id: string ...

What is preventing the 'p:nth-child(1)' from functioning properly in my HTML code?

Even though I used p:nth-child(1){color: white;} in my CSS style tag, it did not produce the expected result. body { background-color: #162b85; } button, p:nth-child(1) { color: white; } <p class="center">Register your account</p&g ...

When text is wrapped within the <li> tag

In this div, the structure is as follows: <div class="box1" id="infobox"> <h2> Point characteristics: </h2> <div style="padding-left:30px" align="left"> <ul> <li class="infobox_list"><b>X value: </b>< ...

Conflicting React types found in pnpm monorepo

In the process of converting an inherited monorepo from yarn+lerna to pnpm workspaces, I am encountering some issues. Specifically, there are mismatching React versions causing errors in typescript. It seems that TypeScript is not recognizing the closest @ ...

Is it feasible to have two interfaces in Typescript that reference each other?

I am facing an issue with two interfaces, UserProfile and Interest. Here is the code for both interfaces: export default interface UserProfile { userProfileId: string, rep: number, pfpUrl: string, bio: string, experience: "beginner" | " ...

Adjusting the size of images in a Bootstrap lightbox gallery

I am currently working on a website for an artist, making the galleries a key aspect. The website is built using Bootstrap, with the Lightbox for Bootstrap plugin being used for the galleries. Everything seems to be working well in terms of adjusting the i ...

Is there a way to change the orientation of the cards so that they move from left to right instead of

I am looking to have my cards displayed from left to right rather than vertically, but I'm struggling to achieve this. I have tried using the float: left property with no success. Below is an example of a single card in my layout. They all follow the ...

JavaScript issue causing unexpected behavior in top and left positions

I've been experiencing an issue with my JavaScript code on an HTML file. Despite changing the top or left values, the image does not move as expected. I've spent hours searching for a solution and even tried copying tons of different code snippet ...

Change the font style of individual characters within a string using CSS or JavaScript, instead of applying it to the entire

Is it feasible to assign a specific font to a particular character? I would like: #test_id{ font-family: "digitalfont"; font-family-of-, : "HelveticaNeue-Light"; } In order to set a font for a comma and a separate font for the rest, do I need to ...

Exclude defaults from the Material UI Autocomplete options

I am using a Material-ui autocomplete element (tags mode) that has a list of options and default selections. Is there a way to prevent the defaults from being added again? I attempted to achieve this with the following code: for (var i = options.length - ...

Trouble with history.push not functioning until button click in sync or wait mode

When attempting to navigate a page without refreshing using "history.push()", I encountered an issue where it only works when clicked by a human via a button. Programmatically triggering the navigation did not work as expected, as it only updated the URL w ...

Navigate to the correct page when the Button is clicked in a ReactJS/Django project

Embarking on my web development journey, I opted for django/Reactjs to build a social network platform. I created several API methods like account/view_user/ to retrieve a list of users and account/view_user/ for specific user attributes. In React, I cra ...

Tips for showcasing numerical data above a bar graph using Echart-for-React

I've been exploring data visualization with Echarts using the library from https://github.com/hustcc/echarts-for-react. Is there a way to show the precise numbers on top of each bar in the chart? For instance, displaying 30,000 on top of the first bar ...

ReactJS Alert: It is advisable for each child in an array or iterator to possess a distinct "key" property

var divArr = [ '<div>布吉岛啊</div>', '<div>呵呵呵</div>', ]; ReactDOM.render( <div>{divArr}</div>, document.getElementById("example") ); but ...

Displaying and concealing table rows based on selected items

After spending a whole day trying to get this HTML/java script to work properly, I came across some code online that I used here. My goal is to have the "Colors*" row not displayed when the page loads, but to show the color options when a shirt size is sel ...

Expanding Gridview Width within a Container in ASP.Net: A Step-by-Step Guide

https://i.stack.imgur.com/ZaJE7.jpg After viewing the image above, I am facing a challenge with stretching and fixing a gridview to contain the entire div where it is placed. The issue arises when the gridview adjusts automatically based on the content&ap ...

What is the best way to incorporate the .top offset into a div's height calculation?

Looking to enhance the aesthetic of this blog by adjusting the height of the #content div to match that of the last article. This will allow the background image to repeat seamlessly along the vertical axis. I attempted the following code: $(document).re ...