How to hide and show a table-row (css-tables) - html

I'm trying to hide and show a table row using css-tables and pure JavaScript (No jQuery).
I've got a div with the display set to table-row and a nav inside of it. No matter what I do, border-collapse etc, the div still maintains some of it's height.
Any ideas?
HTML:
<!-- Header -->
<header id='header'> <!-- Table Row 1 -->
<div id="header-table">
<div id='back'>
<button id='back-button'>←</button>
</div>
<div id="title">
<h1 id='title-h1'>Title</h1>
</div>
<div id="menu">
<button id='menu-button'>≡</button>
</div>
</div>
</header>
<nav id="menu-nav">
Introductory Page
Activity List
Settings
About
</nav>
<div id="body"> <!-- Table Row 3 -->
<div id="wrapper">
CSS
header#header {
position: relative;
display: table-row;
}
div#menu-nav-cell {
position: relative;
display: table-row;
text-align: center;
overflow: hidden;
background: yellow;
}
nav#menu-nav {
display: table-row;
height: 0em;
width: 100%;
color: #000;
background: pink;
}
div#body {
position: relative;
display: table-row;
height: 100%;
}
div#wrapper {
position: relative;
height: 100%;
}

Why not simply using display: none?
Maybe I misunderstood, since you said you have a div with a nav inside, but I cannot see that in your html sample.
I think you want to show/hide the navigation. This can be done by adding this css rule:
nav#menu-nav.hidden {
display: none;
}
and javascript
document.getElementById("toggle").onclick = function () {
document.getElementById("menu-nav").classList.toggle("hidden");
}
jsFiddle
If you want to animate the height, you can do this:
/* new rules that I added */
nav#menu-nav {
line-height: 1em;
-webkit-transition: line-height .2s, background-color .2s;
}
nav#menu-nav a {
display: inline-block;
overflow: hidden;
height: 1em;
-webkit-transition: height .2s;
}
nav#menu-nav.hidden {
line-height: 0em;
background-color: transparent;
}
nav#menu-nav.hidden a {
height: 0;
}
The trick is to use overflow: hidden; display:inline-block for the table cells, instead of display:table-cell.
This way, changing the height and line-height to zero works fine.
However there is still some height (around 3px) still visible, so I decided to animate the background-color to transparent as well. If you comment that part that animates the background color, you will understand what I mean.
jsFiddle v2

Related

HTML css - width of element than 100% width

I am trying to append a tooltip to a list/div block of elements - but these elements are set at 100% width. I'd like to have it so the tool tip is only appearing a few px away from the last word in the list/sentence.
Doing it html + css only, you need to wrap each line in a div, like
.gray-container {
display: flex;
flex-direction: column;
width: 100%;
background: red;
}
.line {
display: inline-block;
position: relative;
}
.tooltip {
display: inline-block;
position: absolute;
background: black;
width: 30px;
height: 20px;
margin-left: 10px;
}
<div class="gray-container">
<div class="line"><input type="radio">None<div class="tooltip"></div></div>
<div class="line"><input type="radio">Two</div>
<div class="line"><input type="radio">Three</div>
<div class="line"><input type="radio">Four</div>
</div>
Now for demo purposes and because i don't have any idea of the methods you're using to create the tooltips since you didn't post your code i'm using a div with class="tooltip", but this solves your question of the div being 100%.

Reposition div left of another div rather than below

I am attempting to tile a webpage with div elements of various sizes. However, I am running into an issue with once x number of div elements have filled the width of the screen the following div is placed below the previous 'row', rather than being floated to fit into space between elements in the previous 'row'. The code below better demonstrates what I mean; I'd like the 'game' div to be floated to fit into the space above where it is currently positioned.
h1 {
color: white;
}
.center {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
.container {
display: inline-block;
}
.default {
margin: 1em;
float: left;
}
/* For hover text */
.hover_img {
width: 100%;
height: 100%;
position: relative;
float: left;
}
.hover_img h4 {
color: white;
}
.hover_img:hover img {
opacity: .2;
}
.hover_img:hover .center_text {
display: block;
}
.center_text {
position: absolute;
top: 50%;
left: 0;
display: none;
font-weight: bold;
text-align: center;
}
img {
margin: 0;
}
.rectangle-tile-horizontal {
height: 15em;
width: 35em;
}
.red {
background-color: rgba(255, 63, 63, 0.8);
}
#game, #game img {
width: 30em;
height: 30em;
}
#app, #app img {
width: 40em;
height: 35em;
}
<div class="container">
<div class="rectangle-tile-horizontal red center default">
<h1><b>Projects</b></h1>
</div>
<div class="rectangle-tile-horizontal hover_img default" id="app">
<img src="http://cohenwoodworking.com/wp-content/uploads/2016/09/image-placeholder-500x500.jpg">
<div class="center_text"><h4>Web App</h4></div>
</div>
<div class="hover_img default" id="game">
<img src="http://cohenwoodworking.com/wp-content/uploads/2016/09/image-placeholder-500x500.jpg">
<div class="center_text"><h4>Breakout</h4> </div>
</div>
I'm afraid what you want to do is actually re-order your divs to create a space-filling layout. To the best of my knowledge, using only CSS for this is difficult, if not outright impossible.
I suggest you take a look at this SO post, or perhaps even the Bulma framework is what you want.
If, however, you move away from re-ordering the containers automagically and instead look towards a solution that elastically adapts the width of each container to fill the available space while maintaining its "order" (first, second, third), I am sure CSS will be a viable solution. If you require assistance, please use the search or ask anew.
Create a style for your div class or id like
.className
{display:inline;}
and use it in your each div
Hope this will help you
An example of this
http://jsfiddle.net/JDERf/

DIV with max-height not expanding

I've made a drop-down list which attaches to a text input, and the list which appears beneath has a header and footer row, and scrolling content in between. JS fiddle here:
https://jsfiddle.net/tpgjjh81/3/
It works great, except I'd like the drop-down to have a flexible height, depending on its content, up to a specified max-height. However, if I change:
DIV.dropdown {
...
height: 100px;
...
}
to:
DIV.dropdown {
...
max-height: 100px;
...
}
...then the "content" part of the list doesn't show at all when the drop-down appears, only the header and footer rows. The DIV's within have height: 100% so I would have thought these would push the outer DIV to its max-height but it doesn't appear to be working?
edit: I've also tried adding height: auto alongside the max-height but it doesn't have any effect.
See this fiddle here: https://jsfiddle.net/tpgjjh81/22/
The main issue was to do with the DIV.scroll_inner having absolute positioning with 0 edges (to fill the scroll_outer container).
Let the outer container control its own content, and limit the inner content's height to max-height: 100px.
Essentially, what you are looking for is something like this:
DIV.wrapper {
display: inline-block;
position: relative;
}
DIV.dropdown {
display: none;
position: absolute;
clear: left;
left: 0;
right: 0;
border: 1px solid black;
}
DIV.list_container {
display: table;
width: 100%;
height: 100%;
}
DIV.header,DIV.footer {
display: table-row;
background-color: lightgray;
}
DIV.scroll_outer {
display: table-row;
height: auto;
background-color: white;
}
DIV.scroll_inner {
overflow: auto;
max-height: 100px;
}
EDIT I've also removed some now unnecessary properties from the CSS, and updated this above, and in the fiddle. This should at least get you off the ground.
Best of luck in your project! :)
I cleaned up your css. Not sure why you were using display table and setting up the height etc. Just hide the parent overflow and set child overflow to scroll and that should do it.
Also I moved the border to outer container so it is not cut off.
is_visible = false;
function Toggle() {
is_visible = !is_visible;
document.getElementById("dropdown").style.display = (is_visible ? "block" : "none");
}
DIV.wrapper {
display: inline-block;
position: relative;
}
DIV.dropdown {
display: none;
position: absolute;
clear: left;
left: 0;
right: 0;
height: 100px;
border-bottom: 1px solid black;
overflow: scroll;
}
DIV.list_container {
display: block;
border: 1px solid black;
border-bottom: 0px;
}
DIV.header,DIV.footer {
display: block;
background-color: lightgray;
}
DIV.scroll_outer {
display: block;
position: relative;
background-color: white;
}
DIV.scroll_inner {
overflow: hidden;
}
<div class="wrapper">
<input type="text" size="50" value="Click me" onclick="Toggle()" />
<div class="dropdown" id="dropdown">
<div class="list_container">
<div class="header">Header</div>
<div class="scroll_outer">
<div class="scroll_inner">
Item 1<br />
Item 2<br />
Item 3<br />
Item 4<br />
Item 5<br />
Item 6<br />
Item 7
</div>
</div>
<div class="footer">Footer</div>
</div>
</div>
</div>
height: auto;
max-height: 100px;
overflow: auto;

Content beyond the screen is not displayed?

I am doing something wrong here but what is it I am not being able to figure out. Is something wrong with my code? Whenever I try to make the screen size smaller the content must be fixed up to a certain width but it's adjusting itself and nothing is displayed beyond it. And here is the jsFiddle with the image of what is wrong below.
HTML
<div class="sitefeed">
<!-- this is the start of site -->
<header>
<div class="wrap head-rel">
<ul class="nav">
<li>Home
</li>
<li>Contact
</li>
<li>Services
</li>
</ul>
<ul class="logo">
<h1>Naveen Niraula</h1>
</ul>
</div>
</header>
<div id="main">
<article>
<div class="wrap">
<h1>This</h1>
<p>My dear has kinda some typo somewhere.</p>
</div>
</article>
</div>
<!-- and here is the end -->
</div>
CSS
* {
margin: 0;
padding: 0;
font-family: consolas;
}
html {
height: 100%;
overflow: hidden;
}
body {
width: 100%;
height: 100%;
overflow: auto;
}
.sitefeed {
display: table;
table-layout: fixed;
width: 100%;
height: 100%;
}
.wrap {
max-width: 901px;
min-width: 900px;
margin: auto;
padding: 0 5px;
}
/* ------------- header here ------------------- */
header ::-moz-selection {
color: #6cccf2;
}
header ::selection {
color: #6cccf2;
}
.head-rel {
position: relative;
}
header {
background: #3b5998;
color: #fff;
}
/* ----------- navigation goes right here ---------------- */
.nav {
list-style-type: none;
position: absolute;
bottom: 0;
right: 0;
}
.nav li {
display: inline-block;
}
.nav li a {
text-decoration: none;
color: #fff;
padding: 10px;
display: block;
}
.nav li:hover {
background: #000;
}
.nav li a:hover {
color: #fff;
}
/* ------------------------ main content goes here ------------------------ */
#main ::-moz-selection {
color: #a0249c;
}
#main ::selection {
color: #a0249c;
}
#main {
background: #e1e1e1;
}
I want it to display the whole content even when the viewport is small but if the viewport exceeds the webpage I want the background color to measure up to fill that space(left and right). Like the image below . But when I remove the width from .sitefeed it's not possible.
Solved.
It seems like table-layout:fixed; was causing the problem but now I fixed it!
Try taking the overflow:hidden out of your HTML style.
In this case when you work with the fixed width, just add this with to header and #main, which are both parents of .wrap with fixed width.
header, #main {width: 900px;}
http://jsfiddle.net/cj9pvz5o/
If I understand your question right, you don't want the following code:
.sitefeed { width: 100% }
If you remove this width, you get the background over the whole layout no matter if its outside of the viewport or not. Block elements (display: block) will always take as much width as they can, if not used in conjunction with float. I guess they same is true for display: table. This will take only 100% of the viewport and thus cut the background color at the point where the other content overflows.
Here is an updated jsFiddle: https://jsfiddle.net/nkwxw9gj/3/ Do you wanted to achieve this?
Note: the reason why it overflows from the viewport is your use of min-width: 900px within .wrap-rule. Change that in case you don't want to overflow for reasonable resolutions.

CSS trouble getting hover state to behave on simple div

Here’s a tricky one…
I have a div, the contents of which should change on hove over on any part of it.
Here’s a pic detailing both wanted states:
And here is best effort, so far:
codepen
..it needs a bit of work.
Any help much appreciated!
Here's the HTML so far:
<div class="item green">
<a href="#">
<h4>Welcome</h4>
<p>Click here to find out more</p>
<img src="http://www.veropixel.com/res01-170w115h.jpg"/>
</a>
</div> <!-- /item -->
So there's my solution http://codepen.io/anon/pen/mIrvA :
$resinGreen: #00a14a;
.green { background: $resinGreen; }
.item {
width: 300px;
margin-bottom: 5px;
a {
display: block;
height: 98px;
overflow: hidden; /* cancels img float */
text-decoration: none;
h4, p {
height: 98px;
line-height: 98px; /* Two lines added to center
vertically text of course you can use display:inline-block
with vertical-align:middle */
padding-left: 15px;
margin:0;
}
img {
float: right;
height: 98px;
}
p {
display: none;
}
&:hover {
h4, img { display: none; }
p { display: block; }
}
}
}
Your problem was that your link haven't a height so it's why it was blinking, i also moved img to the first place for floating
If using just images within the div this bit of jquery will do it:
$('#applyimg').hover(function(){
$(this).attr('src','/design/sendcv_over.png');
},function(){
$(this).attr('src','/design/sendcv.png');
});
HTML
<img id='applyimg' src='/design/sendcv.png'>
Mouseover the image will swop it's source