This question already has answers here:
Hide text in html which does not have any html tags [duplicate]
(3 answers)
Closed 3 months ago.
I'm looking how to hide a text ("Tag") into a span like this :
<span class="tagged_as">
Tag :
Enfant,
Jeu primé
</span>
I tried to remove the text but I don't want to change something that a don't make...
With css, i tried different things like font-size 0 but font of the href is also changed...
visibility hidden... not working...
I don't know how to select only the text and not the "a" part.
Found another way to do it tinkering with transforms. You can push the parent out of the viewport using translateX(-100vw) on the span and translateX(100vw) on a. Kind of a weird way, but you will not ever see it, provided the website scrolls vertically.
Changing the font-size to 0 and adding it back to a is more reliable (and elegant), but this solution might be helpful, if you don't know the texts font-size or if it is variable.
span {
transform: translateX(-100vw);
display: block;
}
span a {
transform: translateX(100vw);
display: block;
}
<span class="tagged_as">
Tag :
Enfant,
Jeu primé
</span>
Related
This question already has answers here:
How to apply CSS to the first letter after :before content?
(4 answers)
Closed 4 months ago.
Given this markup
<span class="something">world</span>
and this CSS
.something::before {
content: 'hello';
}
I want to add CSS to capitalise the first letter that isn't in the before psudo element.
i.e. the w from world.
Initially I (somewhat naively) thought that the following would work:
.something::first-letter {
text-transform: uppercase;
}
But it actually capitalised the first letter of the before psudo element, and only that.
I also tried to apply :not but this isn't valid on psudo elements.
Is it possible to use CSS to capitalise the first-letter that isn't part of the before psudo element?
Usually you would do this with the :first-letter pseudo element, but you are using :before.
This inserts text before the actual content of your paragraph, rather than the first letter of the actual content, :first-letter would match the first letter of the :before content instead.
That means that instead of this:
<p class="normal">
<p:before>Former - </p:before>
<p.normal:first-letter>F</p.normal:first-letter>irst character of this paragraph will be normal and will have font size 40px;
</p>
You actually get this:
<p class="normal">
<p:before>
<p.normal:first-letter>F</p.normal:first-letter>ormer -
</p:before>
First character of this paragraph will be normal and will have font size 40px;
</p>
Due to how CSS generated content works, I don't think there's a solution in pure CSS to reach the first letter of the actual content once you have inserted content before it.
As an alternative, you could use a span in place of the :first-letter pseudo-element, to which you can then apply the blue color, but that means you have to insert extra elements:
<p class="normal"><span>F</span>irst character of this paragraph will be normal and will have font size 40px;</p>
p.normal {
font-size: 40px;
color: blue;
}
This question already has answers here:
Best replacement for font tag in html
(4 answers)
Closed 4 years ago.
font tag is deprecated in HTML5. Let's say I have a paragraph in which I need to have some words in specific colors. While I can still use the deprecated font tag to achieve that, what would be a good and clean CSS solution to that?
You can use span
span.blue {
color: blue;
}
span.red {
color: red;
}
<p>
Here is some text - <span class="blue">this text is </span><span class="red">another color but in the same </span>paragraph
</p>
Working fiddle
This question already has answers here:
How do I select an element that has a certain class?
(5 answers)
Closed 6 years ago.
So I have few buttons that are arranged in this fashion:
<button>Home</button>
<button>Blog</button>
<button>Forums</button>
<button>Contact Us</button>
I want to have a "selected" class or ID that changes the background of the selected button.
I tried doing this:
button > .selected {
background: red !important;
}
And changed button in HTML to this:
<button class="selected">Home</button>
It didn't do anything at all, button background stayed the same color. I also tried using ID instead of class to no avail.
How can I solve this task easily?
Use:
button.selected {
background: red !important;
}
For a button with a class (Make sure there's no space between them, or you will be selecting child elements)
You should also be able to remove the !important unless there's actually a good reason to keep it. Since the selector including a class is more specific than a standard selector, it will overwrite the background colour without the use of !important.
The > symbol means a direct child of an element.
Here's a few beginers resources for leaning about CSS selectors:
https://css-tricks.com/how-css-selectors-work/
https://css-tricks.com/child-and-sibling-selectors/
try these code, it will work
button{
background:green;
}
button.selected {
background:red;
}
button:active,button:focus {
background:red;
}
<button>Home</button>
<button>Blog</button>
<button>Forums</button>
<button>Contact Us</button>
This question already has answers here:
Does :before not work on img elements?
(16 answers)
Closed 8 years ago.
I've tried this and it works fine
<p alt="world">hello</p>
With CSS
p::after {
content: attr(alt);
}
But it doesn't work when I try
<img src="http://placehold.it/300x300" alt="my image caption">
With CSS
img::after {
content: attr(alt);
}
Is it possible to output alt text for an img using CSS?
Please indicate browser compatibility with any solution you provide.
Here's a jsfiddle
This is by design.
img tags are self-closing (<tag />) tag, and therefore they contain no "content". Since they do not contain any content, no content can be appended (i.e. ::after) or prepended (i.e. ::before).
This is also the case for other self-closing HTML elements:
<area>, <base>, <br>, <col>, <command>, <embed>, <hr>, <keygen>,
<link>, <meta>, <param>, <source>, <track> and <wbr>
Here's what the (CSS2) Spec says:
Note. This specification does not fully define the interaction of
:before and :after with replaced elements (such as IMG in HTML). This
will be defined in more detail in a future specification. [2014: hasn't happened yet]
Source: http://www.w3.org/TR/CSS2/generate.html#before-after-content
This question already has answers here:
How to fade to display: inline-block
(6 answers)
Closed 9 years ago.
div#errors_of_saved{
width: 100px;
display: inline-block;
display: none;}
There is error div, which is hidden until some JS function doesn't fade it in, and also it should be displayed inline.
The problem - this way text editor says that display property is overwritten, and display: inline-block none; - that syntax is invalid.
I don't want to use visibilty:hidden because Jquery animation fadeIn() fadeOut() doesn't work with visibility.
What can I do?
Because div#errors_of_saved is displayed on demand to show error messages, I would set the default to display: none.
jQuery tends to use display: block to show an element. Since you want to use display: inline-block, I might try setting a more specific CSS rule, for example:
div#errors_of_saved.show {
display: inline-block
}
and then have jQuery add the class as needed to show the error message.
My suggestion assumes that you might use the jQuery animate() function, but there are several approaches one could try.