What is the best way to align a div with a fixed width in the center, when it is positioned between two other divs within a parent

I have this HTML (technically JSX) code snippet here:

The center div with the class domain-input-parent is supposed to have a fixed width of 400px and stay centered horizontally on the screen.

This arrangement ensures that both the domain-label and icon-container elements will have equal widths.

How can I achieve this such that it works for screens of any width (>400px)?

Below is the complete HTML structure:

  <div className="domain-container">
    <div className="domain-label">
      <p>Domain</p>
    </div>
    <div className="domain-input-parent">
      <input className="domain-input" id="website-url" placeholder="    https://www.yourwebsite.com" onInput={validateDomain} onClick={validateDomain}></input>
      <p id="error-text" className={ (hideErrorText == true) ? "hidden invalid-input" : "invalid-input"}>Please enter a valid domain ex. www.example.com</p>
    </div>
    <div className="icon-container">
      <img className="info-icon" src="images/info_icon.png"></img>
      <span className="tooltip-text">This is the top level website for seo radar to monitor.  We will validate the domain and will fetch the robots.txt file associated with it.  Examples: www.example.com or example.com.</span>
    </div>
  </div>

Please let me know if you need more information.

Answer №1

When using input and img elements, remember they do not have closing tags. Additionally, className is a JavaScript construct that can be utilized for styling. Consider utilizing flexbox for layout.

.domain-container{
display:flex;

}

.y {width:400px}

.x {
width: calc((100% - 400px) / 2);
}

div{border:solid 1px black;}
<div class="domain-container">
  <div class="domain-label x">
    <p>Domaina</p>
  </div>
  <div class="domain-input-parent y">
    <input className="domain-input" id="website-url" placeholder="https://www.yourwebsite.com" onInput={validateDomain} onClick={validateDomain}>
    <p id="error-text" className={(hideErrorText==true) ? "hidden invalid-input" : "invalid-input"}>Please enter a valid domain ex. www.example.com</p>
  </div>
  <div class="icon-container x">
    <img class="info-icon" src="images/info_icon.png">
    <span class="tooltip-text">This is the top level website for SEO radar to monitor. We will validate the domain and fetch the associated robots.txt file. Examples: www.example.com or example.com.</span>
  </div>
</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

The function 'myfunc' was called within a render, however, it is not defined in the instance

I keep seeing this error message Property 'myfunc' was accessed during render but is not defined on instance, and I'm not sure why. Below are my HTML and JavaScript code snippets. const ListRenderingApp = { data() { return { todo ...

Transforming JSON in Node.js based on JSON key

I am having trouble transforming the JSON result below into a filtered format. const result = [ { id: 'e7a51e2a-384c-41ea-960c-bcd00c797629', type: 'Interstitial (320x480)', country: 'ABC', enabled: true, ...

Discover the magic of TransformToggle and slideToggle in Javascript, HTML, and CSS

Working on a website coding project and ran into an issue. Trying to utilize an img as a link to slideToggle content. It's working, but I'd like the img to rotate 90deg on the first click and -90deg on the second one. Any solutions are greatly ap ...

Is your content flickering and constantly re-rendering due to the Next.js router.query?

One issue I'm facing is with a page that relies on router.query to determine the content to display. The problem arises when the page initially renders without any data from router.query, causing a noticeable "flickering" effect once the relevant cod ...

Why is my code executing twice rather than just once?

` import './App.css'; import ArrayState from './components/ArrayState'; import FetchApi from './components/FetchAPI/FetchApi'; import Login from './components/Login'; import Useeffect2 from './components/Use ...

I recently encountered an issue where the Google Chrome Element Inspector (Developer Tools) unexpectedly removed an HTML element from

While using WordPress, I noticed a strange issue on the admin side when utilizing Google Chrome v.32 Element Inspector (Developer Tools) - some of the elements in my HTML seem to disappear. However, when I view the page without the Developer Tools, all the ...

Animating or transitioning CSS keyframes to an inline value when the page is initially loaded

In my current project, I am working on creating HTML and CSS-based bar representations of percentage values. The structure of the code is as follows: Using HTML: <div class="chart"> <div class="bar" style="width:43%"></div> </div&g ...

Utilizing the Autocomplete feature of Material-UI in conjunction with Formik for enhanced form functionality

Attempting to integrate Formik with Material UI's Autocomplete component has been a bit challenging. While other Material-UI components like text fields and selects work smoothly with Formik, implementing Autocomplete is proving to be more difficult. ...

Encountering an issue with React 16.13.1 Hooks: "Error message stating `React.useState is not

I encountered an error message: ERROR TypeError: React.useState is not a function. (In 'React.useState(false)', 'React.useState' is undefined) These are the dependencies I am using: "dependencies": { "react": ...

Creating rounded corners in Firefox can result in a gap between the border and the background

I'm trying to round the corners of a div, but in Firefox there seems to be an issue with whitespace between the border and background color. Check out my demo fiddle. <div>&nbsp;</div> div { margin: 20px; width: 250px; ...

Sharing a photo and showcasing it on a webpage (Node.js, React.js, Express.js)

I am facing an issue with uploading and displaying an image on a website along with its filename caption. Despite researching various tutorials on the same topic, I believe my confusion lies in understanding how to request information from a server and dis ...

Tips on using JQuery to extract form field information from a drop-down menu, display it in a div, and then compare it with the subsequently

In my HTML file, I am using two dropdown lists and JQuery for validation. First, I need to save the selected items from both dropdown lists in a variable and then compare them with the next selection. If the data from both dropdown lists match, an alert m ...

Create a list using ReactJS

I've been working on rendering a dynamic list in JSX, but I'm facing issues displaying the items. Below is my code snippet where I attempted to use useState const [orderList, setOrderList] = useState([]) and setOrderList(prev => [...prev, chil ...

The Challenge with jQuery Nano Scroll

I recently added the jQuery Nano Scroll plugin to my HTML page. However, I am facing an issue where the scrollpane is not visible. When I inspect the div using Chrome, the scrollpane appears. Any suggestions on how to resolve this? Here's a snippet ...

Launching a React application on Godaddy using GitHub deployment

I'm currently working on a react app hosted on GoDaddy. Every time I want to make changes live, I have to manually build the project, delete all previous files in cPanel, and add the new build file. Is there a way to automate this process so that when ...

Utilize HTML5 Application Cache solely for storing and managing dependencies

My goal is to selectively cache certain files like JavaScript, CSS, fonts, and image sprites. Should I create a manifest file for these specific files or rely on the browser's caching mechanism? If using a manifest is preferred, can I still prevent ...

Exploring the functionality of CodePen's code editor in relation to developing a 2D shooting game

Recently, I created a straightforward 2D shooter game with all the code neatly organized in a single HTML file: (file_gist). When I tested the game in my chrome browser, everything worked flawlessly according to my intentions. However, upon transferring th ...

Guidelines on centering an AJAX spinning animation within a parent div

Below is the basic structure of an HTML document for a webpage. <div class="grand-parent"> <div class="header">Heading</div> <div class="parent-div"> <div class="child-div-1"></div> ...

invoking a JavaScript function from an HTML file

I want to create a JavaScript server on Raspbian that not only serves .html content to the browser but also allows for user input through events like button clicks. Both my .html and .js files are located in the same directory, and I have used absolute pat ...

Add a click event listener to the body element using a button click, without causing it to trigger

What is the current situation: A button is clicked by the user The menu opens (list items display = block) The function to close the menu is connected to the <body> The function to close the menu is immediately triggered, causing the menu to close ...