Relocate the text within the confines of the border

Currently, I am attempting to position the text within a bold border of its parent element. My component, built using material-ui, resembles this code:

   <List className={classes.root}>
       <Typography className={classes.fieldLabel}>Attach PDF</Typography>
             {/***SOME CODE**/}
  </List>

The styles for the two classes (root and fieldLabel) are defined as follows:

root: {
    width: "100%",
    maxWidth: 360,
    border: "3px solid #388FCE",
    marginLeft: "3%",
    maxHeight: 200,
    overflow: "auto",
    borderTop: "40px solid #388FCE",
    position: "relative",
  },


 fieldLabel: {
    transformOrigin: "0 0 ",
    position: "absolute",
    fontSize: "1rem",
    textTransform: "uppercase",
    letterSpacing: "3px",
    top: 0,
    left: 0,
    color: "red",
    fontWeight: "bold",
  },

I am struggling with getting the "Attach PDF" label to appear inside the border:

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

What could I be doing incorrectly that is causing the label to remain inside the border instead of appearing on it?

Answer №1

If you want to add a heading to the material-ui List without forcing it into a border, simply wrap the List in a separate component that displays the header before the list:

const ListWithHeading = ({heading, classes, children, ...props}) => (
    <div className="list-container">
        <Typography className={classes.fieldLabel}>{heading}</Typography>
        <List classes={classes} {...props}>{children}</List>
    </div>
);

You can style the element containing the heading by adding a specific class, such as setting a background color and making it full width.

To render this structure, use the following code:

<ListWithHeading heading="Attach PDF">
    {/* list items here */}
</ListWithHeading>

Answer №2

Instead of attempting to manipulate space and time in order to relocate the text, why not simply eliminate the top border? This way, the height and background of the text will seamlessly blend with the intended layout.

I have customized your elements using classes, and it just works without distorting space or time :)

.container {
    width: 100%;
    max-width: 360px;
    border: 3px solid #388FCE;
    margin-left: 3%;
    max-height: 200px;
    overflow: auto;
    border-top: none;
    display: block;
  }


 .labelText {
    height: 40px;
    line-height: 40px;
    background: #388FCE;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: red;
    font-weight: bold;
    display: block;
    padding-left: 10px
  }
<List class="container">
       <Typography class="labelText">
        Attach PDF
       </Typography>
             {/***SOME CODE**/}
  </List>

Answer №3

My recommendation would be to utilize the ListSubheader component from Material-UI, which can be found at https://material-ui.com/api/list-subheader/

   <List 
      className={classes.root} 
      subheader={
        <ListSubheader className={classes.subHeader} component="div">
          Attach PDF
        </ListSubheader>
      }>
          {/*** Your List Items**/}
  </List>

You can also customize it with styles. For example:

subHeader: {
  background: '#388FCE',
  // add any other necessary styles here
}

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

Angular JS Directive is a powerful feature that allows developers

There are three HTML screens available. Screen1.html: <button id="screenbtn"></button> Screen2.html: <div id="sctmpl"> <label>Label for screen two</label> </div> Screen3.html: <div id="sctmpl1"> <l ...

Encountering a blank screen issue post building with vue-cli-service and electron:build

I have attempted various solutions to eliminate the blank screen issue in my electron application: (1) I tried commenting out createProtocol and loadURL('app:...') in background.js and instead using path.join(): if (process.env.WEBPACK_DEV_SERVE ...

Using React: Passing the state value of Child1 to the Parent component, then passing it back down to Child2 from

Within my application, I've implemented two child components: 'FoodScreen' and 'OperationScreen', along with a parent component called 'Desk'. I am passing a JSON array variable to the FoodScreen component in order to sel ...

the sorting functionality failing to switch between ascending and descending orders

I have been diligently working on a table that organizes cat data using pure JavaScript and jQuery. Although I am close to completion, I am struggling with implementing sorting functionality for my table headers in both ascending and descending order. I ha ...

Showing no background color until the user lifts their finger

I am currently in the process of developing a website. The navigation on the website starts off as transparent (background: transparent) when opened, but as soon as you start scrolling, it should transition to a colorful state with shades like grey, midnig ...

aligning a trio of button pieces to seamlessly merge in CSS

I have a total of 6 files that I need to work with. They are as follows: button_01.png (left side of the button) button_01-RO.png (rollover effect) button_02.png (middle part of the button) button_02-RO.png (rollover effect) button_03.png (right side ...

increase the number of rows in the table automatically

I've encountered an issue while working on a form that involves getting a value from a jQuery spinner and dynamically adding that number of rows to a table inside the form. Despite using firebug to debug, I couldn't pinpoint the exact cause of th ...

Is AngularJS causing issues with Foundation modals? Any solutions to this problem?

Wondering how to manage Foundation4 modals with AngularJS? I've noticed that when I navigate from a modal to a new view, the old modal disappears but the page stays darkened as if it's still there in the background. I tried adding a class attribu ...

Issues with the CSS animation not properly scaling

I'm currently working on an animation using CSS keyframes. Here is what I have: @keyframes experience { 0% { -webkit-transform: scale(0,0); transform: scale(0,0); -webkit-transform: translateY(40px); transform: translateY(40px); opac ...

Using res.locals with TypeScript in Next.js and Express

In my express - next.js application, I am transferring some configuration from the server to the client using res.locals. My project is written in typescript and I am utilizing "@types/next": "^8.0.6". The issue at hand: typescript is throwing an error st ...

Ways to merge duplicate entries in an html table?

As a junior developer working on my first project, I am currently struggling with creating a stats page for my application. My main issue is how to display the data in a user-friendly manner. After looking at similar applications, I noticed that they used ...

Tips for effectively managing errors in Next.js getStaticProps

Currently, I am immersed in the development of my inaugural Next.JS application (Next and Strapi). All functionalities are operational, but I am interested in discovering the optimal approach to integrate error handling within getStaticProps. I have exper ...

Ways to incorporate a dependency from an external script

Utilizing a cloud service known as Parse within a JavaScript closure implemented with require.js: define([/*some dependencies*/], function(/*some dependencies*/) { ... // utilizing Parse. For instance: var TestObject = Parse.Object.ex ...

Python makes sure that HTML values remain constant even after a button is clicked by Selenium

I am currently utilizing Soup and Selenium to access a particular page . My objective is to extract a comprehensive list of pricing and ratings for different types of packaging available on this webpage. https://i.sstatic.net/3gbJ7.png Displayed below is ...

What are the steps to install the LTS release of NodeJS if Node 10 is already installed on my system?

Several weeks ago, I installed Node version 10.11 on my computer. However, a repository I am working with requires me to have the LTS version of Node, which is currently 8.12. If I download the LTS version, will it interfere with my existing install, or ...

Kineticjs is not performing up to par

I apologize if this question has already been asked, but I haven't been able to locate it. I am working on a project that involves a canvas displaying approximately 400-500 rectangles, each ranging in height and width from 20-30 pixels. The goal is t ...

What is the reason behind JSF using the file extension .jsf and GET parameter ln=js for delivering JavaScript resources?

Take this as an example: <h:outputScript library="js" name="foo.js" /> This can be transformed into: <script type="text/javascript" src="/welcomepage/javax.faces.resource/foo.js.jsf?ln=js"></script> Pay attention to the .jsf?ln=js ...

Combining react-draggable and material-ui animations through react-transition group: a comprehensive guide

Trying to incorporate react-draggable with material-UI animations. One approach is as follows: <Draggable> <Grow in={checked}> <Card className={clsx(classes.abs, classes.paper)}> <svg classN ...

Using htmlentities in PHP while maintaining the integrity of HTML tags

I am looking to convert text within a string into HTML entities while still maintaining the HTML tags. For instance: <p><font style="color:#FF0000">Camión español</font></p> The desired output would be: <p><font style= ...

Developing microfrontends using Angular involves loading and navigating a compiled package from npm

I have been struggling to find a solution to an ongoing issue and wasting time on futile attempts. Currently, I am working with Angular 15 within a microfrontend architecture. My goal is to implement a system where I can download a compiled microfrontend ...