Can't place my DIV 10px from bottom - html

would you have any idea why my red div (.testbox) is not placed 10px from bottom as I would like it to be and despite the margin-bottom: 10px? See http://jsfiddle.net/Hs977/
Thanks for your help
body {
background-color: rgb(255, 255, 255);
font-family: Helvetica;
font-size: 16px;
font-weight: 400;
line-height: 1.38;
color: rgb(21, 84, 244);
margin: 0;
margin: 0;
padding: 0;
border: 0;
}
header {
width: 100%;
height: 600px;
min-height: 300px;
margin-right: auto;
margin-left: auto;
background-image: url('http://lorempixel.com/output/nature-q-c-1020-711-1.jpg');
background-size: cover;
background-position: center center;
background-color: rgb(222, 222, 222);
}
h1 {
width: 100%;
margin-top: 39px;
margin-right: auto;
margin-left: auto;
font-size: 37px;
font-weight: 400;
line-height: 1.38;
text-align: center;
color: rgb(0,0,0);
}
.blablatext {
margin-top: 16px;
margin-right: auto;
margin-left: auto;
font-weight: 400;
line-height: 1.38;
text-align: center;
color: rgb(21, 84, 244);
}
.testbox {
float: right;
width: 200px;
height: 90px;
background: red;
margin-right: 20px;
margin-bottom: 10px;
}

Does not work that way. To place the div at a specified distance from the bottom of it's container, you need to use position:absolute on the div and set position:relative on the container. Then use bottom:10px; to place it 10px from it's parents bottom.
Updated your fiddle: http://jsfiddle.net/Hs977/1/

from the Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification
In the absolute positioning model, a box is explicitly offset with
respect to its containing block. It is removed from the normal flow
entirely (it has no impact on later siblings). An absolutely
positioned box establishes a new containing block for normal flow
children and absolutely (but not fixed) positioned descendants.
However, the contents of an absolutely positioned element do not flow
around any other boxes. They may obscure the contents of another box
(or be obscured themselves), depending on the stack levels of the
overlapping boxes.
since your header have height defined:
height: 600px;
min-height: 300px;
you can specify absolute position, then set bottom position
.testbox {
float: right;
width: 200px;
height: 90px;
background: yellow;
margin-right: 20px;
position:absolute;
bottom:0;
}
http://jsfiddle.net/InferOn/Hs977/8/
I don't know why would you define float for .textbox

Related

beginner question on flexbox with absolute content

i have a probably rather easy question. I gave my body a background gradient and set it as a flexbox. I can give my 2 text elements the position absolute and everything works fine. But as soon as i give my box (which should have the same relation to the body as the text elements) an absolute position, my background gradient disappears. With a relative positioning that doesnt happen. I know i can work with relative here as well, but I just want to know why this happens to my background gradient. Hope sb can help,
Thanks
body {
margin: 0;
height: 100%;
background-image: linear-gradient(
to right,
rgb(69, 174, 201),
rgb(169, 248, 253)
);
display: flex;
justify-content: center;
flex-wrap: wrap;
}
h2 {
text-align: center;
font-size: 40px;
width: 100%;
position: absolute;
}
.poben {
text-align: center;
font-size: 20px;
letter-spacing: 0.2em;
width: 100%;
position: absolute;
top: 60px;
}
.center-box {
/* if I change the position below to absolute, the page gets white */
position: relative;
height: 800px;
width: 200px;
background: linear-gradient(rgb(17, 17, 53), rgb(62, 55, 102));
border-radius: 2%;
box-shadow: 10px 10px 10px hsl(284, 100%, 9%);
}
<h2>Test survey form</h2>
<p class="poben">Thanks for talking part in this survey!</p>
<div class="center-box">
</div>
Position: Absolute; when you use this it basically removes the element from the flow of the document. It behaves like it's not present there. You can use left/right/top/bottom properties to move the element anywhere you want.
Position: Relative; when you use this, it basically keeps the element in the flow of the document. You can use left/right/top/bottom properties to move the element relative to its parent container.
In your code, the body is the parent container.
When you give the child elements of this container as position: absolute; it basically moves them out of that body container.
Now body thinks there is no child inside me and its height is now 0 i.e no content no value. You inspect that in the Chrome Inspector and check the box model to understand it.
body {
margin: 0;
padding: 1px; /* Filling the body with some content */
height: 100%;
background-image: linear-gradient(
to right,
rgb(69, 174, 201),
rgb(169, 248, 253)
);
display: flex;
justify-content: center;
flex-wrap: wrap;
}
h2 {
text-align: center;
font-size: 40px;
width: 100%;
position: absolute;
}
.poben {
text-align: center;
font-size: 20px;
letter-spacing: 0.2em;
width: 100%;
position: absolute;
top: 60px;
}
.center-box {
/* if I change the position below to absolute, the page gets white */
position: absolute;
height: 800px;
width: 200px;
background: linear-gradient(rgb(17, 17, 53), rgb(62, 55, 102));
border-radius: 2%;
box-shadow: 10px 10px 10px hsl(284, 100%, 9%);
}
<h2>Test survey form</h2>
<p class="poben">Thanks for talking part in this survey!</p>
<div class="center-box">
This might help - https://css-tricks.com/almanac/properties/p/position/

Putting an image in above

I'm currently making a project which consists of a website that streams movies and tv shows, in the tv show section I want to insert a image to illustrate each episode. My idea is making a second image that shows which episode that image corresponds to and I'm having a little trouble putting the second image above the first one.
.episode-slidebackground {
width: 950px;
height: 220px;
background: rgba(162, 162, 162, 0.24);
float: left;
margin-left: 15px;
margin-top: 20px;
margin-bottom: 15px;
}
.episode-slidebackground img {
width:182px;
height:136px;
float: left;
margin-left: 7px;
margin-top: 7px;
margin-bottom: 5px;
border-radius: 15px;
}
.episode-slideimgbackground{
width: 925px;
margin-left:10px;
margin-right:10px;
height:145px;
background: rgba(128, 128, 128, 0.24)
}
h1{
font-size: 30px;
color: #f2a223;
font-weight: bold;
margin-bottom: 30px;
margin-top: 10px;
}
h2 {
font-size: 15px;
color: #f2a223;
font-weight: bold;
}
h3 {
font-size: 14px;
color: #fff;
font-weight: bold;
}
h4 {
font-size: 14px;
color: #f3b12b;
font-weight: bold;
}
h5 {
font-size: 12px;
color: white;
}
h6 {
font-size: 20px;
color: white;
padding-left: 5px;
padding-top: 5px;
}
<div class="episode-slidebackground">
<h6>Temporada:1 2 3 4 5 6</h6> <br>
<h2>Episódios:</h2>
<div class="episode-slideimgbackground">
<img src="img/1.jpg">
<img src="img/2.jpg">
<img src="img/3.jpg">
</div>
</div>
This is the page without the second image:
You need to try and work with CSS's position attribute. This will enable you to have more control over your elements.
The two position attribute's you need to make use of are absolute and relative.
Basically, if you have a div that is set to position: relative that means that you can adjust that div's position without changing the layout of your webpage. It also means that any children elements of that div with the position: absolute can be positioned anywhere inside of that relative div.
.videoContainer {
position: relative;
height: 200px;
width: 200px;
}
.videoImage, .videoCaption {
position: absolute;
color: white;
}
.videoCaption {
bottom: 0;
height: 50px;
background: Gray;
width: 100%;
}
<div class="videoContainer">
<img class="videoImage" src="http://placehold.it/200x200"/>
<div class="videoCaption">Some Caption</div>
</div>
You need to set the z-index this is an css attribute that determines which element is on top
https://developer.mozilla.org/en-US/docs/Web/CSS/z-index

Top message box in CSS

I'd like to make a message-alert box in my web app. I created the main style but I have problems on small screen sizes.
Here's the image for the regular 1366x768 computer screen:
And here is for a typical mobile device:
Problems:
The X button has tagled with the message.
The main message wrapper has fixed and wasn't expand when the message came out of the wrapper.
How to fix the two above problems? Do I have to follow another path? I use position: fixed; property-value to keep my message on top.
Here are my HTMl and CSS code:
HTML:
<div class="top-msg">
<div class="top-msg-ico">
!
</div>
<div class="top-msg-inner">
<p>Only letters and nubers are allowed for email. See security for more info.</p>
</div>
<div class="top-msg-close" style=" cursor: pointer;">✕</div>
</div>
CSS:
.top-msg {
width: 100%;
height: 55px;
position: fixed;
background-color: rgba(42,45,50,0.6);
color: rgba(250,251,255,0.95);
font-family: "Lato", sans-serif;
font-size: 18px;
}
.top-msg-close {
float: right;
padding-top: 17px;
padding-right: 30px;
//border: 1px solid white;
//height: 100%;
width: 3%;
}
.top-msg-inner {
top: 15px;
position: absolute;
display: inline-block;
padding-left: 10px;
width: 80%;
//border: 1px solid white;
}
.top-msg-ico {
min-width: 65px;
height: 100%;
background-color: #fff;
display: inline-block;
background-color: rgba(0,0,0,0.7);
text-align: center;
font-size: 45px;
}
FIDDLE:
https://jsfiddle.net/4oLvyajo/
UPDATE -SOLUTION!-
After some help from LGSon answer I manage to finish all the design, so I accepts his answer but the hole solution is in the fiddle below.
FIDDLE:
https://jsfiddle.net/4oLvyajo/4/
Images:
Here is a start for you
.top-msg {
width: 100%;
position: fixed;
background-color: rgba(42,45,50,0.6);
color: rgba(250,251,255,0.95);
font-family: "Lato", sans-serif;
font-size: 18px;
}
.top-msg-close {
float: left;
box-sizing: border-box;
padding-top: 17px;
padding-right: 30px;
width: 45px;
}
.top-msg-inner a {
text-decoration: none;
color: RGBA(0, 0, 0, 0.6);
font-weight: bold;
}
.top-msg-inner a:hover {
color: RGBA(0, 0, 0, 0.5);
}
.top-msg-inner {
float: left;
box-sizing: border-box;
padding: 0 10px;
width: calc(100% - 110px);
}
.top-msg-ico {
float: left;
width: 65px;
height: 57px;
background-color: #fff;
background-color: rgba(0,0,0,0.7);
text-align: center;
font-size: 45px;
}
<div class="top-msg">
<div class="top-msg-ico">
!
</div>
<div class="top-msg-inner">
<p>Only letters and nubers are allowed for email. See security for more info.</p>
</div>
<div class="top-msg-close" style="cursor: pointer;">✕</div>
</div>
replace the width: 80% with margin-right: 40px, and you'll have to play around with the top: 15px as well (at -11 I had it looking right, but you can play around with that)
Here is the updated Fiddle
If you want everything scalable you'll need a completely different approach. First of all, if you place a right floating element under a block element it will float right, but underneath it. You'll need to define the floating close button element first.
Anyway, here's the updated Fiddle
It needs some minor tweaks in the padding and margins, but I think this is very close to what you're looking for

margin right doesn't work inside block

I'm trying to set the margins to a text, however margin-right doesn't seem to work inside message.
Why?
css:
message
{
position: fixed;
display: block;
margin-bottom: 0px;
width: 100%;
height: 40px;
background-color: rgba(26, 119, 212, 100);
line-height: 40px;
font-style: italic;
text-align: left;
overflow: hidden;
}
.messageotext
{
width: 100%;
margin-right: 0px;
}
html:
<message><span class="messageotext">prova</span></message>
I want the text to be out the screen so I can translate it by scripting language from right to left.
You have given width:100% and the parent is fixed so it will not effect
If you remove your width:100% of span you will see margin-right
so you can add text-align:right to parent which will show the effect of margin-right or you can also use float:right
Demo - fiddle
Removed browser default styles by adding
*{
margin:0;
padding:0;
}
* {
margin: 0;
padding: 0;
}
message {
position: fixed;
display: block;
margin-bottom: 0px;
width: 100%;
height: 40px;
background-color: rgba(26, 119, 212, 100);
line-height: 40px;
font-style: italic;
text-align: left;
overflow: hidden;
text-align: right;
}
.messageotext {
/* width: 100%;*/
margin-right: 100px;
}
<message><span class="messageotext">prova</span>
</message>
You can modify your class messageotext with the following code:
.messageotext {
width: 100%;
position: absolute;
left: 100%;
}
Then you can decrease the value of left property to translate it from right to left.
Try using float:right
or you can also use only right:0px if position is absolute

Fixed Height for Vertical Scrollbar to Appear? No JS, only CSS

I am trying to set a fixed height for when the vertical scrollbar begins to be visible on the browser. My container is only 500px high. I set the body to 500px high. But I also have a footer that is about 30px high below the container. So my entire page is about 530px. However I don't want the page to start scrolling when it detects the bottom of the footer, but rather at the bottom of the container. Is there any way to ignore my footer so the page doesn't begin to scroll until 500px??
My markup:
<body>
<div id="veritcal"></div>
<div id="container"></div>
<div id="row1">
<div id="box1">content</div>
<div id="box1">content</div>
<div id="box1">content</div>
<div id="box1">content</div>
<div id="box1">content</div>
</div>
</div>
<div id="footer">Some Footer Content</div>
</body>
My css:
html,body{
height: 100%;
margin: 0;
padding: 0;
}
body{
font-family: "Lucida Console", Monaco, monospace;
font-size: 1em;
font-style: normal;
color: #FFFFFF;
text-align: center;
min-width: 800px;
min-height: 500px;
}
#vertical{
position: relative;
height: 50%;
margin-top: -250px;
margin-left: 0px;
margin-right: 0px;
width: 100%;
}
#container{
position: relative;
width: 800px;
height: 500px;
padding: 0px;
margin-left: auto;
margin-right: auto;
text-align: center;
z-index: 0;
}
#footer{
margin-left:auto;
margin-top: 5px;
margin-right: auto;
padding: 10px 10px 0 10px;
width: 550px;
height: 30px;
background-color: #000000;
color: rgba(0, 166, 172, 0.3);
line-height: 2.0em;
font-size: 0.7em;
font-weight: bold;
text-align: center;
border-radius: 5px;
opacity: 0;
}
#footer:hover{
opacity: 1;
}
So again, my page begins scrolling at 530px at the bottom of the footer. I have the container horizontally centered and my #vertical div makes the container center vertically. When I resize the browser, the top of the container stops at the top of the browser perfectly, but then the browser vertical scrollbar appears at 530px instead of 500px, which I set for the min-height of the body. Not sure why it still appears at 530px.
if I propably understood what you want, i think that you need to use in #footer in css
display: none;
instead of
opacity: 0;
I hope that will help you ...
if you want to use #footer:hover , may this code help you
in #footer , try this
#footer {
margin-left: auto;
margin-top: 5px;
margin-right: auto;
padding: 10px 10px 0 10px;
width: 550px;
height: 30px;
background-color: #000000;
color: rgba(0, 166, 172, 0.3);
line-height: 2.0em;
font-size: 0.7em;
font-weight: bold;
text-align: center;
border-radius: 5px;
opacity: 0;
/*add this code*/
position: fixed;
bottom: 0;
right: 50%;
margin-right: -285px;
}
you can also use
position: absolute;
instead of
position: fixed;
maybe this will solve your problem ...