Height in % = 0, if position is static or relative - css

I'm facing an issue whenever I set the height of .task in % then it's height becomes 0. But at the same time if I will change position to absolute or fixed... it's working fine... why?
* {
font-family: monospace;
padding: 0;
margin: 0;
}
section{
margin-top: 8vh;
min-height: 87vh;
width:100%;
position: relative;
background-color: white;
}
section>.app{
width: calc(100% - 22vh);
min-height: inherit;
background-color: inherit;
left: 11vh;
position: relative;
padding-top: 5vh;
box-sizing: border-box;
}
section>.app>input[type="search"]{
width: 100%;
font-size: 200%;
outline: none;
position: relative;
height: 7vh;
border: none;
border-bottom: 0.5vh solid white;
color: deepskyblue;
background-color: deepskyblue;
box-sizing: border-box;
padding-right: 0.25em;
padding-left: 0.25em;
}
section>.app>input[type="search"]:valid{
background-color: white;
color: deepskyblue;
border-bottom-color: deepskyblue;
}
section>.app>input[type="search"]::-webkit-input-placeholder{
color: white;
}
section>.app>input[type="search"]::-moz-placeholder{
color: white;
}
section>.app>input[type="search"]:-ms-input-placeholde {
color: white;
}
section>.app>input[type="search"]::placeholde {
color: white;
}
section>.app>input[type="search"]:focus{
border-bottom-color: deepskyblue;
background-color: inherit;
}
section>.app>input[type="search"]:focus::-webkit-input-placeholder{
color: transparent;
}
section>.app>input[type="search"]:focus::-moz-placeholder{
color: transparent;
}
section>.app > input[type="search"]:focus:-ms-input-placeholder {
color: transparent;
}
section>.app>input[type="search"]:focus::placeholder{
color: transparent;
}
section>.app>div.tasks{
background-color: black;
position: relative;
margin-top: 5vh;
width: 100%;
min-height: 70vh;
}
section>.app>div.tasks>.task {
height: 10%;
width: 50%;
position: relative;
background-color: white;
}
<section>
<div class="app">
<input type="search" placeholder="Search For Task List..." spellcheck="false" required="required"/>
<div class="tasks">
<div class="task"></div>
</div>
</div>
</section>
I can't set the position: absolute; as parent element's height will no longer be relative to it's child.
You can also check out the full project here at codepen:
Project at codepen
As the styling causing this problem, if removed will cause a problem in my project.... if so plz suggest an alternative.

If I understand correctly, you are asking why it is that the height = 0 when you explicitly initiated that property as height: 10%; for the .task class. This is because the position: relative; property doesn't take elements out of the flow of things. When you use position: absolute; for example, it does take that element out of the flow of things and it would then make it have a different height.

Related

Text input - can't align text top or bottom, only center

folks! I'm trying to align the text inside a text form input to be next to the line at the bottom, but it doesn't quite concede, insisting on being center aligned.
I've put some vertical-align: bottom on different elements, but it didn't work (it's on the code below).
Here is the codepen: https://codepen.io/ironsand-sou-eu/pen/zYEmEdw
HTML:
<div class="form-input field">
<input type="text" name="my_input" id="my_input" value="I'd love to be a little closer to the line below! Can you help me?">
<label for="my_input" data-title="Just some label"></label>
</div>
CSS:
.form-input {
width: 100%;
background-color: transparent;
border-bottom: 1px green solid;
border-top: none;
border-right: none;
border-left: none;
}
.form-input::before {
content: '';
position: absolute;
background-color: green;
left: 0;
bottom: 0;
width: 0;
height: 2px;
transition: ease-out 300ms;
}
.form-input:hover::before {
width: 100%;
}
.form-input:focus-within::before {
width: 100%;
}
.form-input input {
border: none;
width: 100%;
}
.form-input input:focus-visible {
outline: none;
}
.field {
position: relative;
margin-bottom: 15px;
vertical-align: bottom;
}
.field label::before {
content: attr(title);
position: absolute;
top: 0;
left: 15px;
line-height: 40px;
font-size: 14px;
color: #777;
transition: 300ms all;
}
.field input {
width: 100%;
line-height: 40px;
padding: 0 8px;
box-sizing: border-box;
font-size: 14px;
color: green;
vertical-align: bottom;
}
Place this at the bottom of the CSS section:
input[type=text] {
height: 15px;
}

Button not laid out against top of relatively positioned container in Firefox

I'm building a toggle switch and the head (button) isn't positioned all the way to the top as I'd expect it to be in Firefox. Works fine in Chrome, so maybe has something to do with default browser styles?
Edit: I know how to make it work, I want to know why it happens.
codepen https://codepen.io/warhammered_cat/pen/qBZYZVy
const toggleSwitch = document.querySelector('.toggle-switch')
const toggleSwitchHead = document.querySelector('.head')
function handleToggle(e) {
toggleSwitch.classList.toggle('active')
}
toggleSwitchHead.addEventListener('click', handleToggle)
* {
box-sizing: border-box;
}
document, body {
margin: 0;
padding: 0;
}
.head {
width: 1.25rem;
height: 1.25rem;
border: 0.125rem solid gray;
border-radius: 50%;
background-color: white;
cursor: pointer;
transition: all 0.4s;
outline: none;
box-shadow: none;
}
.rail {
height: 0.75rem;
width: 100%;
background-color: gray;
border: 0.125rem solid gray;
position: absolute;
top: 0.25rem;
z-index: -1;
border-radius: 0.3rem;
transition: all 0.4s;
}
.toggle-switch {
position: relative;
height: 1.25rem;
width: 2rem;
}
.toggle-switch.active > .head {
background-color: #F7941E;
border-color: #F7841E;
transform: translateX(1rem);
}
.toggle-switch.active > .rail {
border: 0.125rem solid #F7941E;
background-color: white;
}
<div class='toggle-switch'>
<button class='head'></button>
<div class='rail'></div>
</div>
The <button> element is what is specifically being rendered differently in Firefox and Chrome.
If you change the <button> to a <div> the problem fixes itself.
The reason is that the button element is not a block element by default. You have to explicitly set the button to be a block element to get the desired behavior.
.head {
...
display: block;
...
}
try this instead,
Add display:inline-flex; to head class
.head{
display:inline-flex;
}
Click below to see codepen demo
Result :
const toggleSwitch = document.querySelector('.toggle-switch')
const toggleSwitchHead = document.querySelector('.head')
function handleToggle(e) {
toggleSwitch.classList.toggle('active')
}
toggleSwitchHead.addEventListener('click', handleToggle)
* {
box-sizing: border-box;
}
document, body {
margin: 0;
padding: 0;
}
.head {
width: 1.25rem;
height: 1.25rem;
border: 0.125rem solid gray;
border-radius: 50%;
background-color: white;
cursor: pointer;
transition: all 0.4s;
outline: none;
box-shadow: none;
display:inline-flex;
}
.rail {
height: 0.75rem;
width: 100%;
background-color: gray;
border: 0.125rem solid gray;
position: absolute;
top: 0.25rem;
z-index: -1;
border-radius: 0.3rem;
transition: all 0.4s;
}
.toggle-switch {
position: relative;
height: 1.25rem;
width: 2rem;
}
.toggle-switch.active > .head {
background-color: #F7941E;
border-color: #F7841E;
transform: translateX(1rem);
}
.toggle-switch.active > .rail {
border: 0.125rem solid #F7941E;
background-color: white;
}
<div class='toggle-switch'>
<button class='head'></button>
<div class='rail'></div>
</div>

Trouble Getting Tooltip Width Correct Using CSS

I've looked at various solutions to this and can't seem to get anything to work. I hope I'm missing something simple. What I want is for a tooltip width to use only what is needed, then wrap when a max-width is reached.
Here's my CSS:
<style>
.tooltip {
position: relative;
display: inline-block;
width: 20px;
height: 20px;
background-color: steelblue;
color: yellow;
border: solid;
border-width: 1px;
border-radius: 50%;
text-align: center;
cursor: help;
}
.tooltip:before {
content: '?';
}
.tooltip .tooltiptext {
visibility: hidden;
position: absolute;
display: inline-block;
max-width: 300px;
background-color: black;
color: #fff;
text-align: left;
border-radius: 6px;
z-index: 10;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
</style>
And here's my HTML:
<div class="tooltip">
<div class="tooltiptext">
I want this to wrap only after 300 pixels.
</div>
</div>
Blacklist
What happens is it always wraps to fit only the widest word, making the max-width setting meaningless. Any assistance would be appreciated.
The problem is that you're trying to cram the tooltip inside a container with 20px width. It simply doesn't have any wiggle room!
For a solution, move the .tooltiptext out of the .tooltip. The CSS can mostly stay the same.
.tooltip {
position: relative;
display: inline-block;
width: 20px;
height: 20px;
background-color: steelblue;
color: yellow;
border: solid;
border-width: 1px;
border-radius: 50%;
text-align: center;
cursor: help;
overflow:visible;
}
.tooltip:before {
content: '?';
}
.tooltip + .tooltiptext {
visibility: hidden;
position: absolute;
display: inline-block;
max-width: 300px;
background-color: black;
color: #fff;
text-align: left;
border-radius: 6px;
z-index: 10;
}
.tooltip:hover + .tooltiptext {
visibility: visible;
}
<div class="tooltip">
</div>
<div class="tooltiptext">
I want this to wrap only after 300 pixels.
</div>
Blacklist
You need to explicitly set a min-width as well:
.tooltip .tooltiptext {
visibility: hidden;
position: absolute;
display: inline-block;
min-width: 100px;
max-width: 300px;
background-color: black;
color: #fff;
text-align: left;
border-radius: 6px;
z-index: 10;
}
https://jsfiddle.net/gdL458jo/

How to position a text inside a rotated div box

Like this
Should be centered too.
.diamond {
display: block;
height: 30px;
width: 30px;
background-color: white;
border: 2px solid #dcdcdc;
transform: rotate(45deg);}
Rotate the content back the other way.
* {
margin: 0;
padding: 0;
}
.diamond {
display: block;
height: 30px;
width: 30px;
background-color: white;
border: 2px solid #dcdcdc;
transform: rotate(45deg);
text-align: center;
line-height: 30px;
margin: 25px;
}
.diamond p {
transform: rotate(-45deg);
}
<div class="diamond">
<p>Hi</p>
</div>
I would use a pseudo element for this.
Then i only need to apply one rotation.
That rotation is only on a single element.
.mid-angle {
color: black;
width: 50px;
height: 50px;
text-align: center;
line-height: 50px;
}
.mid-angle:before {
content: " ";
display: block;
position: absolute;
width: 50px;
height: 50px;
box-sizing: border-box;
border: 2px solid pink;
transform: rotate(45deg);
}
<div class="mid-angle">Hello</div>

How can I make my css :hover work?

Bellow is my css i'm using. The div with the largebutton class on it works with the exception of the hover. I would like it to change it's background color, but am not sure why its not working. Any ideas?
edit - I'm working in FF at the moment. I'm not looking for support in IE6, possibly not IE7 either.
.top .bottombar .largebutton
{
position: relative;
float: left;
height: 100%;
width: 195px;
font-size: 13px;
letter-spacing: 1px;
text-transform:uppercase;
line-height: 33px;
text-align: right;
background-color: #99CCFF;
margin-left: 5px;
padding-right: 5px;
overflow: hidden;
cursor: pointer;
}
.top .bottombar .largebutton:hover
{
background-color: #9999FF;
}
edit - Full files
HTML
<html>
<head>
<link rel="StyleSheet" href="css/LCARS.css" type="text/css" media="screen">
</head>
<body>
<div class="top">
<div class="content">
</div>
<div class="leftbuttonbox">
<div class="button">
Label
</div>
<div class="largebutton">
Label
</div>
<div class="button">
Label
</div>
</div>
<div class="bottombar">
<div class="button">
Label
</div>
<div class="largebutton">
Label
</div>
<div class="button">
Label
</div>
<div class="label">
This is a label, it grows as large as it needs to
</div>
</div>
<div class="cap">
<div class="capinner">
</div>
</div>
</div>
</body>
</html>
CSS
#font-face {
font-family: "LCARS";
src: url('../FONT/lcars.ttf');
}
body
{
font-family: "LCARS";
position: relative;
background-color: black;
padding: 0px;
margin: 0px;
}
.top
{
position: relative;
height: 220px;
min-width: 100px;
margin-top: 5px;
margin-left: 5px;
margin-right: 5px;
background-color: #6666FF;
-moz-border-radius-bottomleft: 50px;
}
.top .content
{
position: absolute;
top: 0px;
right: 0px;
left: 100px;
bottom: 25px;
background-color: black;
-moz-border-radius-bottomleft: 25px;
}
.top .leftbuttonbox
{
position: absolute;
top: 0px;
left: 0px;
width: 100px;
bottom: 60px;
background-color: black;
overflow: hidden;
}
/*
* the button is 1/2 the size of the large button
* the button box can hold 4 buttons or 2 large
* buttons or any combination of equal size
*/
.top .leftbuttonbox .button
{
position: relative;
height: 35px;
width: 95px;
font-size: 13px;
letter-spacing: 1px;
text-transform:uppercase;
line-height: 53px;
text-align: right;
background-color: #99CCFF;
margin-bottom: 5px;
padding-right: 5px;
overflow: hidden;
cursor: pointer;
}
.top .leftbuttonbox .button:hover
{
background-color: #9999FF;
}
.top .leftbuttonbox .largebutton
{
position: relative;
height: 75px;
width: 95px;
font-size: 13px;
letter-spacing: 1px;
text-transform:uppercase;
line-height: 133px;
text-align: right;
background-color: #99CCFF;
margin-bottom: 5px;
padding-right: 5px;
overflow: hidden;
cursor: pointer;
}
.top .leftbuttonbox .largebutton:hover
{
background-color: #9999FF;
}
.top .bottombar
{
position: absolute;
bottom: 0px;
height: 25px;
left: 200px;
padding-right: 5px;
background-color: black;
overflow: hidden;
}
.top .bottombar .button
{
position: relative;
float: left;
height: 100%;
width: 95px;
font-size: 13px;
letter-spacing: 1px;
text-transform:uppercase;
line-height: 33px;
text-align: right;
background-color: #99CCFF;
margin-left: 5px;
padding-right: 5px;
overflow: hidden;
cursor: pointer;
}
.top .bottombar .button:hover
{
background-color: #9999FF;
}
.top .bottombar .largebutton
{
position: relative;
float: left;
height: 100%;
width: 195px;
font-size: 13px;
letter-spacing: 1px;
text-transform:uppercase;
line-height: 33px;
text-align: right;
background-color: #99CCFF;
margin-left: 5px;
padding-right: 5px;
overflow: hidden;
cursor: pointer;
}
.top:hover .bottombar:hover .largebutton:hover
{
background-color: #9999FF;
}
.top .bottombar .label
{
position: relative;
float: left;
height: 100%;
min-width: 50px;
font-size: 22px;
letter-spacing: 1px;
font-variant: small-caps;
padding-left: 5px;
padding-right: 5px;
background-color: #CC99CC;
margin-left: 5px;
cursor: default;
}
.top .cap
{
position: absolute;
height: 25px;
width: 20px;
right: 0px;
bottom: 0px;
padding-left: 5px;
padding-right: 5px;
background-color: black;
cursor: default;
}
.top .cap .capinner
{
position: relative;
height: 100%;
width: 100%;
background-color: #6666FF;
cursor: default;
-moz-border-radius-topright: 50%;
-moz-border-radius-bottomright: 50%;
}
div.top div.bottombar div.largebutton:hover
{
background-color: #9999FF;
}
I think it's a bug in Firefox. Sometimes, when you add CSS for nested classes without specifying what elements these are applied to, the browser goes crazy. Your code works OK in other browsers, so technically it's not your fault, but FF's ;)
I suggest this solution:
.top .largebutton:hover
{
background-color: #9999FF; /* make this whatever color it was before */
}
This worked for me when I tried it with your full code.
Hope it works for you :)
Amit
The key concept of styling a link stands toward following steps:
You have to declare styles of 4 different condition which are a:link , a:visited , a:hover , a:active .
You have to be careful about the order. Because it matters. link > visited > hover > active. (especially to have :hover and :visited work...)
Eventhough you don't need styling one or more of conditions, nevertheless, style them all.
If you pay attention to these, you may have perfectly styled links.
I hope it helps.

Resources