Achieving inline display of material-ui components through styling props override

I am struggling to position a checkbox to the right of the "answer input one" field. I've tried adjusting the display property without success. You can see the current layout here.

Below is the code for rendering the answer input:


  <div>
    <TextField
      hintText="An informative question title..."
      fullWidth
      floatingLabelText="Question Title"
      value={questionTitle}
      onChange={(e) => this.props.questionTitleChanged(e.target.value)}
    />

    <TextField
      floatingLabelText="Answer Input 1"
      onChange={(e) => this.props.questionInputChanged({
        inputIndex: 0,
        value: e.target.value,
        correct: false
      })}
      value={questionInputs[0].value}
      style={styles.answerField}
    />

    <Checkbox
      onCheck={() => {
        let correctOrIncorrect = null;

        if (questionInputs[0].correct) {
          correctOrIncorrect = false;
        } else { 
          correctOrIncorrect = true; 
        }

        this.props.questionInputChanged({
          inputIndex: 0,
          value: null,
          correct: correctOrIncorrect 
        });
      }}
      style={styles.checkbox}
    />

  </div>

Inline styles used in the code are as follows:


const styles = {
  createQuizContainer: {
    width: '70%',
    margin: 'auto',
    paddingTop: 30,
    paddingBottom: 40
  },
  answerField: {
    width: '70%',
  },
  checkBox: {
    display: 'inline',
  }

};

I would greatly appreciate any help or advice on working with CSS layouts!

Thank you.

Answer №1

To achieve the layout, you can utilize flexbox:

render() {
    return (
        <div style={{ display: 'inline-flex' }}>
            <div>
                <InputField />
            </div>
            <div style={{ alignSelf: 'center' }}>
                <CheckBox />
            </div>
        </div>
    );
}

https://jsfiddle.net/5t8z7mqn/1/

Answer №2

I decided to modify the styling of the checkbox by adjusting its properties:

checkbox: {
    float: 'right',
    width: '10%',
    marginTop: '7%'
  }

This change was made because the checkbox was originally taking up the full width. While not a perfect solution, it achieves the desired outcome.

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

What is the process of importing Material-Icons into Hyperstack?

I am attempting to incorporate MaterialUi's <MenuIcon /> (similar to the example at https://material-ui.com/demos/app-bar/) into my Hyperstack-App, but encountering the following error. Following the installation of @material-ui/icons using yar ...

Ensure that newly added elements are aligned with the settings of the slide's

I've encountered an issue with my jQuery slider that affects a div's CSS on slide. Everything works as expected, except when I add a new div, the settings from the slider aren't applied to the new div until the slider is moved again. HTML ...

Click X button to toggle and close the dropdown menu

After successfully creating a responsive menu that toggles with a hamburger icon at 1205px resolution, I encountered an issue. Once the hamburger icon is clicked and the dropdown menu opens, there seems to be no way to close it. I am looking to add an X bu ...

Issue with Material-UI component not rendering properly in react-rails pre-rendering

Looking to dynamically include a React component using JavaScript? For example, when a user clicks "Add Place," a form is added to the page with a React component that utilizes material-ui's auto-complete feature. Here is the code snippet for the dyn ...

The visibility of content that flickers on the webpage should be hidden with the display: none property during loading

Currently working on a new toy website, but encountering some unexpected behavior. On the homepage HTML file, there are two separate sets of <body> tags: <body class = "intro">...</body> <body class = "home">...</body& ...

Having trouble setting a background image for a specific DIV element in HTML

I am in the process of updating my webpage, and need some assistance implementing a small background image. Here is what I have done so far: https://i.sstatic.net/nTxtD.png Below is the marked section where I am trying to add the background image: https ...

Using the / (forward slash) in CSS styling statements

Similar Query: Understanding the CSS font shorthand syntax As I was examining the styling on Apple's website, I encountered a CSS rule that left me puzzled: body { font: 12px/18px "Lucida Grande","Lucida Sans Unicode",Helvetica,Arial,Verdana, ...

Script modifies div dimensions independently of CSS styling

Recently, I received assistance from this community in creating a script that displays random images from an array within 4 divs. Each image changes upon refresh or with a timer. HTML: <section> <div id="square_1" class='box'> ...

Absence of MVC5 Vanilla Layouts

Creating my first MVC5/Razor application from the ground up, I want to avoid including unnecessary references that cause bloat. In the Views folder, I have separate Home and Shared subfolders. The Home folder contains Index.cshtml, while the Shared folder ...

Adjusting the size of a Google map based on the size of the browser

Currently, I am working on implementing Google Maps API v3. The map is displaying perfectly on my page, but the issue arises when I resize the browser. Upon resizing, the map reverts to its original size as it was when the page initially loaded. This is t ...

What is the reason for requiring the addition of "repeat" to ensure that it appears on the

Check out my website Take a look at my custom CSS dot { background:url("images/non_selected.png") repeat scroll 22px 22px transparent; height:22px; width:22px; } After making this change url("images/non_selected.png") norepeat scroll 22px 22px tran ...

What is the user-agent string for the Safari home screen?

Is there a unique user-agent string specifically for Safari on IOS that identifies it as being in "Home screen" or "app mode"? I've observed a bug on IOS8 where the browser window appears incorrectly, with the time and battery information overlapping ...

When using HTML/Bootstrap5, the ms-auto class does not correctly align items to the right in the navbar

I'm currently working on mastering bootstrap through an online tutorial, but I've hit a roadblock when it comes to right-aligning items in a navbar. I've double-checked my code against the instructor's, and it's a perfect match: &l ...

Here are the steps to effectively incorporate CSS classes in a form using Laravel Collective 5.2 framework

Hi there, I am currently working on developing an application and find myself in need of implementing CSS classes to a form using Collective Laravel "5.2.*". The snippet of code that I have at the moment is as follows: {!! Form::model($user, array(&apos ...

Is it possible to retrieve the current selector as a string in LESS?

Is there a way to utilize the name of my css classes to specify the URL for an image they depend on? I know that using an ampersand within a selector allows you to add additional states, but can it be accessed as a string? For example: .my-image{ back ...

Issues with Media Queries on Desktop Devices

I've encountered an odd issue with my media queries. While they function properly on my mobile devices, resizing my desktop browser doesn't seem to trigger the changes. This prevents me from inspecting my mobile styles using web inspector/firebug ...

Tips for managing images within the CardMedia component in React Material UI

Some specific images appear much larger and have hidden parts:https://i.stack.imgur.com/God1D.png I've managed to adjust the size somewhat by experimenting with width and height: const useStyles = makeStyles((theme) => ({ ... media: { ...

Utilizing the @page CSS rule in Vue.js: A step-by-step guide

I am facing an issue with printing a specific page in landscape mode. Here is the code snippet I have been using: @page { margin: 0; size: A4 landscape; } The problem is that this style rule affects all pages in my application because all style se ...

Attempting to achieve the effect where the entire row of a table changes color when the mouse hovers

I'm attempting to create a gradient effect for an entire row in a table when the mouse hovers over any cell within that row. Despite using what I believe is the correct CSS code, nothing changes upon mouseover (even though the original gradient appear ...

Creating a div that automatically resizes to fit a specific width, with excess content wrapping to the next row

In our project, we currently have a design with 4 div elements arranged in two rows and two columns. However, the client has requested that we allow for multiple div elements within a container that spans 100% width. The inner divs should adjust to fit si ...