Changing visibility of the div element using only CSS - html

Is it possible without JS/jQuery?
For example: I've got three divs with background images. I want to toggle one description for each image on click. Then, after clicking another image, I need to hide previous description and show one related.
One description can be displayed instantly after page load. There will be content below those paragraphs.

You can use the pseudo class :target and a link with href set to the id of the element that you want to show.
Simple demo
Demo with three images and three descriptions
Demo with transitions
#show {
display: none;
}
#show:target {
display: block;
}
HTML
Click me
<div id="show">Show me!</div>

Related

select only text in elementor nav menu

i have been fiddling around with this for a few hours now.
I have a vertical elementor nav menu and i want to apply a hover affect to it.
So far so good, but i only seem to be able to select the whole column and apply the affect onto that, not only the length of the text.
Here is an example of how it currently looks, the closing "brakets" are always at the same width at the end of the column:
Example 1:
Example 2:
What i want it to be like is on the end of the text - which is differnet for each menu item.
Like This:
My current selector is .elementor-7 .elementor-element.elementor-element-1cf0e88 .elementor-nav-menu--main .elementor-item: - i tried with "a" as well which made it not work at all.
Thank you.
Max
You can not select only text. The text must be inside a html tag.
For example:
div {
color: green;
}
p {
color: red;
}
span {
color: blue;
}
<div>
<p>I am selectable with p { }</p>
I am not selectable as I am a text element of root div tag.
<span>Again I am selectable as I am wrapped with span tag.</span>
<div>
A link to the site would be helpful.
But the problem here is probably, that the element you're targeting is "display: block" or similar, making is a full-width element.
Try setting the a-tag to "display: inline" or "display: inline-block", which will make the width fit the element - not the parent div.
Alternatively, you could target each link as "nth"-elements of a list, but I would need to see the actual page to determine that, as Elementor is rarely just "Elementor". Your theme and additional addons play a part here as well.

how to code if this element activated the other element changes with html and css

I want to know if it's possible to click on an element and then change another element only using Html and CSS and if it is then how.
some thing like this ( btw this code doesn't work ) :
a:active div{
background-color : blue;
}
Without Javascript your options are rather limited.
You have to find a way to toggle the state by a click and be able to express those states in CSS.
Some option might be theese:
using (hidden?) radiobuttons or checkboxes and using their :checked pseudo class in CSS
using anchors and their pseudo classes (like you already attempted to do)
The problem here is that you have to put all your dynamic contents (the stuff you show/hide on click) inside or next to those toggling elements which might be inpractical.
My favorite is the :target pseudo class. When you open the URL "https://something.com#foobar" the element with the id "foobar" is the current target (if it exists). One limitation of this is that there is only one single target per document. You can control the target by clicking on anchors like this:
.dynamic-content {
display: none;
}
#first:target, #second:target {
display: block;
}
<div>
<div id="first" class="dynamic-content">
First dynamic content
Hide
</div>
<div id="second" class="dynamic-content">
Second dynamic content
Hide
</div>
</div>
Show first
Show second
One way ,I use :focus pseudo class. div:focus a {}

Background change in div

I want to have the background color stay after I click on the div.
This div is linked to target another div.
<div class="barbutton">ABOUT</div>
here is the CSS of the div i click on
.barbutton:hover {
background-color: #7BDFBE;
}
so I want the background color to stay when its clicked.
I think what you're trying to achieve is the normal link behaviour i.e. it changes colour and stays that way to indicate it has already been visited. If yes, then you're approaching the problem the wrong way in CSS.
Instead of putting the CSS on a new DIV inside the <a> tag put the CSS on the link itself.
<a class="barbutton" href="#aboutbody">ABOUT</a>
Then use the link states in CSS as below:
a.barbutton:visited {
background-color: #7BDFBE;
}
a.barbutton:hover {
background-color: #7BDFBE;
}
Similarly, add the other links states you require.
To maintain state like you are wanting, I would suggest using some javascript/jQuery.
Javascript:
<div id="barbuttonid" class="barbutton">ABOUT</div>
<script type="text/javascript">
document.getElementById("barbuttonid").onclick = function() {
document.getElementById("barbuttonid").className += " clicked";
};
</script>
jQuery:
<div class="barbutton">ABOUT</div>
<script type="text/javascript">
jQuery('.barbutton').click(function() { jQuery(this).addClass('clicked'); });
</script>
CSS:
/* anchor tags are inline and cannot contain blocks elements like divs */
#aboutbody {
display: inline-block;
}
.barbutton:hover {
background-color: #7BDFBE;
}
.barbutton.clicked {
background-color: #7BDFBE;
}
Now when it is clicked, the additional class will be added and the CSS style can make the background persist for you.
EDIT/NOTE:
Ravi's answer is better as it does not use javascript. If you kept the HTML layout as you have it, the CSS declarations would have to be:
a:hover .barbutton {...}
a:vistied .barbutton {...}
Also, this way will make the style persist as long as the browser remembers that the link has been visited (user comes back in 3 days and the background color may still be persistant). My way above will not keep the background as soon as the user refreshes or leaves the page. I guess it depends on what you are going for.

A simple tab implementation with <ul><li> but how to set tab background-image?

I implemented a simple tab navigation by using <ul><li><a> , the problem is that there are several "layers" on each tab still needed. what I mean is, In my current implementation I have:
-tab text which is <a>text</a>
-on each tab I have a tab icon image, which I put on <li> as background-image of <li>,
But I still need:
-tab seperator image (A vertical bar image) which I intend to put on <a>,and position it on the left side background-position: left , it is working but this implementation is not in my code which I showed below on jsfiddle site because I did not find a suitable image on internet
-tab background image which occupy the whole tab, I have no idea where I should put this image?
Please check & run my implementation here on jsfiddle, in the css code, I used background-color instead of background-image just to express what I want to achieve, but I need to use background-image as the tab background.
What I tried:
I tried to put the tab background image on <li> but it will hide the
icon image which has already on <li>,
I tried to put the tab background image on <a> but it will also hide the tab seperator image when mouse hover
How to get rid of this layer probelm on tab implementation then? (Please do not suggest me to use less image, since it is one requirement of this app to use those images.)
(By the way, all images I mentioned have mouse "hover" counterpart)
If you don't want to change the HTML, you can use pseudo-elements:
Fiddle: http://jsfiddle.net/Pq7LC/39/
li:before{
content: "";
background: pink;
width: 20px;
height: 61px;
display: block;
position:absolute;
}
li:first-child:before{ /* Don't add image border before first li */
content:none;
}
You can do it with css, no need of images.
http://jsfiddle.net/Pq7LC/40/
Hope it helped you :)

multi radio buttons transformed into a radio button with css?

I want After click on the radio,
Radio-selected that background color is yellow putting background label, with use of css no js.
how is it?
Example of myself: http://jsfiddle.net/DVJmS/6/
Example of ui: http://jqueryui.com/demos/button/radio.html -> I not want use of plugin this is only a example.
Volia
What you need to do is:
wrap each <input /><label></label> in a <div>
give input[type="radio”] a width and height of 0px
Then add this rule to your css :checked ~ label {
background: #f00;
}
What that last one does is says if there’s a sibling of mine that is checked preceding me then make me have a background of #f00. Just change the alignment and colors to fit your site.
Also, you should never give two elements the same ID. If you want to be able to select two elements at once always uses classes.