Div that appear after a click (only CSS3) - css

I need to create an icon that shows a div (menu) after a click on it.
Is it possible with CSS3?
This is for the mobile version and I don't need the :hover solution.
PS: If the only solution is doing it with Javascript a link to something would be good too.
CSS
.nav{
color: black;
background-color:white;
height: 5vh;
width: 100vw;
}
.menu{
color: black;
background-color:green;
height: 90vh;
width: 90vw;
}
HTML
<div class="nav">
<!-- Font Awesome Icon -->
<i class="fa fa-bars"></i>
</div>

Theres a few different ways to do this, none of them are foolproof I believe, here's an example using the :focus method. http://fiddle.jshell.net/rpwe4kzy/4/
CSS
.hide{display: none;}
button:focus ~ .hide{ display: block;}
HTML
<div>
<button tabindex="0">Show text</button>
<p class="hide">Hidden type</p>
</div>
See here for more solutions, https://tympanus.net/codrops/2012/12/17/css-click-events/
Otherwise if you want to use JS I suggest utilising a simple jquery function. I'm guessing you have jquery in your project already otherwise just substitute it for a vanilla javascript function.
CSS
<style>
.hidden{ display: none;}
</style>
HTML
<div>
<button class="click-me">Click me</button>
<p class="show-me hidden">
Here is some text!
</p>
</div>
JavaScript
<script>
$( document ).ready(function() {
$('.click-me').on('click', function(){
$('.show-me').show();
});
});
</script>
Here's a working example of the jQuery way, https://jsfiddle.net/clintongreen/bu22op77/

Related

I would like to let it be a click element with link tag in react, but I have problems with css

I am trying to make a website in local using React.
It is my codes, I surrounded those two elements with a div tag and applied border css looking like related elements, but when I applied a Link tag to go to another page to the div elements, the border started not surrounding under the element. In shortly, how can I use the css file that before apply Link tag?
Here is my code.
div{
border: 1px black solid;
width: 250px;
height: 300px;
}
.p {
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<Link to='/tests/'>
<div>
<i class='fas fa-check fa-5x'></i>
<p>take tests</p>
</div>
<Link>
You have to add a class to the div and fix your CSS.
.tests{
border: 1px black solid;
width: 250px;
height: 300px;
}
.p {
text-align: center;
}
The jsx
<Link to='/tests/' style={{ textDecoration: 'none' }}>
<div className="tests">
<i class='fas fa-check fa-5x'></i>
<p>take tests</p>
</div>
<Link>

CSS selector for class and attribute together

I've currently got a few buttons with the .continue class on a webpage, structured with the following code:
<div class="continue" data-section="1">
Continue
<i class="fas fa-arrow-right" id="continueArrow1"></i>
</div>
Each of the continue buttons have a different "data-section" values, and are also placed against different backgrounds on the webpage. I'm wondering if there is a way I am able to target one of these continue button divs that have a certain data-section value, and change the styling of those who match.
Something like:
.continue:data-section=1{
//css that styles button with data-section1
}
.continue:data-section=2{
//css that styles button with data-section2
}
Obviously I could always just give them different IDs, but that leads to a lot of code duplication for the JS and JQuery animations.
Use the attribute selector:
.continue[data-section="1"] {
...
}
Example:
div {
width: 100px;
height: 100px;
background: blue;
display: inline-block;
margin: 5px;
}
.continue[data-section="2"] {
background: red;
}
/*We can combine this selector with other selectors as we normally would:*/
.continue[data-section="2"]:hover {
background: yellow;
}
<div class="continue" data-section="1"></div>
<div class="continue" data-section="2"></div>
<div class="continue" data-section="3"></div>
<div class="continue" data-section="4"></div>
<div class="continue" data-section="5"></div>
Read more on MDN

ngDialog positioning and sizing

I am working on a popup window using ngDialog. Here is some code:
<style>
.ngdialog.dialogforpopup .ngdialog-content
{
width : 1100px;
margin-top:-100px;
padding-top:10px;
}
</style>
Template
<div style="height:800px;width:1040px;padding-left:5px;padding-top:5px;
padding-right:5px"
</div>
<div class="ngdialog-buttons" style="margin-top:10px">
<button type="button" class="ngdialog-button ngdialog-button-primary"
ng-click="cancel()">Cancel</button>
<button type="button" class="ngdialog-button ngdialog-button-primary"
ng-click="save()">Save</button>
</div>
Directive
ngDialog.open({
template: 'editor.html',
controller: 'editorController',
className: 'ngdialog-theme-default dialogforpopup',
closeByDocument: false,
disableAnimation: true
});
I have two questions.
How can center my popup on the screen? Currently I am using margin-top:-100px;
Is it possible to size ngDialog automatically to its content?
Thanks
One can center ngdialog by setting "table-like" styles:
.ngdialog{
padding:0 !important;
}
.ngdialog-content {
padding: 0 !important;
background: transparent !important;
display: table; /*table-like styles for vertical centering*/
width: 100% !important;
height:100%;
}
.ngdialog-holder {
display: table-cell;
vertical-align: middle;
width: 100%;
height:100%;
}
.ngdialog-content > .ngdialog-close{
display:none; /*hide original close button*/
}
.my-dialog{
width:400px;
background:#fff;
border:1px solid #000;
margin:0 auto; /*center dialog horizontally*/
position: relative;
}
Also one need to wrap content of dialog with ".ngdialog-holder" and ".my-dialog" blocks. And finally place ".ngdialog-close" button inside of it.
<div class="ngdialog-holder">
<div class="my-dialog">
Dialog content goes here
<div class="ngdialog-close"></div>
</div>
</div>
Here is live example: ngdialog plunk
I downloaded ngDialog package using bower. so ngDilaog related CSS and JS files are in bower_components.
I added the following CSS and JS files to my html page.
<link rel="stylesheet" href="../bower_components/ng-dialog/css/ngDialog.css">
<link rel="stylesheet" href="../bower_components/ng-dialog/css/ngDialog-theme-default.css">
<link rel="stylesheet" href="../bower_components/ng-dialog/css/ngDialog-theme-plain.css">
<script src="../bower_components/ng-dialog/js/ngDialog.js"></script>
In my own JS file I am opening the dialog in the following way:
ngDialog.open({ template : 'dialog' ,scope : $scope , className: 'ngdialog-theme-default', plain: false,
showClose: true,
closeByDocument: true,
closeByEscape: true,
appendTo: false});
here is the html code:
<script type="text/ng-template" id='dialog'>
<div class="ngdialog-message">
Hello!!
</div>
</script>
With the above changes I am able to show the pop up on the center of the screen.
can use of the following class for pop up.
className: 'ngdialog-theme-plain'
className: 'ngdialog-theme-default'
I hope this will help!

CSS on hover effect not working

Why does the css :hover effect not work?
http://jsfiddle.net/t7on1k15/
body,html
{
font-family: courier;
height:100%;
min-width: 100%;
margin:0;
padding: 0;
}
#idDivBodyWrapper
{
margin:0;
padding:0;
height: 100%;
width: 100%;
background: lightgray;
}
#four:hover
{
color:black;
}
The HTML
<div id="idDivBodyWrapper" style="vertical-align:middle;">
<div style="position:absolute;display:block;float:left;left:0;Top:0"><button class="btn btn-default btn-lg" style="opacity:1;background:transparent;font-family:courier;font-weight:bold;" onclick="location.href='http://vqplan.com';"><i style="color:white;opacity:1;" class="fa fa-th fa-fw fa-5x"></i><br><span style="opacity:1;color:white">home</span></button></div>
<table style="width:100%;height:100%;background:black;clear:both;vertical-align:middle;text-align:center;"><tr><td>
<h1 id="four" style="font-size:10vh;color:white;">Code that lasts.<br><br><i id="one" class="fa fa-terminal fa-3x fa-fw" style="color:white;"></i></h1>
</td></tr></table>
</div><!--end idDivBodyWrapper-->
Here is one that does work:
http://jsfiddle.net/tuxdukz4/
CSS - CASCADING style sheets. You've got style="color:white" inside your h1#four element. That color:white is at a higher precedence level than your external style sheet rule, so color: white overrides the :hover style.
If you mod your fiddle and put color:purple into the h1's style= attribute, you'll get the exact same behavior: the hover won't work.
Because of CSS Specificity. I truly recommend you to read about it: http://www.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/
You have an element-level style color: white that overrides the hover effect.
Check this for a working one: http://jsfiddle.net/t7on1k15/1/
fiddle: http://jsfiddle.net/t7on1k15/2/
change the <h1 id="four" style="font-size:10vh;color:white;"> html to this:
<h1 id="four">Code that lasts.<br><br></h1>
and then add this css:
#four {
font-size:10vh;color:white;
}
your inline style has highest precedence over other css code.
I believe that putting the style inline ("style="font-size:10vh;color:white;") takes precedence over css. Inline style has higher priority. You actually couldn't style #four without hover in css if you use an inline style.

Removing text from an undeclared div via CSS

Subj. I've got a module for Joomla (don't blame me for using joomla, it's not me, i'm just helping my friend) with advertisment. The problem is that i can't get source codes for any modules, so I have to fix most of the problems via CSS (display:none method mostly).
<div style="text-align: right;">
<a style="text-decoration:none; color: #c0c0c0; font-family: arial,helvetica,sans-serif; font-size: 5pt; " target="_blank" href="http://joomline.ru/">ADVERTISMENT HERE</a>
</div>
If only div was declared, I would simply make it invisible using the display:none method...
Looking forward to help !
EDIT:
<div class="content">
<div id="jlvkgroup41016340" style="background: none repeat scroll 0% 0% transparent; height: 301px; width: 270px;">
...
</div>
<script type="text/javascript"> ... </script>
<div style="text-align: right;">
<a style="text-decoration:none; color: #c0c0c0; font-family: arial,helvetica,sans-serif; font-size: 5pt; " target="_blank" href="ADVERT LINK">TEXT ADVERT</a>
</div>
</div>
Assuming you're trying to hide the link (with that specific href):
a[href^="http://joomline.ru"] {
display: none;
}
JS Fiddle demo.
Based on the newly-added HTML, you can target the specific a element using sibling-combinators:
#jlvkgroup41016340 + script + div a {
display: none;
}
JS Fiddle demo.
This targets the a elements that are a descendant of a div element that's the immediately-adjacent sibling of a script element that is itself the adjacent sibling of the element with the id of jlvkgroup41016340.
Or:
#jlvkgroup41016340 ~ div a {
display: none;
}
JS Fiddle demo.
This targets the a descendants of a div which is the later-sibling of the element of id="jlvkgroup41016340".
References:
General-sibling (~) combinator.
Adjacent-sibling (+) combinator.

Resources