I have a button in a div container for a scroll box with some profile info, and my goal is when you press the button the div appears (display: initial;), and when you press it again it disappears (display: none;) Any ideas?
Html:
<div>
<div class="scrollbar">
<input type="button" class="profile_info">Profile Picture
<div class="image_change">This is Blue</div>
</div>
</div>
Css:
div.scrollbar {
display: inline-block;
overflow: hidden;
background-color: #f1f1f1;
overflow: auto;
width: 250px;
height: auto;
max-height: 600px;
padding: 22px;
margin: 15px;
position: relative;
word-wrap: break-word;
}
.profile_info {
text-decoration: none;
color: Black;
cursor: pointer;
}
input.profile_info:focus {
color: Red;
}
input.profile_info:focus ~ .image_change {
display: block;
}
.image_change {
display: none;
position: relative;
height: 200px;
width: 200px;
background-color: Blue;
}
It sort of works if the "image_change" div is in the "scrollbar" div, but if you click away then it disappears.
Thanks!
Since selecting a parent element with CSS is not possible obviously its also not possible to select it's adjacent one....i would suggest the following approach using javascipt :
var image = document.getElementsByClassName('image_change')[0]
var input = document.querySelector('input')
input.addEventListener('click',function(e){
if(image.style.display == '') {
image.style.display = 'block'
} else {
image.style.display = ''
}
})
div.scrollbar {
display: inline-block;
overflow: hidden;
background-color: #f1f1f1;
overflow: auto;
width: 250px;
height: auto;
max-height: 600px;
padding: 22px;
margin: 15px;
position: relative;
word-wrap: break-word;
}
.profile_info {
text-decoration: none;
color: Black;
cursor: pointer;
}
input.profile_info:checked {
color: Red;
}
.image_change {
position: relative;
display : none;
height: 200px;
width: 200px;
background-color: Blue;
}
<div>
<div class="scrollbar">
<input type="checkbox" class="profile_info">Profile Picture
</div>
<div class="image_change">
This is a Blue div
</div>
</div>
Related
[![How to restrict the autocomplete div tags height without affecting the bottom fields.
Here when i'm searching for country references dropdown is showing, but the entire height is increasing.
here the dropdown is fall over the communication field. How to achieve this. Please find the PIC for better understanding Thanks.`
Country Reference
<div class="form-group right">
<label for="Communication_Type" class="label-title">Communication Type</label>
<div class="autocomplete1">
<input type="text" class="" id="empid1" name="empid1">
<div class="dialog1">
<ul id="charactersList1"></ul>
</div>
</div>
</div>
.cref_container {
background-color: yellow;
}
.label_cref {
display: inline-block;
margin-left: 25px;
padding: 5px;
width: 30%;
margin-top: 2px;
background-color: royalblue;
}
.autocomplete {
/* background: #fff; */
position: relative;
}
.autocomplete .close {
position: absolute;
font-size: 13px;
z-index: 10;
top: 10px;
left: calc(100% - 50px);
color: #aaa;
cursor: pointer;
display: none;
}
.autocomplete .close.visible {
display: block;
}
.dialog {
width: 60%;
margin-left: 40%;
display: none;
min-height: 40px;
max-height: 330px;
overflow: scroll;
border-top: 1px solid #f4f4f4;
}
.dialog.open {
display: block;
}
.dialog div {
padding: 20px 10px;
font-size: 13px;
cursor: pointer;
transition: all 0.2s;
}
.dialog div:hover {
background: #f2f2f2;
}`]1]1
You have two options:
either use a native "select" input component which already does that (see https://www.w3schools.com/tags/tag_select.asp)
set your "dialog1"'s position to "fixed" and set its "left" and "top" from javascript. "fixed" position takes it out of the normal layout and doesn't push around any other elements.
const leftCoordinate = 20;
const topCoordinate = 100;
document.getElementsByClassName("dialog1")[0].style.left = leftCoordinate;
document.getElementsByClassName("dialog1")[0].style.top = topCoordinate;
.dialog1 {
position: fixed;
}
I have three divs. I want them to be in one line so I used inline-block. When I resize the window the third element (nav) stacks and then the 2nd element (searchBar). I want the 2nd element stacks first and then the 3rd one. For undoing, the 3rd element and then the 2nd element.
body {
margin: 0px;
padding: 0px;
}
header {
width: 100%;
min-eight: 48px;
position: fixed;
background: #ffffff;
padding-bottom: 5px;
border-bottom: 2px solid #fed700;
}
nav {
width: 489.7px;
height: 18px;
background: red;
display: inline-block;
}
#searchBar {
width: 330px;
height: 16px;
background: blue;
display: inline-block;
white-space: nowrap;
}
#logo {
width: 220px;
height: 32px;
background: green;
display: inline-block;
}
<header>
<div id=logo>logo
</div>
<div id=searchBar>searchBar
</div>
<nav>nav
</nav>
</header>
You could use an inline-block wrapper with a min-width, wrapping the nav and searchBar. That would give the result you wanted in with the code sample supplied, but might cause problems in the real world, depending on your requirements.
body {
margin: 0px;
padding: 0px;
}
header {
width: 100%;
min-height: 48px;
position: fixed;
background: #ffffff;
padding-bottom: 5px;
border-bottom: 2px solid #fed700;
}
.wrapper {
min-width: 50%;
display: inline-block;
}
nav {
width: 489.7px;
height: 18px;
background: red;
display: inline-block;
}
#searchBar {
width: 330px;
height: 16px;
background: blue;
display: inline-block;
white-space: nowrap;
}
#logo {
width: 220px;
height: 32px;
background: green;
display: inline-block;
}
<header>
<div id=logo>logo
</div>
<div class="wrapper">
<div id=searchBar>searchBar
</div>
<nav>nav
</nav>
</div>
</header>
I have a div where I inputted a picture and I "Position: absolute" another div that when clicked will bring you down to the bottom of the page. But when you zoom out, it stays in place but, when you zoom out it moves down and out of the picture div. I am asking, how do i keep my content centered and in position when zooming in and out of your browser. I searched all over stack and other websites but can't find a solution.
HTML
#pic-div {
width: 100%;
height: 700px;
margin: 0 auto;
overflow: hidden;
}
#pic-button {
width: 100px;
height: 100px;
margin: 0 auto;
}
#down-button {
max-width: 200px;
max-height: 200px;
background-color: black;
border-style: none;
color: white;
font-family: 'Coiny', cursive;
position: absolute;
cursor: pointer;
margin: 0 auto;
margin-top: 500px;
}
#down-button:hover {
background-color: grey;
}
<div id="pic-div">
<div id="welcome-pic"> <img id="pic-welcome" src="luxpics/logobar.jpg">
<div id="pic-button">
<button id="down-button">LET'S START</button>
</div>
</div>
</div
Try this
#down-button {
max-width: 200px;
max-height: 200px;
background-color: black;
border-style: none;
color: white;
font-family: 'Coiny', cursive;
position: absolute;
cursor: pointer;
margin: 0 auto;
bottom: 25px;
//margin-top: 500px;
}
Can you try using position: fixed instead of using absolute?
I am trying to make a file hierarchy in html/css and I can't get these labels or the divs they are in to expand to full width. They only expand to the width of the visible area but I want the width of what they are in. Here is the fiddle to see what I am talking about. The grey area needs to all line up on the right.
a = 3;
html,
body {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
}
div.hierarchy {
position: relative;
overflow: auto;
border-right: 1px solid grey;
width: 150px;
left: 0;
top: 0;
bottom: 0;
height: 100%;
}
div.hierarchy label {
display: block;
min-width: 100%;
background: #eee;
white-space: nowrap;
}
div.directory {
padding-left: 20px;
width: 100%;
}
div.directory label {
border: 1px solid grey;
width: 100%;
cursor: pointer;
}
<div class="hierarchy">
<label>Hierarchy</label>
<div class="directory">
<label>src</label>
<div class="directory">
<div class="file"><label>test.txt</label></div>
<div class="file"><label>readme.txt</label></div>
<div class="file"><label>a really long filename.txt</label></div>
</div>
</div>
</div>
You need to change your div.directory CSS class as follows:
div.directory {
display:inline-block;
padding-left: 20px;
}
I made the following changes:
1) Added display:inline-block;
2) Removed the width:100%; rule.
Here is an example:
http://jsfiddle.net/nnd7jyj1/
(As a side note, it's generally bad practice in CSS to apply both a width and either a padding or margin rule to the same element. The reason for this is that some browsers interpret the width to include the padding/margin and some don't, which leads to inconsistent results)
Simply add display:inline-block; to div.directory
html,
body {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
}
div.hierarchy {
position: relative;
overflow: auto;
border-right: 1px solid grey;
width: 150px;
left: 0;
top: 0;
bottom: 0;
height: 100%;
}
div.hierarchy label {
display: block;
min-width: 100%;
background: #eee;
white-space: nowrap;
}
div.directory {
padding-left: 20px;
/* width: 100%; */
/* added */
display: inline-block;
}
div.directory label {
border: 1px solid grey;
width: 100%;
cursor: pointer;
}
<div class="hierarchy">
<label>Hierarchy</label>
<div class="directory">
<label>src</label>
<div class="directory">
<div class="file">
<label>test.txt</label>
</div>
<div class="file">
<label>readme.txt</label>
</div>
<div class="file">
<label>a really long filename.txt</label>
</div>
</div>
</div>
</div>
Before you roll your eyes and move on, I know how to solve this problem by using a fixed height and absolution positioning with top: and bottom:, but I want to solve it without using fixed heights. I want to learn more about CSS so I'm trying to solve this a different way.
I have set up a typical navbar running across the top, and then a scrolling content div below.
However! How do I fit the bottom scrolling div container to the remaining space without using absolute coordinates? I can't do position: absolute, because then I'd need to know the height of the navbar to set "top:". And I can't do "bottom: 0" because I'd have to specify a height.
Here's the JS filddle:
http://jsfiddle.net/8dugffz4/1/
The class of interest is ".result". I currently have the height fixed, which I don't want.
Thanks, y'all.
PT
CSS:
* {
font-family: Helvetica, Sans;
border: 0px;
margin: 0px;
padding: 0px;
}
.navBar {
width: auto;
overflow: auto;
border-bottom: 1px solid #bbb;
}
.pageBar {
float: right;
}
.pager {
cursor: pointer;
float: left;
border: 1px solid #bbb;
width: 2em;
height: 2em;
line-height: 2em;
text-align: center;
margin: 5px;
margin-left: 0px;
background: #eee;
color: #bbb;
}
.pager:hover {
background: #777;
border: 1px solid black;
color: white;
}
.fliph {
-ms-transform:scale(-1,1); /* IE 9 */
-moz-transform:scale(-1,1); /* Firefox */
-webkit-transform:scale(-1,1); /* Safari and Chrome */
-o-transform:scale(-1,1); /* Opera */
}
.results {
background: gray;
width: 100%;
height: 200px;
overflow: scroll;
}
.line {
height: 10em;
line-height: 10em;
border: 1px solid red;
}
HTML:
<body>
<div class='navBar'>
<div class='pageBar'>
<div class='pager'>◁</div>
<div class='pager'>1</div>
<div class='pager fliph'>◁</div>
</div>
</div>
<div class='results'>
<div class='line'>Line1</div>
<div class='line'>Line2</div>
<div class='line'>Line3</div>
<div class='line'>Line4</div>
</div>
</body>
Here's a solution that uses display: table and can actually achieve fluid heights:
http://jsfiddle.net/8dugffz4/8/
And a minimalistic snippet in case you want to see specifically what I did:
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
}
#table {
display: table;
height: 100%;
width: 100%;
}
#table > div {
display: table-row;
}
#navbar {
height: 45px;
opacity: .5;
}
#navbar > div {
height: 100%;
background: black;
}
#results {
height: 100%;
}
#results > div {
height: 100%;
overflow: auto;
background: green;
}
<div id="table">
<div id="navbar">
<div></div>
</div>
<div id="results">
<div></div>
</div>
</div>
If you're just looking for an alternative to the position: absolute method, you could use the height: 100% method:
html, body { height: 100%; }
body { box-sizing: border-box; padding-top: 45px; }
.navBar { height: 45px; margin-top: -45px; }
.results { height: 100%; }
Like so: http://jsfiddle.net/8dugffz4/7/