Ensure that the display is set to block to stack the input elements on top of each other

I am attempting to grasp the functionality of CSS display property and experimented with this basic HTML code:

<div>
  <form className="container" action="">
    <input name="fName" placeholder="First Name" type="text" value={props.fName}/>
    <input name="sName" placeholder="Second Name" type="text" value={props.sName} />
    <button>Submit</button>
  </form>
</div>

Despite my efforts, the two input boxes appear horizontally aligned rather than stacked on top of each other. In an attempt to correct this, I added some CSS styling.

.container{
  text-align: center;
  display: block; 
}

However, I was puzzled as to why the display block property did not have the desired effect. Shouldn't it apply to the child elements as well?

Interestingly, when I applied display: block; directly to the input element, it worked as intended. This has left me wondering about the intricacies of how CSS properties are inherited by different elements.

Answer №1

By setting display: block; on the container, you won't automatically stack its children vertically since <input> elements are naturally inline-block and will sit side by side. To achieve vertical stacking, you must apply display: block; directly to the <input> elements.

.container input {
  display: block; 
}
<div>
  <form class="container" action="">
    <input name="fName" placeholder="First Name" type="text" value={props.fName}/>
    <input name="sName" placeholder="Second Name" type="text" value={props.sName} />
    <button>Submit</button>
  </form>
</div>

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

Focus on a specific div element while bypassing its parent

Can I directly target the element with .div-3 class, even if its parent does not have an id or class? <div class="wrapper"> <div> <div> <div class="div-3"> </div> </div> </div> </div> I am aware ...

What is the best way to locate elements with the term "download" in them using Selenium's x-path feature?

I'm currently utilizing Selenium for web scraping purposes and I am in need of a way to identify all clickable elements that contain the word "download" (regardless of capitalization) within their link text, button text, element ID, element class, or ...

Learn how to separate two SCSS files and compile them into individual CSS files

Currently, I have two SCSS files that need to be compiled into separate CSS files. For one of the SCSS files, my script looks like this: "watch:sass": "node-sass assets/stylesheets/custom.scss assets/stylesheets/custom.css -w", "compile:sass": "node-sass ...

An issue with type conversion arises in Visual Basic when trying to access data from an HTML

I'm currently working with an HTML table that allows for dynamically adding and deleting rows with text-input's in the cells using JavaScript. Instead of ASP.NET TextBox controls, I am sticking to traditional HTML because I believe rows containin ...

Autofill Dropdown in AngularJS Using Data from Previous Page

Despite searching extensively on StackOverFlow, I was unable to find the answer I needed. So, I am posting my question below. I have a form that includes a dropdown menu. When a user clicks a button, they are taken to a new HTML page with additional infor ...

I am having trouble getting the (:active) pseudo-class to function properly with the menu on my WordPress theme

Purchased a theme called HelpGuru and encountering issues with the CSS of the menu. Reached out to support but they were unable to assist, directing me to a company that specializes in customizing WordPress themes instead. The link to the demo can be found ...

How can you turn off CSS3 animations for browsers that don't support them

Upon page load, a fade-in animation is applied to the main container. Although it functions properly in most browsers, it seems to have an issue in IE(9). Is there a method to identify if the user's browser does not support CSS3 animations and disabl ...

How can we add a class to a radio button using jQuery when it is checked, and remove the class when it

I'm looking for help with using jQuery to toggle between two radio buttons and display different divs based on the selection. jQuery(document).ready(function($) { if ($('#user_personal').is(':checked')) { $('.user_co ...

Leveraging retrieved data for conducting further JavaScript assessments through ajax

I have a mail.php file that is triggered by an ajax script. The purpose of the mail.php file is to conduct server-side validation and, if successful, send an email using mail() along with the data received from the ajax request. Now, I am looking to take ...

Button click not functioning to switch the displayed image in Javascript

As a beginner in Javascript, I'm attempting to create a basic button in html that switches the originally shown image when clicked. Unfortunately, my current code isn't functioning properly. Could someone please assist me in identifying the mista ...

What about employing the position:fixed property to create a "sticky" footer?

I've come across various methods for creating a sticky footer, such as Ryan Fait's approach found here, another one here, and also here. But why go through the trouble of using those techniques when simply applying #footer{position:fixed; bottom ...

Customize your payment with a PayPal button tailored to your desired price

I've been tasked with creating a dynamic PayPal button that can receive different values based on user choices. The website has so many options that creating separate buttons for each choice doesn't seem feasible. I've tried researching solu ...

Can you tell me the specific location in the CSS where this logo image is defined?

I've been working on a website at http://onofri.org/WP_BootStrap/ and I'm facing an issue. When using FireBug, I can't seem to locate where in the CSS the image logo.png is defined (this is the small image in the upper-left corner of the the ...

How can I implement 'blocked tails' using the :after pseudo-element?

Apologies, I'm uncertain of the right term for these elements. I have a module that reveals another box with information when hovered over. I want them to be visually connected by an angled rectangle or tail to indicate their association. Something a ...

Tips on displaying a successful message and automatically refreshing the page simultaneously

I am working on a JSP Servlet code that utilizes AJAX to handle user data. In the success function of AJAX, I aim to display a success message to the user and clear all fields in the form by reloading the page. Unfortunately, when the page reloads, the a ...

Starting the description text immediately after the title while maintaining equal width for the title can be achieved by carefully

I need some assistance with formatting a title and description in a specific way. The title should be followed by the description starting on the next line while maintaining the same width for the title. It should resemble the image linked below https://i. ...

Embedding a CSS file into a PHP class

I've encountered a little issue that I can't seem to solve on my own. I've put together a "webengine" using multiple classes. The primary class responsible for obtaining a theme's internals is called "Logic". This Logic class contain ...

Issue with PHP incorrectly encoding JSON when writing to a file

I encountered a problem while working on this task. I used preg_split in PHP to create an array. However, my challenge now is converting it into JSON format. Despite trying several methods, the resulting code appears poorly written and does not seem to be ...

Is it feasible to customize the appearance of output text to resemble that of a password input field in Rich Faces?

Within our dataTable, we have a collection of attributes. Included in these are outputtext fields that contain passwords. Typically, password fields display as a series of black bullets if they are input fields (inputSecret). Currently, the outputText fi ...

Using CSS to Showcase Text and Images

Setting up a database for Weapons for Sale and incorporating PHP code: <?php echo '<link rel="stylesheet" href="display.css" type="text/css">'; function FindPhoto($name) { $dir_path = "http://www.chemicalzero.com/FireArms_Bis/Guns ...