button is missing or outside of body - html

body{
position:relative;
width:200px;
margin:0 auto;
background:gold;
}
.btn{
position:absolute;
right:10px;
bottom:0;
background:blue;
color:white;
}
<button class='btn'>SEND</button>
why body in code snippet is not 200px?
where is btn in code snippet?
On my localhost body IS 200px and btn is there but outside of body (seams as his parent is html and not body.
Any help?

Here you are confused by a specific behavior of the background which is background propagation from body to canvas which make you thing that what you see is the whole body.
For documents whose root element is an HTML HTML element or an XHTML
html element [HTML]: if the computed value of background-image on the
root element is none and its background-color is transparent, user
agents must instead propagate the computed values of the background
properties from that element’s first HTML BODY or XHTML body child
element. ref
If you add a background color to the html element this one will get used and you will no more see the gold
html {
background: red;
}
body {
position: relative;
width: 200px;
margin: 0 auto;
background: gold;
}
.btn {
position: absolute;
right: 10px;
bottom: 0;
background: blue;
color: white;
}
<button class='btn'>SEND</button>
Now it's clear the body is not visible simply because its height is 0 since there is no in-flow element inside it as the button is position absolute. Considering this, bottom:0 is the top of you screen and you button is overflowing from the top.
Let's add some animation to see it:
html {
background: red;
}
body {
position: relative;
width: 200px;
margin: 0 auto;
background: gold;
}
.btn {
position: absolute;
right: 10px;
bottom: 0;
background: blue;
color: white;
transition:1s;
}
html:hover .btn {
bottom:-50px;
}
<button class='btn'>SEND</button>
And to make sure that your body is having a width equal to 200px and a height 0 simply add a border and you will see it. You will also notice the background propagation
body {
position: relative;
width: 200px;
margin: 0 auto;
background: gold;
border:5px solid;
padding:1px;
}
.btn {
position: absolute;
right: 10px;
bottom: 0;
background: blue;
color: white;
transition:1s;
}
body:hover .btn {
bottom:-50px;
}
<button class='btn'>SEND</button>
As you can see the body behave exactly like you want (centred with 200px width) and by adding a small padding and border we can also see that the button is placed at the bottom right.

You need to apply some of the properties to both your body and html because there is no content to apply your height: 100% to.
Try applying a border on your body to see how 'big' it is. If you do not set a height to you html at the same time, you will see that it has no height because of the lack of content.
body, html {
position: relative;
width: 200px;
height: 100%;
margin: 0 auto;
}
body {
background: gold;
}
.btn {
position: absolute;
right: 10px;
bottom: 0;
background: blue;
color: white;
}
<button class='btn'>SEND</button>

you must have to add a body height, 100% is not ok without any element in the body
try this CSS code
body{
position:relative;
width:200px;
margin:0 auto;
background:gold;
border: 1px solid #111;
height: 100px; /* this height for example */
}
.btn{
position:absolute;
right:10px;
bottom:0;
background:blue;
color:white;
}

Please try following code
body {
position:relative;
width:200px;
margin:0 auto;
background:gold;
}
.btn {
position:absolute;
right:10px;
bottom:0;
background:blue;
color:white;
top: 0;
height: 25px;
}
<button class='btn'>SEND</button>

Since you havent mentioned what end result you want. I have assumed few things and worked accordingly. Since all the absolute elements are by default related to body. The position relative to the body is not making any difference. Plus if you want a 200px width of the button container, its better to use a div here with max-width:200.Try the code below make changes accordingly. Hope it helps !!
CSS:
body{
//Removed everything
}
.btn{
position:absolute;
width:60px;height:20px;
top:50%;left:50%;
margin-top:-10px;margin-left:-30px;
background:blue;
color:white;
}
.button_holder{
position:relative;margin: 50px auto;
max-width:200px;height:100px;
background:gold;
}
Markup :
<div class="button_holder">
<button class='btn'>SEND</button>
</div>
https://codepen.io/anon/pen/MPvLqE

Related

How to create a overlapping border with different colors and widths / heights on a input element?

I am currently working on a drag and drop web app with vue.js
In this app, we have some special designed borders on an input HTML element.
The designs look like this: (ignore the grey vertical line. This is drawn dynamically)
I have tried something like creating a sibling div an make it a little bit larger than the input, set it with z-index behind the input and set a color. But the problem is that the light blue border-right and border-left will always take 100% of the height. I need something like 75% or 80%.
The "overlapping" border can also be on the top, right or left on an element
Does anyone have a clue for the best way to solve this problem responsive?
border-image with gradient is what you need:
input {
border:2px solid;
padding:10px;
background:pink;
}
.one {
border-image:linear-gradient(to right, red 80%,blue 0) 2;
}
.two {
border-image:linear-gradient(to bottom,red 70%,blue 0) 2;
}
<input type="text" class="one">
<input type="text" class="two">
You can use :after and :before for the borders that cover the remaining 20%.
<div><input value="Text"/></div>
CSS:
input {
padding:20px;
border: 5px solid lightblue;
border-bottom: 5px solid gray;
position:relative;
display:block;
}
div:before {
content:' ';
width:5px;
height: 14px;
background:gray;
position:absolute;
display:block;
bottom:0;
left:0;
z-index:999;
}
div:after {
content:' ';
width:5px;
height: 14px;
background:gray;
position:absolute;
display:block;
bottom:0;
right:0;
z-index:999;
}
div {position: relative;width:fit-content;}
See example: https://codepen.io/MistaPrime/pen/XWryOOy
I would probably style the wrapping element and add psuedo elements on it.
https://codepen.io/slackday/pen/wvwQOvq
<html>
<head>
<title>How to create a overlapping border with different colors and widths / heights on a input element?</title>
</head>
<style>
body {
margin: 0;
padding: 0;
}
.site {
height: 100vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
}
.input-wrapper {
position: relative;
}
.input-wrapper::before,
.input-wrapper::after {
height: 20%; /* adjust height of how much it should overlap */
width: 1px; /* same width as your input border */
position: absolute;
bottom: 0;
z-index: 1;
content: '';
background-color: #ccc; /** same color as bottom border */
}
.input-wrapper::before {
left: 0;
}
.input-wrapper::after {
right: 0;
}
input {
border: solid 1px aqua;
border-bottom: solid 1px #ccc;
position: relative; /* to position psuedo elements ::before, ::after */
padding: 1rem;
font-size: 16px;
line-height: 1;
}
input:focus {
outline: none;
}
</style>
<body>
<main class="site">
<div class="input-wrapper">
<input type="text" value="text" placeholder="Aorta" />
</div>
</main>
</body>
</html>

css layout not displaying correctly

I have an application which I am trying to layout. Everything is fine apart from the left column content. It should display 100% of the height of the parent container, the same height as the right column.
#Container is the outer container.
#TreeList is the left column.
#Tabcontrol is the right column.
This is what my app looks like right now:
And here is the current css for my app:
html {
font-family: Open Sans, Calibri, Arial;
margin: 0 auto;
width: 1500px;
}
body {
}
#Container {
float:left;
width:100%;
position:relative;
border:1px solid black;
}
#TreeList {
position:relative;
border-bottom: 1px solid #707070;
border-top: 1px solid #707070;
border-left: 1px solid #707070;
float:left;
overflow:hidden;
padding: 20px;
}
#TabControl {
position:relative;
border:1px solid #707070;
overflow:hidden;
float:left;
padding: 20px;
}
height: 100%; does not work like some would expect, you need a given height (em,%,px,etc..) on the parent element. In this case Your body I suppose. Add this to your css:
html, body{
height: 100%;
}
If you need a flexible parent container height there are several workarounds to achive that:
#1 Flexbox
You might take a look here: Flexbox Guide, works pretty neat, with the downside of browser support.
#2 Absolute positioning
Give the parent position: relative; And your element position: absolute; top: 0, bottom: 0; left: 0; for example.
#3 jQuery Plugin: matchHeight
This plugin does the job as well: matchHeight, only requires jQuery included and javascript to run
You haven't set any height in your css document, therefore all of the heights are pretty much random. First off set a main height for your body & html and then for the container like so:
html, body {
height: 100%;
}
#Container {
float:left;
width:100%;
position: relative;
border:1px solid black;
height: 100%;
}
Then for your other elements:
#TreeList {
position:relative;
border-bottom: 1px solid #707070;
border-top: 1px solid #707070;
border-left: 1px solid #707070;
float:left;
overflow:hidden;
padding: 20px;
height:100%;
}
#TabControl {
position:relative;
border:1px solid #707070;
overflow:hidden;
float:left;
padding: 20px;
height: 100%;
}
Or if you prefer you could use position: absolute; for your child element and do something like this:
child {
position: absolute;
top: 0px;
left: 0px;
bottom: 0px;
width: 100px;
}
Which will make the elements stretch to the entire screen and keep a width you choose.
This should work, although I highly recommend using Javascript to set the height for body as well as position: absolute; instead of relative;
Add 100% height to the left column.
#TreeList { height:100% }

force div to bottom

I want the green div to be below the blue div instead of on top of it without changing either of their position values and using pure css only.
http://jsfiddle.net/LpjgLydv/40/
Is this possible?
Assumptions:
I may use inline css only
This is for a footer that needs to stay at the bottom regardless of how much content is on the page
Any other element on the page besides the footer (and html,head,body) may or may not exist at any given time
The footer is nested in <body> and cannot be placed anywhere else
I figured it out. Basically I had to add a relative position and a min-height to the html attribute as well as a margin-bottom to the body attribute:
http://jsfiddle.net/LpjgLydv/44/
html
<html>
<head>
</head>
<body>
<div class="box"></div>
<div class="box2"></div>
</body>
</html>
css
html {
position: relative;
min-height: 100%;
}
body {
margin: 0 0 250px;
}
.box
{
border: solid 10px blue;
position: relative;
height:900px;
width:380px;
margin-top: 5px;
margin-left: 8px;
}
.box2
{
border: solid 10px green;
position: absolute;
bottom:0px;
left:8px;
height: 180px;
width: 380px;
}
It now meets the criteria of all of the assumptions in the question.
You can use this without positioning.
.inner-box
{
border: solid 10px blue;
height:900px;
width:380px;
margin-top: 5px;
float:left;
}
.inner-box2
{
border: solid 10px green;
float:left;
bottom:0px;
height: 180px;
width: 380px;
clear:both;
}

Nav goes off the screen but button doesn't

HTML:
<html>
<head>
<title>Parallax</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav>
<br><br>
</nav>
<h2>One ring to rule them all</h2>
<button>View Our Work</button>
</body>
</html>
CSS:
*
{
margin: 0;
}
body
{
background-image: url("background.jpg");
color: white;
font-family: Helvetica;
padding: 0;
}
h2
{
font-family: "Kingthings Calligraphica";
font-size: 30pt;
text-align: center;
margin-top: 30%;
}
nav
{
border: 1px solid red;
position: fixed;
padding: 10px 20px;
width: 100%;
top: 0;
}
nav div
{
float: left;
height: 100%;
width: 20%;
background-color: rgba(0,0,0,0.6);
transition: background-color 0.5s;
}
nav div:hover
{
background-color: rgba(0,0,0,0);
cursor: pointer;
}
button
{
border: 1px solid white;
border-radius: 3px;
background-color: rgba(0,0,0,0);
color: white;
padding: 10px 20px;
width: 100%;
}
Result:
Why does the nav go off the screen but the button doesn't?
That's cause you use
width:100%;
and
border: 1px solid red;
which equals to
100% + 2px;
than you also add padding
and it just adds to the math.
This will work: http://jsbin.com/vubug/2/edit
nav{
box-shadow: inset 0 0 0 1px red;
position: fixed;
width:100%;
top: 0;
}
To let the browser do the math you can also use the calc CSS property. (*2014 still experimental)
Also worth to note: action elements (input, button etc) act differently across browsers and even OS. The padding applied to a 100% width button is applied inwards, while applied to a 100% width block level DIV element it acts outwards adding to the set width.
One of the logic reasons is that you cannot have block-level elements inside the <button></button> (and have a valid markup) that will allow you to use that element's padding instead, so browsers try to compensate that applying the padding in the inner button's space. TEST CASE
Using CSS3 box-sizing: border-box ;
DEMO
<div id="widthAuto">DIV {width: auto;}</div> <!-- DESIRED -->
<div id="width100">DIV {width: 100%;}</div> <!-- OVERFLOWS -->
<div id="fixed">DIV {position:fixed;}</div> <!-- LOOSES WIDTH -->
<div id="fixed_width100">DIV {position:fixed; width:100%;}</div> <!-- OVERFLOWS -->
<div id="fixed_width100_boxSizing">DIV {position:fixed; width:100%; box-sizing: border-box;}</div>
CSS:
div{
background:#ddd;
border:10px solid red;
padding:10px;
margin-bottom:5px;
font-family:monospace;
}
div[id^=fi]{border-color:blue}
#widthAuto{
width:auto;
}
#width100{
width:100%;
}
#fixed{
position:fixed; /* Not in flow and looses the "auto" width :( */
/*just for preview*/ top:200px;
}
#fixed_width100{
position:fixed;
width: 100%; /* same issue as #width100 */
/*just for preview*/ top:300px;
}
#fixed_width100_boxSizing{
position:fixed;
width:100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
/*just for preview*/ top:400px;
}
Simplest solution
Or simply use the fixed element as a 100% width dummy wrapper and apply padding, border, whatever you need to an inner element. That's the way I do.

divs are displaying behind footer

im using this css code:
/* status update page style */
#content_wrapper {
display: inline;
width: 80%;
padding: 0;
margin: 0 auto;
}
#content_update {
display: block;
float: left;
padding: 20px;
margin-top:20px;
width: 100%;
background-color: #eee;
border-radius: 10px;
box-shadow: 0 1px 6px rgba(0,0,0,0.5);
}
#content_maintainance {
display: block;
float: left;
padding: 20px;
margin-top:20px;
width: 100%;
background-color: #eee;
border-radius: 10px;
box-shadow: 0 1px 6px rgba(0,0,0,0.5);
}
#content_sidebar {
display: block;
float: right;
width: 230px;
padding: 20px;
background-color: #eee;
border-radius: 10px;
box-shadow: 0 1px 6px rgba(0,0,0,0.5);
}
/* FOOTER */
#footer {
width:100%;
height:580px;
position:absolute;
bottom:0;
left:0;
border-top:4px solid #ed1c24;
background-color:#eeeeee;
}
#footer-inner {
width:80%;
margin:0 auto 0 auto;
height:inherit;
}
#footerTop {
width:100%;
height:480px;
padding-top:10px;
border-bottom:2px #000000 solid;
}
#footerTopLeft {
width:30%;
height:420px;
float:left;
display:inline;
margin-top:10px;
padding:0 15px 10px 15px;
border-right:1px solid #000000;
}
#footerTopMid {
width:30%;
height:420px;
float:left;
display:inline;
margin-top:10px;
padding:0 15px 10px 15px;
border-right:1px solid #000000;
}
#footerTopRight {
width:30%;
height:420px;
float:left;
display:inline;
padding:0 15px 10px 15px;
}
but the divs are displaying behind the footer divs. i have created a fiddle here so you can see the html too - http://jsfiddle.net/wmrhC/
It's because you have set the footer div to be absolutely positioned at the bottom of the browser window with a height of 580px. This takes the div out of the regular document flow, which means other elements can start hiding behind it, and since it is 580px high, most other elements on the page will hide behind it. You could fix this by setting the z-index on the footer to -1, but that's probably not what you are after, as it would just mean that the div's will start floating over the top of the footer instead of behind the footer, and that still doesn't look pretty.
You should get rid of the absolute positioning which you have set currently, and maybe look at something like CSS sticky footer for an approach which will let you set a footer which sticks to the bottom of the page instead of to the bottom of the browser window.
When working with position: absolute or fixed you should always be aware that these elements can cover other parts of your site, and you have to manage their depth manually
You can do this using the z-index property.
Let's say that you would like that the footer part appears below all contents.
You could add the z-index property like this:
#footer {
/* other styles */
z-index: -1;
}
See it in action
Though note, that this only fixes the "content is displayed behind" problem. But looking at your page you have more positioning problems to solve.
As stated in other answers, it's because you've positioned your footer div to be fixed.
Something along this line (regarding HTML and CSS) should help for your page lay-out:
JSFiddle demo
This is the CSS (see the JS Fiddle for the full code):
...
.wrapper {
position: relative;
float: left;
left: 5.00%;
width: 90.00%;
background-color: #cccccc
}
.left1 {
position: relative;
float: left;
left: 0.50%;
width: 32.00%;
background-color: #ccccff
}
.left2 {
position: relative;
float: left;
left: 1.50%;
width: 32.00%;
background-color: #ccccff
}
.right {
position: relative;
float: right;
right: 0.50%;
width: 32.00%;
background-color: #ccccff
}
.footer {
position: relative;
float: left;
left: 5.00%;
width: 90.00%;
margin: 10px 0px;
background-color: #cfcfcf
}
...
As you can see, none of these items are positioned absolute or fixed.
Be sure to check this link too, which explains how you can create a sticky footer:
CSS Sticky footer (As indicated by another answer).