Legend alignment issue in Firefox disrupting Flexbox functionality

My fieldset has a legend containing text and a button. I am attempting to use flexbox to right-align the button within the legend. This setup works correctly in Chrome, but encounters issues in Firefox.

I have managed to replicate the problem with a simplified code snippet:

main {
  width: 100%;
}

fieldset legend {
  display: flex;
  justify-content: space-between;
  width: 100%;
}
<main>
  <fieldset>
    <legend>
      Legend text
       <button type="button">
        Button text
      </button>
    </legend>
   </fieldset>
</main>

In Chrome, both elements inside the legend are displayed on the same line as intended:
https://i.stack.imgur.com/Gm03K.png

However, when viewing the page in Firefox, the layout is not displaying as expected. Here is how it looks: https://i.stack.imgur.com/dh3Su.png

Answer №1

Simply enclose the content you want to style in a div container and then apply the flex properties accordingly.

main {
  width: 100%;
}

 span {
  display: flex;
  justify-content: space-between;
  width: 100vw;
}
<main>
  <fieldset>
    <legend>
    <span>
      Legend text
       <button type="button">
        Button text
      </button>
      </span>
    </legend>
   </fieldset>
</main>

Answer №2

It has been noted that Flexbox does not work well with fieldset elements. An alternative solution is to use float property:

fieldset legend {
  width: 100%;
}

fieldset legend button {
  float: right;
}
<fieldset>
  <legend>
    Legend text
    <button type="button">
            Button text
          </button>
  </legend>

</fieldset>

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

Putting Images Next to Each Other - Arranging Them to Be Responsive

I have a pair of images on my webpage that I've aligned next to each other. To enhance the mobile user experience, I want these two images to stack on top of each other when viewed on smaller screens. If anyone can provide guidance on creating respon ...

storing the input values in a cache

When a user enters a query into the search form and submits it, they are taken to a results page displaying the search results. If the user then clicks on the browser's back button, I want them to be directed back to the search form with their previou ...

Display overlay objects specifically focused around the mouse cursor, regardless of its position on the screen

I am currently working on a project using SVG files and processing.js to develop a unique homepage that incorporates both animation and static elements. The concept is to maintain the overall structure of the original homepage but with varying colors, esse ...

Div displaying with extra space below

UPDATE check out the new jsfiddle link here that effectively showcases the problem I am encountering an issue with white space appearing below my div. This can be seen in 2 photos, one of which is scrolled down: https://i.sstatic.net/yHlXL.png https:// ...

Controlling the scroll behavior of div elements with the CSS overflow-y property

This is the current setup I have: <div> <div> </div> <div> </div> <div> </div> </div> The inner divs are styled with this CSS: float: left; margin-right: 40px; width: 100px; While ...

Middleware that handles form post requests quickly became overwhelmed and resulted in a RangeError

Currently, I am working with a form using ejs templates to collect data. When accessing the "/" route, my application renders the "main" view and utilizes a middleware to handle the form data. However, I encountered an error stating "RangeError: Maximum ca ...

No data retrieved from database using PDO, Empty Table

I am struggling to integrate MySQL database information into HTML. Despite researching extensively on this forum for solutions, I have not been successful. The code below aims to retrieve data such as courseNumber, section, instructor, startTime, endTime ...

Issue with Next.js: Setting the width to 100vh prevents the height from being responsive on mobile devices

While I understand that using height: 100vh on mobile is generally discouraged for various reasons, I'm curious as to why height: 100vh paired with width: 100vh in Next.js doesn't produce the expected result. Instead of a full-height square, I en ...

Having trouble making an HTML5 video work on Android? It seems to play fine when clicking the play button,

It has come to my attention that html5 video on Android devices is unable to autoplay. Currently, the video only plays on the device when the user manually clicks on the play button. <video width="640px" height="360px" src="media/video/Moments_of_Every ...

Is the original image source revealed when clicked?

I've implemented an expand and collapse feature using jQuery/JavaScript. Clicking on the DIV causes the image inside to change state. However, clicking on the same DIV again doesn't return the image to its original state; it remains stuck in the ...

Show the modal content in Bootstrap on mobile and tablet screens

I have exhaustively searched the web for a solution to my issue, but unfortunately, I have come up empty-handed. I am hoping that you can offer some guidance in this matter. I am currently utilizing modals to showcase details on my website. However, when ...

What is the best method to display and conceal a table row in Angular 6?

In the midst of developing a table with multiple rows, I am seeking a way to invisibilize a particular row and then reveal it again using a reset button. Any tips on how to accomplish this task?emphasis added ...

What steps can be followed to incorporate a loading gif into this popup and subsequently eliminate it?

These simple inquiries are starting to get on my nerves. I can't keep waiting around for my website designer to resolve this issue. It shouldn't be that difficult... I managed to figure out most of it by researching similar questions, but I could ...

Changing the screen size of a panel using asp.net and c#

When my screen size reaches 480px, I want to remove one menu and replace it with another. The solution I'm considering is creating two panels. In this setup, I would set menu1 to false when the screen size is less than 480px and menu2 to true. Conve ...

Adding hue to the portion of text following a JavaScript split() operation

I need assistance in printing the text entered in a textarea with different colors. I am separating the string using the split() method, which works fine. However, I now want to print the substrings in the textarea with colors. How can this be achieved? & ...

Incorrect font display occurring exclusively on Windows Chrome

There seems to be an issue with the Google served Open Sans font on my website, specifically with Win Chrome where the font appears thick and ugly. However, when I tested it on Win FF and Safari, everything seemed fine. The font also displays correctly on ...

Continue to run upon clicking the button in the Document Object Model

I want the code to constantly change instead of executing only once. By default, the button has a dark mode for text and the background color is pink. When you click the button, the background color changes to black and the text in the button turns into li ...

What is the best way to animate CSS elements using jQuery to slide in from the right, left, or bottom?

When the page is scrolled on my website, I want table_area-left to move from left to right to its current position, table_area-right to move from right to left to its current position, and morph button to move from down to up. I am struggling to find the j ...

What are alternative ways to divide CSS without relying on CSS-in-JS and CSS modules?

Recently, I transitioned to next.js and I'm eager to develop an application with CSS styles without resorting to css-in-js or inline styling. In my exploration, I've come across two potential options: using CSS modules or importing global styles ...

Line breaks showing up on the page that are not present in the HTML source code

Why are unwanted line breaks appearing in my rendered DOM that are not in the source code, causing the content to be displaced? And how can I resolve this issue? Below is the code snippet: <div class="float-left" style="position:relative;left:15px"> ...