Problem

The text in legends contained within fieldsets has an overflow issue when the line wraps. The current CSS anticipates a single line of text, but this is not always the case.

legend overflow

The css that causes the issue is in form.css, specifically the position:absolute; rule:

fieldset:not(.fieldgroup) > legend {
font-size: 1em;
font-weight: bold;
letter-spacing: 0.08em;
position: absolute;
text-transform: uppercase;
top: 10px;
}

Proposed Solution

Remove the absolute position, and adjust the styles to flow within the fieldset.

fieldset:not(.fieldgroup) {
  background-color: #fcfcfa;
  border-radius: 2px;
  margin: 1em 0;
  padding: 18px; /* was 30px 18px 18px */
  min-width: 0;
  position: relative;
}

fieldset:not(.fieldgroup) > legend {
  font-size: 1em;
  font-weight: bold;
  letter-spacing: 0.08em;
  position: relative; /* was absolute */
  text-transform: uppercase;
  /* top: 10px; */
  /* additional styles */
  float: left; /* to override default browser styles */
  width: 100%; /* to prevent actual float behaviour */
  padding-bottom: 1em;
}

legend overflow corrected

Issue fork seven-3028704

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

occupant created an issue. See original summary.

occupant’s picture

StatusFileSize
new778 bytes

Adding patch

joelpittet’s picture

Status: Active » Needs review

Setting as NR

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

This works great!

I checked it with webform too and with RTL because of the width: 100% it works with that too.

lauriii’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/themes/seven/css/components/form.css
@@ -25,12 +25,14 @@ fieldset:not(.fieldgroup) {
+  padding-bottom: 1em;

I'm wondering if we actually need this change? This seems to make a minor change to the design even for single line legend.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

sulfikar_s’s picture

StatusFileSize
new665 bytes

I've rerolled the patch. Please review

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bhumikavarshney’s picture

Version: 9.3.x-dev » 10.0.x-dev
StatusFileSize
new58.19 KB
new54.31 KB

Hi @sulfikar_s,
The above patch works fine for me.
Thanks
RTBC+1

longwave’s picture

Project: Drupal core » Seven
Version: 10.0.x-dev » 1.0.0-alpha1
Component: Seven theme » Code

Following #3304285: Remove Seven from core I confirmed that this CSS is only present in Seven and no other core themes, so moving this to the contributed Seven project.

avpaderno’s picture

Version: 1.0.0-alpha1 » 1.0.x-dev
Status: Needs review » Needs work
Issue tags: +Needs merge request

immaculatexavier made their first commit to this issue’s fork.

immaculatexavier’s picture

Status: Needs work » Needs review
avpaderno’s picture

Status: Needs review » Reviewed & tested by the community

I checked on the live preview: The merge request fixes the reported issue.

  • avpaderno committed 6daefbe1 on 2.0.x
    Issue #3028704: Legend text overflows on small viewports
    
avpaderno’s picture

Status: Reviewed & tested by the community » Fixed

Thank you! The changes have been applied to both the branches.

avpaderno’s picture

Issue tags: -Needs merge request

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

joevagyok’s picture

StatusFileSize
new354.23 KB

This issue introduced a regression on vertical tabs form when element is in place over the fieldsets over 2.0.x.

screenshot

avpaderno’s picture

Version: 1.0.x-dev » 2.0.x-dev
Status: Closed (fixed) » Active
avpaderno’s picture

Does it happen for other fieldsets?

joevagyok’s picture

Yes, wherever we use the same combination it's broken, only tested on 2.0.x. We did a temp fix on our side as such:

fieldset.js-form-wrapper div.fieldset-wrapper:has(> fieldset) {
  float: left;
}
avpaderno’s picture

May you verify if it happens also with the 2.0.x-dev development version? After #3546625: Remove the prefix added to the details class in the details.html.twig file, some of the pages are rendered differently.

Which module adds the Navigation block vertical tab?

avpaderno’s picture

Status: Active » Postponed (maintainer needs more info)
joevagyok’s picture

The <legend>Behaviour as parent</legend> inside the Navigation block is coming from our own module. It's an optional element for the fieldset, and a combination that is being used elsewhere as well. Presence of a <legend> should not cause this issue. In 1.x this was working perfectly, before this change was introduced. I can confirm the issue is present in both 2.0.x and 1.0.x branches.

avpaderno’s picture

Status: Postponed (maintainer needs more info) » Needs work
avpaderno’s picture

On the merge request !221, I reverted the changes done in this issue.

avpaderno changed the visibility of the branch 3028704-legend-text-overflow to hidden.

avpaderno’s picture

Issue summary: View changes

I am no longer sure that what reported here is an issue that can practically occur in any Drupal core or contributed modules' page.
The legend text used inside field-sets is supposedly a short text of three-four words (Available menus, Preview before submitting, Toolbar configuration). In some rare cases, the legend can be a full sentence (Who can register accounts?) or contain more than four words ( When cancelling a user account, Time zone for new users).

I agree, we need to consider that the translation of those strings can be longer than the English text, but the changes in CSS styles must be not so disruptive to cause what shown in the screenshot in #24.

@joevagyok May you show the full markup? It would help to see the full content of the <fieldset> shown in the screenshot.

avpaderno’s picture

The issue fork merged in this issue changes the styles for fieldsets whose class is not fieldgroup. The fieldsets used in vertical tabs in /admin/structure/types/manage/article have that class, like the Preview before submitting fieldset.

<fieldset data-drupal-selector="edit-preview-mode" id="edit-preview-mode--wrapper" class="fieldgroup form-composite js-form-item form-item js-form-wrapper form-wrapper">
      <legend>
    <span class="fieldset-legend">Preview before submitting</span>
  </legend>
  <div class="fieldset-wrapper">
<div id="edit-preview-mode" class="form-radios">
<div class="js-form-item form-item js-form-type-radio form-type-radio js-form-item-preview-mode form-item-preview-mode">
<input data-drupal-selector="edit-preview-mode-0" type="radio" id="edit-preview-mode-0" name="preview_mode" value="0" class="form-radio">
<label for="edit-preview-mode-0" class="option">Disabled</label>
      </div>
<div class="js-form-item form-item js-form-type-radio form-type-radio js-form-item-preview-mode form-item-preview-mode">
<input data-drupal-selector="edit-preview-mode-1" type="radio" id="edit-preview-mode-1" name="preview_mode" value="1" checked="checked" class="form-radio">
<label for="edit-preview-mode-1" class="option">Optional</label>
      </div>
<div class="js-form-item form-item js-form-type-radio form-type-radio js-form-item-preview-mode form-item-preview-mode">
<input data-drupal-selector="edit-preview-mode-2" type="radio" id="edit-preview-mode-2" name="preview_mode" value="2" class="form-radio">
<label for="edit-preview-mode-2" class="option">Required</label>
      </div>
</div>
          </div>
</fieldset>
avpaderno’s picture

Status: Needs work » Needs review

I changed the fieldset styles to avoid using position: relative and position: absolute.

kmitch’s picture

Hi,

Thanks for everybody's work on this issue! I ran across this issue when I installed v2.0.0-beta2 (preparing for Drupal 11), and wanted to note that the June 2025 commits on this issue (MR!99) ended up getting into the v2.0.0-beta2 branch/tag, resulting in the regressions noted by @joevagyok . Unfortunately, the later commits on this issue (MR!221) do not appear in v2.0.0-beta2, so we've had to apply MR!221 as a patch in composer to resolve the regression.

One issue we noticed with MR!221, at least with the most recent commit (8523a326) that removes the positioning rules altgother, is that the legends for fieldsets now appear differently than they did prior to all of the adjustments: the legends now appear along the fieldset's top border rather than just below the top border. I have attached two screenshots showing before and after views (before uses only MR!221 commit a34616df, while after uses the latest version of MR!221).

Given that all of the changes from this issue appear to be moot (re comment #35 above), I would probably vote for keeping the fieldset legends the way they were (as in sticking with MR!221 commit a34616df). But I will defer to you all if that seems like the best course of action.

Either way, thanks for everyone's work on this!

-- Ken

  • avpaderno committed af714023 on 2.0.x
    Revert "Issue #3028704: Legend text overflows on small viewports"
    

  • avpaderno committed b3b77ead on 1.1.x
    Revert "Issue #3028704: Legend text overflows on small viewports"
    
avpaderno’s picture

Status: Needs review » Fixed

The merge request !221 was a test to see what happened when removing the position style. Some of those styles are for preventing regression due to fieldset styling that was removed in normalize.css; any change in those styles could cause regression, so they should be carefully checked.

I reverted the changes done in this issue. Thanks everybody!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.