Follow-up from #1986074: Buttons style update.
When restyling the buttons in the Seven theme we added a 'danger' variant that actually looks more like a link:

This required us to override all the default button styling and undo it:
.button--danger {
display: inline;
cursor: pointer;
padding: 0;
border: 0;
border-radius: 0;
box-shadow: none;
background: none;
-webkit-appearance: none;
-moz-appearance: none;
color: #c72100;
font-weight: 400;
text-decoration: underline;
}
The ideal markup here would be to to remove the button classes completely and simply style it as a link, without having to undo the base styling.
Comments
Comment #1
internetdevels commentedPatch attached.
Comment #2
lewisnymanThe tricky part here is that we can't change the original function in form.inc. We have to modify the classes in the theme layer, just in Seven.
Comment #4
internetdevels commentedMoved changes to the Seven theme.
Comment #5
sunNote that #216064: Entity form "Delete" button triggers server-side + HTML5 form validation; change "Delete" button to a link is about to replace all Delete buttons with
That change is both a win and also a conflict for Seven. ;)
You want the a.button--danger part.
You do not want the .button part. :)
If you're overriding the full button CSS anyway already, then you could simply do this though:
Comment #6
yuki77 commentedI'm working on it
Comment #7
sunbtw, I would not recommend to do what the issue title suggests (using link--danger instead of button--danger).
That is, because doing so would require you to write some very sophisticated preprocess (or whatever) code in seven.theme that is guaranteed to replace all buttons of #button_type 'danger' with links. — Contributed modules will use danger buttons in their forms, so you'd have to ensure that every possible instance is replaced accordingly.
I'd recommend to change the issue title + summary; basically to implement #5.
Comment #8
yuki77 commentedComment #9
yuki77 commentedThanks sun, I changed the title!
Comment #10
yuki77 commentedHi,
So I changed the css, added :not on button css so that the reset on the button--danger is minimum. I wasn't sure if there would be any occasion where .button-danger and .button-primary so I also added :not on Button primary, but if there would be no such occasion I will remove it.
Hope it works!
Comment #12
rteijeiro commented@yuki77 it seems that you have to update your codebase and try to apply the patch. It's what we call a Re-roll.
Try: git fetch (to get latest codebase)
And then try to apply your patch changes. It seems that some files has been changed while you were working on this patch.
Let me know if you need more help and thanks for your contribution!
Comment #13
yuki77 commentedHi,
So I created a new one, Hope this one works...! And Please let me know if I can remove :not from .button--primary
Comment #14
Jalandhar commentedChanging status to Needs review to run tests.
Comment #15
lewisnymanThanks for the patch, I reviewed it:
We don't need these extra blank lines here. Also our coding standards request a space between the .button selector and the curly bracket.
We don't need to add the :not() to the .button--primary. They aren't designed to be combined.
Careful with hoe many blank lines you leave between components/variants. We only need one.
Yeah lets delete this. Also make sure you leave a blank line at the end of the file
Comment #16
Jalandhar commentedUpdating patch with changes said in #15. Please review.
Comment #18
Jalandhar commentedAnother try at patch.
Comment #19
lewisnymanIt seems a bit weird to add such a heavy reset here? Especially when one exists already in buttons.css. Do we need all of these? Maybe we only need a few more lines in buttons.css.
Comment #20
lewisnymanComment #21
nesta_ commentedComment #22
nesta_ commentedWith this patch I add the code from the class ".button--danger" to "button.css", witch contains the same property the clases format that it was declarated before.
I've cleaned the "buttons.theme.css" and the other elements with "button" class will not be rendered.
Comment #23
lewisnymanThis is definitely tidier than before, but if we use the :not() selector then we don't have to override the .button styles at all?
Comment #24
Bojhan commented@Lewis Can this go in?
Comment #25
lewisnymanWhy are we adding an element here? Shouldn't this apply to button elements rather then links?
Comment #26
Aleksandar_P commentedI combined all the previous patches and created one which uses :not(.button--danger) because :not selector can accept a simple selector as argument.
No additional reset of .button--danger is needed.
Comment #27
BarisW commentedVisually, it looks good on desktop. It doesn't look good on mobile though (see screenshot), so it needs a bit of work there.
Apart from this, I really get a bit nauseous from using a 'button' class on a link, that looks like a link (not a button). Don't know of a better solution now thought.
Comment #28
BarisW commentedAnd the screenshot.
Comment #30
Aleksandar_P commented'Save' and 'Delete' buttons styled for rwd.
'Save' centered with parent element text alignment set to center.
Padding and margins on buttons changed in order to fit 780px screen and to be centered for mobile devices.
Comment #31
lewisnymanWe've changed the padding here, I don't think we should do that.
Also I noticed here that we've added a :hover selector here that was not there before.
We need to replace the selectors here, not just add to them, otherwise they still apply incorrectly to button--danger
I'm not sure why we are adding margin left here? Margin does not apply to display: inline elements.
We shouldn't need to reset these styles if we implement the styling above correctly
We are modifying the dropbutton component, which seems out of scope of this issue.
Comment #32
lewisnymanComment #33
Aleksandar_P commentedI tried another approach to the issue. Fixed only the overriding of button--danger with button:not(.button--danger).
Comment #35
nesta_ commentedRetest to 8.1.x and add tag for DrupalCampES
Comment #43
sakthivel m commented#33 Patch failed
Comment #44
sakthivel m commented#44 Please review the patch
Comment #45
chetanbharambe commentedVerified and tested patch #44.
Patch applied successfully and looks good to me.
Testing Steps:
# Goto: Any content
# Edit the content
# Check the delete button
# Inspect it and check the CSS classes
Expected Results:
# Remove the button classes completely.
Looks good to me.
Can be a move to RTBC.
Comment #47
vsujeetkumar commentedRe-test on #44 and its pass, Move to NR.
Comment #48
yogeshmpawarRemoving Needs reroll tag as it is no longer needed.
Comment #52
longwaveThe Seven theme has been removed from Drupal 10 core. I confirmed that this issue only affects Seven and no other themes included with Drupal core, so I am moving this to the contributed Seven project.
Comment #53
gaurav-mathur commentedComment #54
gaurav-mathur commentedI applied patch #44 With this patch i add the code from the class like ".button--danger" witch contains the same property the clases format that it was declarated before. its work fine.
Comment #55
gaurav-mathur commentedComment #56
roshni27 commentedDrupal Version :10.1.2
PHP Version 8.1.16
Seven Theme : 1.0.0-alpha1
No patch applied.
I have shared a screenshot in which the 'delete' button style appeared correct.
Comment #57
avpadernoComment #58
avpadernoThe existing patches are for Drupal core.
Comment #59
sandip commentedI am working on it.
Comment #61
avpadernoComment #62
avpadernoI apologize: I did not refresh the page, and I did not see the new comments.
Comment #63
sandip commentedI checked the MR and it resolved the issue and we dont need to reset css provide by
.buttonclass in.button--dangerclass. So moving this issue to RTBC.Comment #64
avpadernoComment #67
avpadernoThank you for the patches!
Comment #69
stefan.kornThis is not really playing nice, because
.button:not(.button--danger)has a high CSS specifity and can therefore easily interfere with other styles.
I encountered this already in two places. One even interfering with
from
https://git.drupalcode.org/project/drupal/-/blob/875f19af4634a6b6618fe1a...