Applying CSS only to parent without touching the child - html

How can I hide/remove the "Category:" text here without touching what is inside <span> </span>?
<h1 class="f_p f_700 f_size_50 w_color l_height50 mb_20">
Category:
<span>Men</span>
</h1>
Thanks in advance.

Edit: I missed the important detail below. As another answer might have noticed, trying something like display: none and display: initial isn't going to work.
How can I hide/remove the "Category:" text
The initial CSS keyword can be applied to children to reset styles. As the doc mentions, sometimes initial has unexpected results, check out its peers inherit, unset, and revert. To give an example using text color:
h1 {
color: red;
visibility: hidden;
}
h1 > span {
color: initial;
visibility: initial;
}
<h1 class="f_p f_700 f_size_50 w_color l_height50 mb_20">
Category:
<span>Men</span>
</h1>

You could change visibility to hidden or font-size to zero on parent and reset it on the child. Without attaching any styles to the child, it's not possible with css.

If it's possible to use JS, try this:
$("h1").contents().filter(function(){
return (this.nodeType == 3);
}).remove();
<h1>Category:<span>Men</span></h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Or, with CSS only:
h1 {
font-size: 0px;
visibility: hidden;
}
h1 span {
font-size: 36px;
visibility: initial;
}
<h1>Category:<span>Men</span></h1>

Related

CSS - do not show symbol at anchor with ::before

I have some code in my WP CSS that shows a link-symbol before links on pages and articles. Here is section of the styles for styling anchors:
.entry-container .entry-content a::before {
display: inline-block;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
padding-right: 4px;
font: var(--fa-font-solid);
content: "\f0c1";
}
Problem: The symbol shows before anchors too.
On one page I managed to hide them successfully using this chunk of CSS:
#mpm.wpsal-anchor::before {
display: none;
}
This works fine.
But on the other page, I have several anchors and I want to use a css code, that hides all of them without typing each anchor! I tried
[class$="wpsal-anchor::before"] {
display: none !important;
}
but without success.
Do anyone have a suggestion or solution?
Thanks in advance!
So based on your reply of not wanting the before to show on any anchor element there are a few things you can try
You can use the * in CCS to target all elements and follow it with an anchor. The CSS below says that for all elements that have an anchor tag to not display the before pseudo element. Give that a try. I would put it at the top of your CSS just in case other elements use before. You could also try it without the ( and just use a::before
* a::before { display: none; }

Can you use two different pseudo elements on one element on CSS?

I make userstyles, in other words, third party CSS or custom CSS, and I'm replacing text with content property and the before and after pseudo elements. The problem is, to completely hide the original text, I have to set the original element's font-size to 0. This also hides things set in place with the hover pseudo element. I was going to just apply the hover properties to my before pseudo element, but then I would have to use 2 pseudo elements, which I don't think is possible. But, I'm not sure. Here's a sample similar to my code.
a.class[href="link"] {
font-size: 0;
visibility: hidden;
hover:
}
a.class[href="link"]:hover {
background-color: black;
}
a.class[href="link"]:before {
font-size: 16px;
visibility: visible!important;
content: "This text replaced what showed before";
}
a.class[

Apply style to div but not <strong> child

How can I possibly apply a style to a parent div but not the <strong> child. I've tried various ways of :not selector but none of my tries succeeded.
Here's what I came up with
.total:not(strong) {
color: gray;
}
<div class="total">Baloons <strong>$3.75</strong></div>
<div class="total">Pens <strong>$1.99</strong></div>
I know I can do apply the styles to those separately but I am looking for a :not way of doing it so I can do it on one line.
I also know I can give <strong> a class and do .total:not(.strong-class) but why doesn't it work the way I try it originally?
The :not rule refers to the target element. Your rule .total:not(strong) is translated to apply the styles (color: gray) to an element with class .total, which is not a strong node (the <strong> tag). Since the .total node is div, the rule still applies.
Reset the strong's color to initial or choose a different color:
.total {
color: gray;
}
.total strong {
color: initial;
}
<div class="total">Baloons <strong>$3.75</strong></div>
<div class="total">Pens <strong>$1.99</strong></div>
Check the default css of color in the element strong.
.total:not(strong) { works fine, but the default color is gray too!
:not
*{color:blue}
.total:not(strong) {
color: gray;
}
<div class="total">Baloons <strong>$3.75</strong></div>
<div class="total">Pens <strong>$1.99</strong></div>
You can use this code
body {
padding: 0;
margin: 0;
}
.total {
color: red;
}
.total strong {
color: gray;
}
<div class="total">Baloons <strong>$3.75</strong></div>
<div class="total">Pens <strong>$1.99</strong></div>

Hiding element in body, which has specific classes

I got some code here:
<html>
<head>
<title>Select View</title>
</head>
<body class="class-1 class-2 class-3 class-4 class-5 class-6">
Many divs here
...
...
...
<div id="test">
<p>PHP code here</p>
</div>
</body>
</html>
And I want to hide the div with the test id. My site is based on wordpress, so in css I have to refer to a specific body.
I tried:
body.class-1, .class-2, .class-3, .class-4, .class-5, div#test{
color: red;
}
and the color is working, "PHP code here" is on red color, but when i do this:
body.class-1, .class-2, .class-3, .class-4, .class-5, div#test{
display: none; //or visibility: hidden;
}
all site dissapears.
Any ideas how to hide only this div?
Just use what you have already
div#test{
display: none;
}
When you called body.class-1, .class-2, .class-3, .class-4, .class-5, and set display: none, it is the expected behaviour, because you are hiding all elements rather than just the test div!
Since you don't repeat the id in other elements you can just use,
#test {
display: none;
}
Just in-case if you have another element (ex: span) with the same id you have to specifically mention that you need to hide the div element with id=test
div#test {
display: none;
}
It is always a good thing to uniquely mark your elements if possible. Since you are dealing with classes if you just mention one class it will select the matching element.
In the below case you used your selection is the whole body,
body.class-1, .class-2, .class-3, .class-4, .class-5, div#test{
display: none; //or visibility: hidden;
}
This might be the same case if you just use the below code,
.class-1 {
display: none; //class-1 supposed to pick the whole body here;
}

how to hide the content of the div in css

I have this html code
<div id="mybox"> aaaaaaa </div>
and this is my css
#mybox{
background-color:green;
}
#mybox:hover{
background-color:red;
}
the question is how to hide the content of the div (aaaaaaa) when the mouse hover event by using css only and without changing the structure of the code
I think I should put some code under #mybox:hover but I don't know the code.
Without changing the markup or using JavaScript, you'd pretty much have to alter the text color as knut mentions, or set text-indent: -1000em;
IE6 will not read the :hover selector on anything other than an anchor element, so you will have to use something like Dean Edwards' IE7.
Really though, you're better off putting the text in some kind of element (like p or span or a) and setting that to display: none; on hover.
Here is the simplest way to do it with CSS3:
#mybox:hover {
color: transparent;
}
regardless of the container color you can make the text color transparent on hover.
http://caniuse.com/#feat=css3-colors
Cheers! :)
Hiding through CSS is achieved by using either the "visibility" or the "display" attributes. Though both achieve similar results, it's useful to know the differences.
If you only want to hide the element but retain the space occupied by it, you should use:
#mybox:hover {
visibility: hidden;
}
If you want to hide the element and remove the space occupied by it, so that other elements can take its space, then you should use:
#mybox:hover {
display: none;
}
Also remember that IE6 and below do not respond to :hover for anything except A tags. In which case, you'll need some Javascript to change the classname:
document.getElementById('mybox').className = 'hide';
and define the "hide" class in CSS:
.hide { display: none; }
sounds silly but font-size:0; might just work. It did for me. And you can easily override this with the child element you need to show.
You could make the text color the same as the background color:
#mybox:hover
{
background-color: red;
color: red;
}
What about opacity
#mybox:hover {
opacity: 0;
}
Best way to hide in html/css using display:none;
Example
<div id="divSample" class="hideClass">hi..</div>
<style>
.hideClass
{display:none;}
</style>
This is a late answer but still, guess setting the color to transparent is the best option.
#mybox:hover{
background-color:red;
}
There are many ways to do it:
One way:
#mybox:hover {
display:none;
}
Another way:
#mybox:hover {
visibility: hidden;
}
Or you could just do:
#mybox:hover {
background:transparent;
color:transparent;
}
#mybox:hover { display: none; }
#mybox:hover { visibility: hidden; }
#mybox:hover { background: none; }
#mybox:hover { color: green; }
though it should be noted that IE6 and below wont listen to the hover when it's not on an A tag. For that you have to incorporate JavaScript to add a class to the div during the hover.
I would say:
#mybox{
background:green;
}
#mybox:hover{
color:transparent;
}
<div id="mybox">
This text will disappear on hover
</div>
This will hide text, but of course, it still contains the text, but it is a tricky way to hide the text (make in invisible), but it will work well
Sorry to be 7 years late but this could be achieved by using the below:
.your-block{
visibility: hidden;
width: 0px;
height: 0px;
}
This will keep the content on the page and won't occupy any space whereas display:none will completely hide the content.
Using the above code can be useful if you need to reference code in a div but don't need it to display.
.button {
width: 40px;
height: 40px;
font-size: 0;
background: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%221284%20207%2024%2024%22%3E%3Cg%20fill%3D%22none%22%3E%3Cpath%20d%3D%22M1298.5%20222.9C1297.5%20223.6%201296.3%20224%201295%20224%201291.7%20224%201289%20221.3%201289%20218%201289%20214.7%201291.7%20212%201295%20212%201298.3%20212%201301%20214.7%201301%20218%201301%20219.3%201300.6%20220.5%201299.9%20221.5L1302.7%20224.2C1303%20224.6%201303.1%20225.3%201302.7%20225.7%201302.3%20226%201301.6%20226%201301.2%20225.7L1298.5%20222.9ZM1295%20222C1297.2%20222%201299%20220.2%201299%20218%201299%20215.8%201297.2%20214%201295%20214%201292.8%20214%201291%20215.8%201291%20218%201291%20220.2%201292.8%20222%201295%20222Z%22%20fill%3D%22%239299A6%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E") #f0f2f5 no-repeat 50%;
}
<button class="button">Поиск</button>