CSS: Click button to transition and keep style open - html

That might sound odd, but essentially, I'm trying to make it so when i click on a designated button/spot on a page, it opens up a CSS border box that contains information. I know how to make it hidden, but like when you hover and it appears using the :hover attribute, i want to make it stay permanently visible after the hover transition is complete. Can this be done with CSS? Or is it going to require Javascript? Here is the code I'm using as a starter base.
#information {
border: solid 2px #FF8000;
border-radius: 20px;
position: absolute;
height: 48%;
width: 24%;
left: =0.6%;
top: 0.7%;
padding: 0.4%;
color: #FFFFFF;
background-color: rgba(114, 70, 0, 0.3);
overflow: hidden;
}
#information:hover {
left: 74.6%;
}
<div id="information">
<div style=" height: 325px; overflow-x: hidden;" align="left">
<i>Information</i>
<br><br>
</div>
</div>
Sorry, I'm new to the site, and I'm still working out how to format my posts.

#information {
border: solid 2px #FF8000;
border-radius: 20px;
position: absolute;
height: 48%;
width: 24%;
left: =0.6%;
top: 0.7%;
padding: 0.4%;
color: #FFFFFF;
background-color: rgba(114, 70, 0, 0.3);
overflow: hidden;
}
input[type="radio"] {
display: none;
}
input[type="radio"]:checked + label {
left: 74.6%;
}
<input type="radio" id="box">
<label id="information" for="box">
<div style=" height: 325px; overflow-x: hidden;" align="left">
<i>Information</i>
<br><br>
</div>
</label>
My solution is similar to what #Michael Coker suggested. We can use radio button instead to disable click on label after first click. I removed the inner div inside #information to make HTML W3C valid.

I'm trying to make it so when i click on a designated button/spot on a page, it opens up a CSS border box that contains information.
You can use the "checkbox hack" to pull off changes like this in CSS. https://css-tricks.com/the-checkbox-hack/
#information {
border: solid 2px #FF8000;
border-radius: 20px;
position: absolute;
height: 48%;
width: 24%;
left: =0.6%;
top: 0.7%;
padding: 0.4%;
color: #FFFFFF;
background-color: rgba(114, 70, 0, 0.3);
overflow: hidden;
}
input[type="checkbox"] {
display: none;
}
input[type="checkbox"]:checked + label {
left: 74.6%;
}
<input type="checkbox" id="box">
<label id="information" for="box">
<div style=" height: 325px; overflow-x: hidden;" align="left">
<i>Information</i>
<br><br>
</div>
</label>

Related

Make element with position: absolute stretch the shadow of parent?

I have a usual search as most websites do. The results are shown below on the div that is visually connected to the search input.
It looks like this:
I need to have one solid shadow for the div parent but can't figure out or find online the way to do this.
I thought that I could either make 2 separate shadows, but that will look inconsistent and just terrible. Or I could make a div below with the same height and width that will act as a shadow but that's a non-necessary complication + the .search-results div's height will change dynamically.
This is an example:
body {
background-color: gray;
}
.search-wrapper {
position: relative;
margin: 100px 100px 0px 100px;
width: 200px;
overflow: initial;
box-shadow: 0px 0px 10px 10px rgba(0,0,0,0.3);
}
.search {
width: 200px;
height: 30px;
color: white;
border-radius: 4px;
} .search input {
padding: 0;
background-color: #022222;
border: none;
height: 100%;
width: 100%;
color: white;
}
.search-results {
position: absolute;
height: 150px;
width: 200px;
background-color: black;
}
<div class="search-wrapper">
<div class="search">
<input placeholder="air max . . .">
</div>
<div class="search-results">
</div>
</div>
I am sure there must be a clever and simple way to do this.
Please help,
Thank you
You don't need to use positions here and you can use FlexBox instead. It's the best way and a lot easier. Also, you can ignore all of them, they will place on top of each other because they are block-level tags/elements. (divs)
You don't need to put the input in another div parent, use it as I did.
Sorry, I couldn't understand your code, so I must write the whole code from the beginning.
EDIT
I removed display flex, cause it's not necessary.
* {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: Arial;
border-radius: 10px;
background-color: #fff
}
body {
height: 100vh;
background-color: gray;
padding: 30px
}
.search-wrapper {
/* EDITED HERE ADDED HEIGHT */
position: relative;
z-index: 999;
width: 200px;
height: 160px;
box-shadow: 0 0 2px 5px rgba(232, 232, 232, .2)
}
.search-input {
width: 100%;
position: absolute;
padding-block: 5px;
border: none;
outline: none;
padding: 15px
}
.search-result {
/* EDITED HERE */
position: absolute;
z-index: 999;
bottom: 0;
width: 100%;
padding: .5px
}
p {
padding: 10px 0 10px 10px;
}
p:hover {
background-color: #e8e8e8;
cursor: pointer
}
<div class='search-wrapper'>
<input class='search-input' placeholder='Search...'>
<div class='search-result'>
<p>Nike Airforce</p>
<p>Nike Airforce</p>
<p>Nike Airforce</p>
</div>
</div>

css hover div flickering

Well, my HTML looks like this, when I hover over the image the two checkboxes with a black background should be visible.
<img class='itemImage'/>
<div class='hoverDisplay'>
<div class="selctImgInptWrapper big">
<input class="selctImgInpt" type="checkbox" value="">
</div>
<div class="selectWrapperImgRetouch big">
<input class="selctImgRetouch" type="checkbox" value="">
</div>
</div>
My CSS
.hoverDisplay {
height: 75px;
font-size: 0.80rem;
background-color: rgba(44, 44, 44, 0.3);
background: rgba(44, 44, 44, 0.3);
color: #ffffff;
width: 95%;
bottom: 8px;
position: absolute;
padding: 2px 5px;
display: none; }
.hoverDisplay .selctImgInptWrapper {
bottom: 50px;
position: absolute;
padding: 2px 5px;
}
.hoverDisplay .selectWrapperImgRetouch {
bottom: 30px;
position: absolute;
padding: 2px 5px; }
.itemImage:hover ~ .hoverDisplay {
display: block; }
It works fine when I hover on the image, the two checkboxes are visible, the problem starts when I hover on the checkboxes it starts to flicker
I am not able to figure out the false scenario here.
When I move my cursor to the black are which is hoverDisplay class it starts to flicker and I am not able to check any checkboxes. While moving my
Simply because you will loss the hover when you want to use the input as you are no more hovering the image but another element which is a sibling. To avoid this add another property to keep the display:block state:
.itemImage:hover ~ .hoverDisplay,
.hoverDisplay:hover {
display: block;
}
The problem is that you show the checkboxes when you hover over the image. And then when you hover the checkboxes ( because they are not inside the image ( they are impossible to be) ) you hover out the image and css tries to hide them. But checkboxes are on top of the image, so the flickering happens.
You basically hover in and out the image in the same time.
One solution would be to wrap the img and checkboxes in a div and show the checkboxes when you hover over the div not just the img.
.img-container {
position:relative;
width:350px;
}
.hoverDisplay {
height: 75px;
font-size: 0.80rem;
background-color: rgba(44, 44, 44, 0.3);
background: rgba(44, 44, 44, 0.3);
color: #ffffff;
width: 95%;
bottom: 8px;
position: absolute;
padding: 2px 5px;
display: none;
}
.hoverDisplay .selctImgInptWrapper {
bottom: 50px;
position: absolute;
padding: 2px 5px;
}
.hoverDisplay .selectWrapperImgRetouch {
bottom: 30px;
position: absolute;
padding: 2px 5px;
}
.img-container:hover .hoverDisplay {
display: block;
}
<div class="img-container">
<img class="itemImage" src="http://via.placeholder.com/350x150">
<div class='hoverDisplay'>
<div class="selctImgInptWrapper big">
<input class="selctImgInpt" type="checkbox" value="">
</div>
<div class="selectWrapperImgRetouch big">
<input class="selctImgRetouch" type="checkbox" value="">
</div>
</div>
</div>

how to allow a hidden button to be shown when focused using CSS only?

I have a container div and it has a hidden button inside it and it appears only when focusing on the container div. I want to make the button visible when focused (I want to make it focusable). Here's a fiddle
HTML:
<div class="ads" tabindex="0">
<button class="close" tabindex="0">X</button>
</div>
CSS:
.ads{
position: relative;
display: inline-block;
border-radius: 0.5625rem;
border-style: solid;
border-width: 0.03125rem;
border-color: lightgrey;
background-color: #ffffff;
width: 100%;
height: 80px;
}
.close{
display: none;
padding: 0;
background: transparent;
border: none;
margin-top: 0.5rem;
margin-right: 0.5rem;
float: right;
width: 0.5rem;
height: 0.5rem;
background-image: url('delete.png');
background-size: 100% 100%;
}
div.ads:focus{
background-color: #ebeded;
}
div.ads:focus .close{
display:inline-block;
}
button.close:focus{
display:inline-block;
}
How can I achieve that?
Thank you.
At any given moment of time only one element can be in focus or none.
But your solution assumes that there are two elements matching :focus in the document at the same time.
Here is sequence of events when you press TAB on focused div:
Your div looses focus so is does not match :focus;
Button gets hidden as it has not got focus yet;
as nothing visible/focusable inside the div focus moves to something else but not to the button.
You should find other solution.
Update: possible CSS only hack is to use opacity:0 instead of display:none.
Hack here is that opacity:0 element is considered as still displayed element so focusable.
input{
display: block;
width: 100%;
}
.ads{
position: relative;
display: inline-block;
border-radius: 0.5625rem;
border-style: solid;
border-width: 0.03125rem;
border-color: lightgrey;
background-color: #ffffff;
width: 100%;
height: 80px;
}
.close{
opacity: 0;
padding: 0;
background: transparent;
border: none;
margin-top: 0.5rem;
margin-right: 0.5rem;
float: right;
width: 0.5rem;
height: 0.5rem;
background-image: url('delete.png');
background-size: 100% 100%;
}
div.ads:focus{
background-color: #ebeded;
}
div.ads:focus .close{
opacity: 1.0;
}
button.close:focus{
opacity: 1.0;
}
<input type="text" placeholder="press on me and tab two times">
<div class="ads" tabindex="0">
<button class="close" tabindex="0">X</button>
</div>
<p>
by the second tab you should see focused button ,but you don't
</p>

z-index conflict with static element

https://jsfiddle.net/0Lfzbzc5/2/
in here I am trying to make the notification box on top of the body class div but couldn't do it the logic says positioned elements should be on top of the not positioned elements but that isn't happenning
tried even making body class div relative and giving it z-index but failed too
structure of notification box is an absolute element in relative element in absolute element (for CSS animation issues)
HTML
<div class="notiIcon glyphicon glyphicon-globe">
</div>
<div class='notiAbs '>
<div class='notiContainer'>
<div class="notiBox">
<div class="notiHeader">
<span class="notiHeaderSpan">notifications</span>
</div>
<div class="notiBody">
<div class="notiElement">Collaboratively enable high-quality imperatives before ubiquitous paradigms.
</div>
<div class="notiElement">Credibly productize customized services whereas.</div>
<div class="notiElement">Efficiently embrace real-time markets without.</div>
<div class="notiElement">Synergistically simplify collaborative web services.</div>
<div class="notiElement">Intrinsicly evisculate magnetic e-services through.</div>
<div class="notiElement">Holisticly build customer directed technologies.</div>
<div class="notiElement">Phosfluorescently synthesize team driven strategic.</div>
</div>
<div class="notiFooter"><span class="notiHeaderSpan">See All</span></div>
</div>
</div>
</div>
<div class="body">aasdasdasdasdasdasdas</div>
CSS
.notiAbs{
position: absolute;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
/* overflow-y: hidden; */
height: 500px;
width: 500px;
/* overflow-x: hidden; */
overflow-y: hidden;
margin: 0 auto;
padding-left: 50px;
}
.notiContainer{
position: relative;
}
.notiIcon{
z-index: 5;
position: relative;
width:100%;
text-align: center;
font-size: 25;
cursor: pointer;
padding-top: 10px;
}
.notiIconNumber{
position: relative;
font-size: 15px;
color: white;
background-color: red;
top: -10;
left: -9;
padding: 2px;
}
.notiBox{
z-index: 4;
position: absolute;
height: 400px;
width: 400px;
display: block;
padding-top: 10px;
box-shadow: rgba(0, 0, 0, 0.298039) 0px 4px 7px;
}
.notiElement{
overflow-wrap:break-word;
font-size: 17px;
padding: 10 0px;
border-bottom-style: solid;
border-bottom-width: thin;
border-bottom-color: lightgray;
}
.notiHeader,.notiFooter{
text-align: center;
font-size: 20px;
font-weight: bold;
height: 15%;
display: table;
width: 100%;
}
.notiHeaderSpan,.notiFooterSpan{
display: table-cell;
vertical-align: middle;
}
.notiFooter{
box-shadow: 0px -4px 7px rgba(0, 0, 0, 0.1);
cursor: pointer;
}
.notiHeader{
box-shadow: 0px 4px 7px rgba(0, 0, 0, 0.1);
}
.notiBody{
padding: 20px;
overflow: auto;
height:70%;
}
.body{
}
It is on top but the background is transparent so it makes the illusion that it's not. Just set a background color as follows :
.notiBox{
z-index: 4;
position: absolute;
height: 400px;
width: 400px;
padding-top: 10px;
border-style:solid;
background:#666;
}
Check the Fiddle.
Your notification box which I believe is the element with class "notiBox" is on top. The reason why it appears not to be is because it has an inherited background-color of transparent.
If you set the background-color property to say "yellow" (for examples sake) you will see that it is on top of the element with class "body".
Does that make sense? I can explain further if you need me to.
I've updated my answer as looking at your HTML again i've realised that the element with class "notiBox" is probably the only element (and it's contents) you want to appear on top

Absolute vs Fixed Positioning

I have a custom dialog box which is shown when I click a button. After the dialog box is shown I show a overlay. The height and width of the overlay is 100% x 100%. Here comes the problem, the height 100% just gets the height of the browser window so when I scroll down on the page it remains at the top. How can I set its height to full page height not browser's?
Fiddle.
HTML:
<div id="overlay"></div>
<div class="description" style="text-align: justify;">Some text..(whole big text is in the fiddle didn't wrote here to shorten the code :))</div>
<div style="text-align: right">
<button id="offer_help">Offer Help</button>
</div>
<div class="offer_a_help">
<textarea rows="5">Write a short experience about yourself</textarea>
<textarea rows="5">Write what do you want in return</textarea>
<button id="send_offer">Send Offer</button>
</div>
CSS:
#overlay {
opacity: 0.5;
width: 100%;
height: 100%;
background-color: black;
display: none;
position: absolute;
top: 0;
left: 0;
}
#offer_help {
background-color: #eee;
border: 0;
padding: 10px;
border-radius: 2px;
box-shadow: 0px 0px 3px 1px #aaa;
}
.offer_a_help {
display: none;
width: 400px;
height: 250px;
position: fixed;
top: calc(100%/2 - 350px/2);
left: calc(100%/2 - 250px/2);
background-color: #eee;
border: 1px solid #bbb;
text-align: center;
}
.offer_a_help textarea {
width: 90%;
padding: 2px;
font-family: Calibri;
}
.offer_a_help textarea:first-child {
margin-top: 20px;
}
.offer_a_help button {
float: right;
margin-top: 10px;
margin-right: 10px;
border: 1px solid #bbb;
background-color: #ddd;
padding: 5px;
border-radius: 3px;
}
How can I set its height to full page height not browser's?
position: absolute takes the element out of line with the document. so the height is that of the viewport, and the top,left values are static. Change this to position: fixed and you will see better results.
Use position:fixed.
http://jsfiddle.net/ryJEW/2/
#overlay {
opacity: 0.5;
width: 100%;
height: 100%;
background-color: black;
display: none;
position: fixed;
top: 0;
left: 0;
}