What is the reason that the text-decoration of "none" does not seem to function properly within

I need help with my HTML and CSS code. Despite trying to prevent the exclamation mark from being underlined, it still is. Can someone spot what I'm doing incorrectly?

p {
  color:red; 
  text-decoration: 
    underline; 
  font-size: 1.2em;
}

span.none {
  text-decoration: none;
}
<p class="p">Click the thumb<span class="none">!</span></p>

Answer №1

Why doesn't the CSS property text-decoration: none work within a paragraph?

In summary; Text decorations that are applied to parent elements cannot be removed from descendant elements, unless in specific cases where they are not inherited.

This scenario is explained in detail on MDN: (emphasis added)

Text decorations extend across child elements, meaning it's impossible to disable a text decoration set by an ancestor element on its children.

For instance, consider this code:

<p>This text has <em>some emphasized words</em> in it.</p>
,

If the style rule is

p { text-decoration: underline; }
, the entire paragraph will be underlined. The subsequent rule em { text-decoration: none; } won't have any effect; the entire paragraph remains underlined.

However, there are exceptions where text decorations do not pass down to child elements - refer to the W3C specification on the 'text-decoration' property for more details

Note that text decorations do not cascade to floating and absolutely positioned descendants or to the contents of atomic inline-level descendants like inline blocks and inline tables.

Hence, if the span element has

1) display: inline-block, or

2) is floated or

3) is absolutely positioned then

the text decorations don't propagate to it initially. (this also implies that text-decoration: none; isn't needed)

p {
  color:red; 
  text-decoration: 
    underline; 
  font-size: 1.2em;
}

span.none {
  display: inline-block;
}
<p class="p">Click the thumb<span class="none">!</span></p>

Answer №2

To make the text in span.none appear inline, add display:inline-block;

p {
  color:blue; 
  text-decoration: 
    none; 
  font-size: 1em;
}

span.none {
  text-decoration: underline;
  display:inline-block;
}
<p class="paragraph">Click on the button<span class="none">!</span></p>

Answer №3

An easy fix, though not the most elegant one. It gets the job done, but I'm hopeful someone else will come up with a better solution.

p {
   color:red; 
   text-decoration: underline; 
   font-size: 1.2em;
}
p { 
   display: inline 
}
p.none {
   text-decoration: none;
}
<p class="p">Click the thumb</p><p class="none">!</p>

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

Steps to retrieve the final page number from ngx-pagination with Angular

Is there a way to utilize Custom templates within ngx-pagination in order to ensure that the first and last buttons function properly when clicked? Currently, I have utilized pagination-template to accomplish this... How can I dynamically determine the la ...

What is the best way to conceal all lists except for the one that has been chosen?

Looking to enhance my sortable list with jQuery UI - currently it's functional, but I'd like to incorporate a dropdown menu for each item to designate the active one when clicked. Is there a way to modify the code so that upon selection, only th ...

What is the best way to animate specific table data within a table row using ng-animate?

Are you working with Angular's ng-repeat to display a table with multiple rows? Do you wish to add an animation effect to specific cells when a user hovers over a row in the table? In the scenario outlined below, the goal is to have only certain cell ...

The div block containing the table is experiencing horizontal overlap as additional elements are inserted

When creating a table within the div section of the code, I am incorporating text using the DRAG and DROP feature with appropriate styling. The table adjusts in size when I resize my window, indicating that it is functioning correctly. However, as the num ...

Guide to customizing a Modal for editing fullcalendar event names instead of relying on the standard javascript prompt

I am facing a challenge with my fullcalendar which involves inserting data into a database table on drag and drop event. The calendar allows me to edit the event name by clicking on it, prompting a dialog box for input, and then saving the new event name t ...

Sending Emails Using Javascript & CSS via SMTP in a Contact Form

Currently fine-tuning a contact form and nearing completion. However, there seems to be a minor error preventing the form from submitting correctly. Expected behavior includes a pop-up confirmation box upon submission and successful message delivery. Yet, ...

JQuery button refusing to trigger点击

I've searched high and low on various coding forums but still can't find a solution. My HTML code is as follows: <input type="button" value="Sign Up Here" id="buttonClick"> and I have a script at the top that looks like this: < ...

Tips for utilizing a slider as a transformation tool over an image for seamless replacement with alternative images

I'm looking to create an image "slider" that reveals the image underneath when the user grabs the handle and drags it. Check out this example: http://jsfiddle.net/M8ydk/1/ In the provided example, the user can grab the handle and move it on the slid ...

Does CSS in the current IE9 beta allow for text shadows to be implemented?

Text shadows look great in Firefox and Chrome. For example, I have a basic website for streaming videos. Unfortunately, there are no shadows in IE9 for me. This is my CSS code: p { color: #000; text-shadow: 0px 1px 1px #fff; padding-bottom: 1em; } ...

Guide on creating a live connection between a slider and a canvas

Currently, I am working on implementing a slider that can dynamically adjust a specific value in the canvas, such as the radius of a circle. Although my code works as intended, I would like the canvas to update in real-time as I move the slider instead of ...

Guide on how to organize a list into three columns using a single ul tag

Is there a way to split a ul list into 3 columns using CSS? This is how my HTML structure looks like: <ul> <li>Test</li> <li>Test</li> <li>Test</li> <li>Test</li> <li> ...

What steps can be taken to implement a code generation feature on our website?

I need to provide the HTML code of my order form to third parties. After they register and pay, they should be able to copy and paste the HTML code from my site onto their own site. The date will then be saved on my site with a reference to the reseller. ...

IE and Chrome are experiencing issues where the radio buttons are disappearing

Here is the style sheet code: select,input ,td a {border:1px solid green; width:25%;height:25px;font-size:20px;margin- left:.1em;} input.myradio {border:none;width:0%;height:0%;font-size:0%;} And here is the corresponding HTML code: <td><inpu ...

Implement a toggle feature for login and registration with jQuery

I am facing an issue with the show/hide model on my website. When I click the link associated with it, nothing happens. I want it to function in a way that when I click "Sign up," the register form is displayed and when I click "Login," the register form ...

Adding a custom class to a select2 dropdown: How can it be done?

I have customized select2 using CSS with its general classes and IDs. Currently, I am attempting to customize a specific class that will be assigned to select2 and then applied in the CSS. The problem lies not within the select itself, but within its dro ...

Receiving Incorrect Input Value for Input Type 'Month'

Currently, I am attempting to retrieve the value of a two-digit month and a two-digit year from an input type called "month." ISSUE The format seems correct, but the incorrect date is being returned. SOURCE CODE: $("#cardExpireDate").change(function ...

Navigating through a modal without affecting the main page's scroll position

My webpage has some content, and I also have a modal that pops up on top of it. The problem I'm facing is that when I try to scroll the contents within the modal, only the contents behind it scroll instead. Below is the CSS code: html, body { b ...

Incorporate static files with dynamic paths using Django Jinja includes

I'm trying to achieve something like this: {% load static %} {% include {% static path %} %} Since I have numerous files and the path variable is included in the context, which corresponds to the static directory, simply using {% include path %} won& ...

React's reset button fails to clear user inputs

Within my App, I have a straightforward form. I recently discovered that using a button with the attribute type="reset" should clear all input fields, but for some reason it's not working properly in React. Is there something crucial I am ov ...

The Chip Component in MUI dynamically alters its background color when it is selected

Currently, I am working on a project in React where I am utilizing the MUI's Chip component. My goal is to customize this component so that it changes its background color when selected, instead of sticking to the default generic color. https://i.sta ...