This is very simple but it just came up on me; and, I can't believe there is nothing I can do about text-decoration inheritance.
I understand that if there is a <div> everything in there has to be underlined. But for a nested <div> with a separate class or id to take on the inheritance even if (none) is selected?!? I don't buy it. This happens with text-style as well, but not color.
#hello {
font-weight: bold;
}
#me {
text-decoration: underline;
color: #cc33cc;
}
.home {
text-decoration: none !important;
color: black;
}
<p id="hello">hello</p>
<div id="me">me
<div class="home">go</div>
</div>
You can position .home absolutely to prevent the text decoration from applying:
#hello {
font-weight: bold;
}
#me {
text-decoration: underline;
color: #cc33cc;
}
.home {
position: absolute;
color: black;
}
<p id="hello">hello</p>
<div id="me">me
<div class="home">go</div>
</div>
From the CSS2.1 spec:
Note that text decorations are not propagated to floating and absolutely positioned descendants, nor to the contents of atomic inline-level descendants such as inline blocks and inline tables.
You can also float it or display it as an inline-block, but doing so will place the element next to the text in the parent element rather than below it as with a block-level element. Absolutely positioning (without offsetting) will not move the element.
Since absolutely positioning an element takes it out of the flow (which is why it prevents parent text decorations from applying), this means if there are any other in-flow elements after .home that need to be aware of its position, you will need to style those accordingly. For example, the next element needs to have a top margin that is equal to its height, or something along those lines.
Just replace your styles with below CSS Code.
.home {
color: black;
display: inline-block;
}
You should try to add Combinators in css
#home {
text-decoration: underline;
color: #cc33cc;
float:Right;
}
.noDecoration, #home ~ p {
text-decoration: none;
color: black;
}
You have to write your hmtl something like this
<div id="home">
<p>Home-1</p>
</div>
<div id="home .noDecoration">
<p>Home-2</p>
</div>
I hope this will solve your problem
You can use > * select all the elements inside #me,
#me > * {
text-decoration: underline;
color: #cc33cc;
}
Related
This question already has answers here:
How do I not underline an element in a link?
(2 answers)
Closed 9 days ago.
It probably is a specificity priority order that I dont get.
Here is the html code:
<div class="side-panel__item side-panel__item-active">
<p>Client Statistics</p>
<div class="side-panel__sub-container">
<p class="test">Option 1</p>
<p class="test">Option 2</p>
</div>
</div>
And the css code:
.side-panel__item-active {
color: orange;
text-decoration: underline;
}
.test {
color: #444;
text-decoration: none;
}
Expected behavior was that the text-decoration in .test would override the text:decoration inherited from .side-panel__item-active.
But it doesnt.
The color on the other hand is changing fine.
I want to understand what is happening here. I would assume specificity order and the parent div having 2 classes but then again, why one declaration works ( color: #444 ) and the other doesnt?
.test overrides the color but not the text-decoration.
What am I missing?
To be honest this had me scratching my head. but Try this css
side-panel__item-active p{
color: orange;
text-decoration: underline;
}
.test {
color: #444;
text-decoration: none;
}
It can work, provided:
that text decorations are not propagated to any out-of-flow descendants, nor to the contents of atomic inline-level descendants such as inline blocks and inline tables. They are also not propagated to inline children of inline boxes, although the decoration is applied to such boxes.
(W3 Consortium note on the subject, 2. Line Decoration: Underline, Overline, and Strike-Through, First note in green).
.side-panel__item-active {
color: orange;
text-decoration: underline;
}
.test {
display: inline-block; /* [MANDATORY] */
color: #444;
text-decoration-color: none;
}
<div class="side-panel__item side-panel__item-active">
<p>Client Statistics</p>
<div class="side-panel__sub-container">
<p class="test">Option 1</p><br>
<p class="test">Option 2</p>
</div>
</div>
I have the following CSS and HTML: http://jsfiddle.net/47w0h73r/6/
.one {
padding: 20px;
background: #f00;
}
.two {
padding: 20px;
background: #00f;
}
a,
button {
font-family: Arial, Helvetica;
font-size: 16px;
padding: 10px;
background: #fff;
color: #000;
display: inline;
border: 0;
text-decoration: none;
}
<div class="one"></div>
<div class="two">
Link
<button>Button</button>
</div>
As you will notice, the button doesn't appear as inline. Why is this? How can I make this button inline, just like its sibling a?
Issue
By changing the button to an a you will notice that the display: inline makes the padding of the parent element to ignore the padding of both child elements, making them really display inline. The problem, is that the button tag doesn't really appear inline, which makes the parent element's padding push both elements down. How can I fix this?
Trying to set a button to display:inline seems to cause some confusion. The inability to get display:inline behaviour is often attributed to it being a replaced element, but that is incorrect. <button> is not a replaced element.
In fact, the HTML5 specification, Section 10.5.2 The button element makes this requirement:
When the button binding applies to a button element, the element is
expected to render as an 'inline-block' box rendered as a button whose
contents are the contents of the element.
The language is a little unusual, but the button binding does apply, and the effect is that the binding takes precedence over the specified value of the display property. The effect is that the button is always rendered as display:inline-block, no matter what its specified value is. There is nothing you can do about it.
Add line-height:17px; to a, button and that should make them the same:
.one {
padding: 20px;
background: #f00;
}
.two {
padding: 20px;
background: #00f;
}
a,
button {
font-family: Arial, Helvetica;
font-size: 16px;
padding: 10px;
background: #fff;
color: #000;
display: inline;
border: 0;
text-decoration: none;
line-height: 17px;
}
<div class="one"></div>
<div class="two">
Link
<button>Button</button>
</div>
fiddle
HTML
<ul>
<li>Messages<span>1</span></li>
</ul>
CSS
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:hover span {
text-decoration: none;
}
span {
background-color: red;
border-radius: 999px;
color: white;
margin-left: 2px;
position: relative;
top: -.5em;
font-size: .75em;
font-weight: bold;
padding: 0 .3em;
}
When you mouse-over the link the underline is applied to the <span> even though I've set text-decoration: none. Is there a way to get rid of it?
Try changing the display of <span> to inline-block as follows:
Example Here
span {
background-color: red;
border-radius: 999px;
color: white;
margin-left: 2px;
position: relative;
top: -.5em;
font-size: .75em;
font-weight: bold;
padding: 0 .3em;
display: inline-block; /* <-- Added declaration */
}
Explanation
According to CSS level 2 specification, text-decoration is not propagated to the contents of nested atomic inline-level elements - such as inline-blocks and inline-tables.
16.3.1 Underlining, overlining, striking, and blinking: the 'text-decoration' property
[...] Note that text decorations are not propagated to floating and
absolutely positioned descendants, nor to the contents of atomic
inline-level descendants such as inline blocks and inline tables.
Also the spec states (my emphasis):
Underlines, overlines, and line-throughs are applied only to text
(including white space, letter spacing, and word spacing): margins,
borders, and padding are skipped. User agents must not render these
text decorations on content that is not text. For example, images and
inline blocks must not be underlined.
Also note that text decorations would stick with the text itself, therefore:
Relatively positioning a descendant moves all text decorations affecting it along with the descendant's text; it does not affect calculation of the decoration's initial position on that line.
add this
ul li a span { text-decoration:none; display: inline-block; }
I am trying to change the css property of first line of a big sentence, I am experimenting with it by using color property, I have an html element
<span class="tripname_heaing">Where Hummus All Began: Jasdasdasddasdasdasdasdadasdasdasdasdsadsadasdasdordan & Issdassasdsadsadsadrael</span>
and CSS property
.span.tripname_heaing:first-line {
color: red
}
span.tripname_heaing{
color: blue
}
span.tripname_heaing {
font-size: 24pt;
font-weight: normal;
line-height: 24pt;
margin: 0;
padding: 0;
}
But the psuedo element property is not working with the above syntax. I am adding a fiddle to show the demo. What could be wrong with this?
http://jsfiddle.net/X33pY/126/
And edit made to fiddle to show the feature
http://jsfiddle.net/X33pY/126/
The ::first-line pseudo element doesn't apply to inline-level elements; from Selectors Level 3:
In CSS, the ::first-line pseudo-element can only have an effect when
attached to a block-like container such as a block box, inline-block,
table-caption, or table-cell.
You can instead use a <p> or change the display value of the <span> - http://jsfiddle.net/X33pY/127/
You had a lot of problems like color: red, it should be color: red;
You also had to add display: block; to the main container since it is a span tag, these are not block elements.
.tripnameHeaing {
font-size: 24pt;
font-weight: normal;
line-height: 24pt;
margin: 0;
padding: 0;
color: blue;
display: block;
}
.tripnameHeaing:first-line {
color: red;
}
jsfiddle with answer
I have a button class working like this :
<p class="button">Rejoindre</p>
The CSS is :
p.button
{
background-color: #e74c3c;
line-height: 30px;
width: 200px;
text-align: center;
}
.button a
{
font-family: Montserrat, sans-serif;
color: white;
font-size: 0.9em;
text-transform: uppercase;
}
.button a:hover
{
text-decoration: none;
}
How can I make the entire button (represented by the paragraph tag) a link instead of just the text ?
You can put the link tag on the outside to make anything inside it be contained in the link:
<p class="button">Rejoindre</p>
However, you probably want to use something other than a p tag for your button, maybe a button element instead?
More info on HTML buttons.
Add display: block to the .button a ruleset.
http://jsfiddle.net/ExplosionPIlls/UvrKx/
You can add display:block; to you anchor tag.
display: block means that the element is displayed as a block, as
paragraphs and headers have always been. A block has some whitespace
above and below it and tolerates no HTML elements next to it, except
when ordered otherwise (by adding a float declaration to another
element, for instance).
Fiddle: http://jsfiddle.net/akx3p/
CSS:
p.button
{
background-color: #e74c3c;
line-height: 30px;
width: 200px;
text-align: center;
}
.button a
{
font-family: Montserrat, sans-serif;
color: white;
font-size: 0.9em;
text-transform: uppercase;
display: block;
}
.button a:hover
{
text-decoration: none;}
<p> are block elements, meaning that they naturally are at 100% width. If you just added display: block; to the anchor tag, you can make it behave the same way. Here's a fiddle
. That way allows you to get rid of the p tag all together.