Absolute position div not working css - html

I have a parent element that is relatively positioned. I also have two absolutely positioned child elements that I want in respective corners (top left and top right). However, both of these elements won't show up in the DOM. I have explicit heights and width on both of these elements. I also tried changing the z-index of both elements to no avail.
Here is the markup and css:
.first_customer, .all_customer {
flex: 1 1 0;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.inner {
text-transform: uppercase;
width: 100%;
}
.inner > * {
margin: 20px auto;
background-color: #fad63a;
padding: 7px;
border-radius: 3px;
box-shadow: inset 0 0 10px #000;
border: 1px solid #fff;
text-align: center;
width: 85%;
}
.inner > h4 {
font-size: 10px;
}
.inner > h6 {
font-size: 10px;
}
.inner > p {
font-size: 10px;
}
.topleftcorner, .toprightcorner {
position: absolute;
min-width: 100px;
min-height: 100px;
}
.topleftcorner {
top: 0;
left: 0;
z-index: 2;
}
<div class="first_customer">
<div class="topleftcorner"></div>
<div class="toprightcorner"></div>
<div class="inner">
<h4>New Customers</h4>
<h6>$10 Gift</h6>
<p>Dry Cleaning</p>
</div>
</div>

it's working already. I just added background color and position right div.
.first_customer,.all_customer{
flex: 1 1 0;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.inner{
text-transform: uppercase;
width: 100%;
}
.inner > *{
margin: 20px auto;
background-color: #fad63a;
padding: 7px;
border-radius: 3px;
box-shadow: inset 0 0 10px #000;
border: 1px solid #fff;
text-align: center;
width: 85%;
}
.inner > h4{
font-size: 10px;
}
.inner > h6{
font-size: 10px;
}
.inner > p{
font-size: 10px;
}
.topleftcorner,.toprightcorner{
position: absolute;
width: 100px;
height: 100px;
background-color: #000;
}
.topleftcorner{
top: 0;
left: 0;
z-index: 2;
}
.toprightcorner {
top: 0;
right: 0;
z-index: 2;
}
<div class="first_customer">
<div class="topleftcorner"></div>
<div class="toprightcorner"></div>
<div class="inner">
<h4>New Customers</h4>
<h6>$10 Gift</h6>
<p>Dry Cleaning</p>
</div>
</div>

Almost there , need some changes for right corner.
.first_customer,.all_customer{
flex: 1 1 0;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.inner{
text-transform: uppercase;
width: 100%;
}
.inner > *{
margin: 20px auto;
background-color: #fad63a;
padding: 7px;
border-radius: 3px;
box-shadow: inset 0 0 10px #000;
border: 1px solid #fff;
text-align: center;
width: 85%;
}
.inner > h4{
font-size: 10px;
}
.inner > h6{
font-size: 10px;
}
.inner > p{
font-size: 10px;
}
.topleftcorner,.toprightcorner{
position: absolute;
min-width: 100px;
min-height: 100px;
background: red;
top: 0;
}
.topleftcorner{
left: 0;
z-index: 2;
}
.toprightcorner{
right: 0;
z-index: 2;
}
<div class="first_customer">
<div class="topleftcorner"></div>
<div class="toprightcorner"></div>
<div class="inner">
<h4>New Customers</h4>
<h6>$10 Gift</h6>
<p>Dry Cleaning</p>
</div>
</div>

Related

Why when i put float:right on <div> it goes down?

I want #cart to go to the right top of the page. When I add float, it goes down. Why? I'm putting there codes and images with and then without the float.
* {
margin: 0;
}
#fl {
background-color: #fff;
padding: 10px;
color: transparent;
font-size: 20px;
height: 60px;
margin-top: 100px;
text-align: center;
line-height: 60px;
width: 70%;
margin-left: auto;
margin-right: auto;
opacity: 0.8;
border-left: 5px solid black;
font-family: 'Nanum Gothic', sans-serif;
}
#log {
height: 60px;
margin-top: 2px;
}
#container {
width: 70%;
height: 70px;
background-color: rgba(111, 250, 171, 0.5);
box-shadow: 1px 1px 2px black;
margin-top: 20px;
display: flex;
justify-content: center;
margin-left: auto;
margin-right: auto;
flex-direction: row-reverse;
}
#cart {
font-size: 30px;
float: right;
height: 40px;
}
<div id="cart">CART</div>
<div id="fl">
<h1><span>BUY EXCLUSIVE ONDRIWATER TODAY</span></h1>
</div>
<div id="container">
<div class="greensale">
<span class="more">400ml</span> for just <span class="more">200$</span>
</div>
<div id="log">
<img src="logo.png" height="60" width="60" />
</div>
</div>
When you make the element floating the next one (id="fl") will become the first in-flow element and its top margin will collapse with the top margin of its the container (body). it's like you increased the top margin of the container by
margin-top: 100px; and since the floating element is placed considering this one the element will jump to its new position.
To avoid this, you need to avoid margin to collapse:
* {
margin: 0;
}
body {
padding-top:1px;
}
#fl {
background-color: #fff;
padding: 10px;
color: transparent;
font-size: 20px;
height: 60px;
margin-top: 100px;
text-align: center;
line-height: 60px;
width: 70%;
margin-left: auto;
margin-right: auto;
opacity: 0.8;
border-left: 5px solid black;
font-family: 'Nanum Gothic', sans-serif;
}
#log {
height: 60px;
margin-top: 2px;
}
#container {
width: 70%;
height: 70px;
background-color: rgba(111, 250, 171, 0.5);
box-shadow: 1px 1px 2px black;
margin-top: 20px;
display: flex;
justify-content: center;
margin-left: auto;
margin-right: auto;
flex-direction: row-reverse;
}
#cart {
font-size: 30px;
float: right;
height: 40px;
}
<div id="cart">CART</div>
<div id="fl">
<h1><span>BUY EXCLUSIVE ONDRIWATER TODAY</span></h1>
</div>
<div id="container">
<div class="greensale">
<span class="more">400ml</span> for just <span class="more">200$</span>
</div>
</div>
Adding background to the body will make you better see the issue. Comment/uncomment the floating property to see what is happening:
* {
margin: 0;
}
body {
background:red;
}
html {
background:#fff;
}
#fl {
background-color: #fff;
padding: 10px;
color: transparent;
font-size: 20px;
height: 60px;
margin-top: 100px;
text-align: center;
line-height: 60px;
width: 70%;
margin-left: auto;
margin-right: auto;
opacity: 0.8;
border-left: 5px solid black;
font-family: 'Nanum Gothic', sans-serif;
}
#log {
height: 60px;
margin-top: 2px;
}
#container {
width: 70%;
height: 70px;
background-color: rgba(111, 250, 171, 0.5);
box-shadow: 1px 1px 2px black;
margin-top: 20px;
display: flex;
justify-content: center;
margin-left: auto;
margin-right: auto;
flex-direction: row-reverse;
}
#cart {
font-size: 30px;
float: right;
height: 40px;
}
<div id="cart">CART</div>
<div id="fl">
<h1><span>BUY EXCLUSIVE ONDRIWATER TODAY</span></h1>
</div>
<div id="container">
<div class="greensale">
<span class="more">400ml</span> for just <span class="more">200$</span>
</div>
</div>
in your code #cart is top and right your page!
so, you could use absolute position like:
#cart {
font-size: 30px;
right: 0;
top:0;
height: 40px;
position:absolute;
}
instead of float: right do text-align: right. The float-style will align the #cartelement with #fl

Style break on flexbox chat

Does anyone know why the image breaks onto a new line when the bubbles sides are constrained?
If I change the bubbles max-width to calc(100% - 70px) the image doesn't break although I get the last word on a new line, which also breaks the style.
body {
background: #f0f3f6;
}
.messages {
width: 100%;
margin-top: 65px;
margin-bottom: 70px;
padding-bottom: 15px;
}
.scrolling {
display: inline-flex;
flex: auto;
overflow-y: auto;
overflow-x: hidden;
}
.scrolled {
flex: 0 1 auto;
display: flex;
flex-flow: column nowrap;
justify-content: flex-end;
width: 100%;
height: 100%;
margin: 0 15px;
}
.message {
line-height: 1em;
display: block;
margin: 18px 0;
position: relative;
}
.message .image {
position: relative;
display: inline-block;
width: 25px;
}
.message img {
display: block;
width: 100%;
border-radius: 150px;
}
.message .bubble {
font-weight: 300;
position: relative;
vertical-align: text-top;
display: inline-block;
font-size: 0.9em;
padding: 12px 14px;
margin-top: -16px;
margin-left: 20px;
margin-right: 20px;
border-radius: 4px;
max-width: 100%;
}
.message .bubble::after {
content: '';
position: absolute;
top: 12px;
width: 0;
height: 0;
}
.message .time {
color: #838689;
font-weight: 500;
font-size: 0.7em;
position: absolute;
bottom: -1.9em;
width: 100%;
}
.message-left {
flex: 1;
align-self: flex-start;
}
.message-left .time {
left: 50px;
}
.message-left .bubble {
color: #343434;
background-color: #fff;
margin-left: 20px;
}
.message-left .bubble::after {
position: absolute;
left: -5px;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-right: 5px solid #fff;
}
.message-right {
flex: 0;
align-self: flex-end;
float: right;
}
.message-right .time {
text-align: right;
right: 50px;
}
.message-right .bubble {
color: #fff;
margin-right: 20px;
background-color: #0084ff;
}
.message-right .bubble::after {
position: absolute;
right: -5px;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 5px solid #0084ff;
}
<div ref="messages" class="messages scrolling">
<div class="scrolled">
<div class="message message-left">
<span class="time">1 min ago</span>
<div class="image">
<img src="https://scontent-lht6-1.xx.fbcdn.net/v/t1.0-9/15492548_1291266807563287_6299338365875926813_n.jpg?oh=b2c7a59d1666247350753be9002e6884&oe=5AB71F93" />
</div>
<div class="bubble">
This message has the same problem.
</div>
</div>
<div class="message message-right">
<span class="time">1 min ago</span>
<div class="bubble">
A small comment.
</div>
<div class="image">
<img src="https://scontent-lht6-1.xx.fbcdn.net/v/t1.0-9/15492548_1291266807563287_6299338365875926813_n.jpg?oh=b2c7a59d1666247350753be9002e6884&oe=5AB71F93" />
</div>
</div>
<div class="message message-right">
<span class="time">1 min ago</span>
<div class="bubble">
A really long message, designed to be big enough to create a multi-line comment.
</div>
<div class="image">
<img src="https://scontent-lht6-1.xx.fbcdn.net/v/t1.0-9/15492548_1291266807563287_6299338365875926813_n.jpg?oh=b2c7a59d1666247350753be9002e6884&oe=5AB71F93" />
</div>
</div>
</div>
</div>
Original JSFiddle
The message element is display: block.
If you use display: flex instead, the image and text are forced to remain on a single line (because a default setting of a flex container is flex-wrap: nowrap).
revised demo 1
If you don't want the images to shrink, add flex-shrink: 0 to the items. (By default, flex items are set to flex-shrink: 1, allowing them to shrink so they don't overflow the container).
revised demo 2

How to align a window on right side with flexible height?

Hey!
As you see in the picture I want to move the existing chatwindow to the right side where the red box is.
And I also need the box to change the height of itself when the window is made smaller.
The grid is from semantic.ui.
EDIT: On some request the whole css and parent html container is given. Hope this helps to solve the problem.
Thanks!
HTML:
<div class="two column doubling ui grid">
<div class="column">
<div class="ui segment">
1
</div>
</div>
<div class="computer only column">
<div class="chat_window">
<div class="top_menu">
<div class="buttons">
<div class="button maximize">
<h4 id="Online"></h4>
</div>
</div>
<div class="title">Chat</div>
</div>
<ul class="messages"></ul>
<div class="bottom_wrapper clearfix">
<div class="message_input_wrapper"><input class="message_input" placeholder="Type your message!" /></div>
<div class="send_message">
<div class="text">Send</div>
</div>
</div>
</div>
<div class="message_template">
<li class="message">
<div class="avatar"></div>
<div class="text_wrapper">
<div class="msgname"><a id="steamlink" target="_blank"><p id="msgname"></p></a></div>
<div class="text"></div>
</div>
</li>
</div>
</div>
</div>
CSS:
.chat_window {
width: 100%;
max-width: 450px;
background-color: #fff;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
background-color: #f8f8f8;
overflow: hidden;
}
.top_menu {
background-color: #fff;
width: 100%;
padding: 20px 0 15px;
box-shadow: 0 1px 30px rgba(0, 0, 0, 0.1);
}
.top_menu .buttons {
margin: 3px 0 0 20px;
position: absolute;
}
.top_menu .buttons .button {
width: 16px;
height: 16px;
border-radius: 50%;
display: inline-block;
margin-right: 10px;
position: relative;
}
.top_menu .buttons .button.close {
background-color: #f5886e;
}
.top_menu .buttons .button.minimize {
background-color: #fdbf68;
}
.top_menu .buttons .button.maximize {
background-color: #a3d063;
}
.top_menu .title {
text-align: center;
color: #bcbdc0;
font-size: 20px;
}
#Online{
margin: 0 0 0 20px;
color: #bcbdc0;
}
.messages {
position: relative;
list-style: none;
padding: 20px 10px 0 10px;
margin: 0;
height: 600px;
overflow-y: scroll;
}
.messages .message {
clear: both;
overflow: hidden;
margin-bottom: 10px;
transition: all 0.5s linear;
opacity: 0;
}
.messages .message.left .avatar {
background-size: 100%;
float: left;
}
.messages .message.left .text_wrapper {
background-color: #DFDFDF;
margin-left: 20px;
}
.messages .message .avatar {
width: 60px;
height: 60px;
border-radius: 50%;
display: inline-block;
}
.messages .message .msgname {
font-weight: bold;
}
.messages .message .text_wrapper {
display: inline-block;
padding-left: 10px;
padding-top: 5px;
padding-bottom: 5px;
border-radius: 6px;
width: calc(100% - 85px);
min-width: 100px;
position: relative;
}
.messages .message .text_wrapper .text {
font-size: 14px;
font-weight: 250;
}
.bottom_wrapper {
position: relative;
width: 100%;
background-color: #fff;
padding: 10px 10px;
bottom: 0;
}
.bottom_wrapper .message_input_wrapper {
display: inline-block;
height: 50px;
border-radius: 5px;
border: 1px solid #bcbdc0;
width: calc(100% - 100px);
position: relative;
padding: 0 20px;
}
.bottom_wrapper .message_input_wrapper .message_input {
border: none;
height: 100%;
box-sizing: border-box;
width: calc(100% - 40px);
position: absolute;
outline-width: 0;
color: gray;
}
.bottom_wrapper .send_message {
width: 90px;
height: 50px;
display: inline-block;
border-radius: 5px;
background-color: #563D7C;
color: #fff;
cursor: pointer;
transition: all 0.2s linear;
text-align: center;
float: right;
}
Picture:
Click here

Html three divs side by side with same height

I am trying to set three divs side by side with each equal width and height.
I am unable to remove that extra space at right at right most div. If I set its margin-right to 0 the rightmost div becomes bigger than other two.
Here is the fiddle.
Css:
.recordpopup {
position: fixed;
z-index: 10000;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: rgba( 0, 0, 0, .8);
background-position: 50% 50%;
background-repeat: no-repeat;
display: block;
}
.recordpopup .retry {
background-color: black;
border: 1px solid white;
xborder-radius: 8px;
box-sizing: border-box;
color: white;
font-family: ProximaNova-Regular;
font-size: 16px;
font-weight: bold;
xheight: 50px;
margin-left: auto;
margin-right: auto;
padding-top: 0px;
position: relative;
text-align: center;
top: 30%;
width: 40%;
z-index: 15000;
border-radius: 8px;
padding: 20px 10px;
background-image: url('images/gray_bar.png');
background-repeat: repeat-x;
background-color: white;
}
#product-wrapper {
overflow: hidden;
margin-top: 25px;
}
.product {
float: left;
width: 33%;
display: table-cell;
width: 33.33333333%;
}
.product .container {
margin-right: 10px;
padding: 10px;
background-color: #000;
}
.product .container img {
display: block;
margin: 0 auto;
width: 100%;
}
#closeRecord {
background: black none repeat scroll 0 0;
border: 2px solid white;
border-radius: 50%;
color: white;
cursor: pointer;
height: 25px;
right: -15px;
left: right;
position: absolute;
top: -10px;
width: 25px;
}
Html:
<div class="recordpopup">
<div class="retry">
<div id="closeRecord">x</div>
<div style="width: 100%;text-align: left;margin: 5px 0;font-size: 12px;color:#333;"><span class="TitleText">Lorem Ipsum Lorem Ipsum</span> </div>
<div id="product-wrapper">
<div class="product">
<div class="container">
<img src="images/circle.png">
<p>Dummy</p>
</div>
</div>
<div class="product">
<div class="container">
<img src="images/circle.png">
<p>Dummy</p>
</div>
</div>
<div class="product">
<div class="container">
<img src="images/circle.png">
<p>Dummy</p>
</div>
</div>
</div>
</div>
</div>
Here is my solution.
The key is removing the margin-right: 10px and adding
.product:nth-child(1) .container{
margin-right:5px;
}
.product:nth-child(2) .container{
margin: 0 5px 0 5px;
}
.product:nth-child(3) .container{
margin-left: 5px;
}
JSFiddle ===> https://jsfiddle.net/kjkk3f9d/1/
The margin-right: 10px was pushing out your divs, replace it with margin: 0 5px to give a uniform look
.product .container {
margin: 0px 5px;
padding: 10px;
background-color: #000;
}
https://jsfiddle.net/kjkk3f9d/3/
check out my fiddle:
https://jsfiddle.net/kjkk3f9d/2/
the important styles are
#product-wrapper {
overflow: hidden;
margin-top: 25px;
display: flex;
justify-content: space-between;
}
.product {
flex-basis:0;
flex: 1 1 auto;
margin: 5px;
}

CSS - div aligning to the bottom of parent div (inline-block)

I know this html is sloppy, with some extra divs that are unnecessary, but regardless, I can't understand why the div with ID "info_box_right" is aligning to the bottom of the parent div (you can see the "text" aligned to the bottom at the below jsfiddle example).
Any ideas how I can get it to align to the top of its parent?
http://jsfiddle.net/taddme0y/1/
HTML:
<div id="info_container" >
<div id="info_box">
<hr class="info_box_hr" noshade>
<a id="info_box_title"></a>
<hr class="info_box_hr" noshade>
<div id="info_box_wrapper">
<div id="info_box_left">
<div class="info_box_sub_wrapper">
<a id="info_box_logo">
<img class="info_img" id="info_img_logo" alt="logo">
</a>
<a id="info_box_screenshot">
<img class="info_img" id="info_img_screenshot" alt="screenshot">
</a>
</div>
</div>
<div id="info_box_right">
<div class="info_box_sub_wrapper">
<a id="info_box_right_text">
Text
</a>
</div>
</div>
</div>
</div>
</div>
CSS:
#info_container {
z-index: 500;
position: relative;
top: 0;
left: 0;
width: 80%;
height: 0;
margin: 0 auto;
background-color: #000000;
}
#info_box {
z-index: 500;
position: relative;
top: 50px;
width: 100%;
background-color: #FFFFFF;
text-align: center;
-webkit-box-shadow: 2px 2px 4px #888;
-moz-box-shadow: 2px 2px 4px #888;
box-shadow: 2px 2px 4px #888;
}
#info_box_wrapper {
position: relative;
display: block;
width: 100%;
margin: 0 auto;
text-align: center;
}
#info_box_left {
display: inline-block;
position: relative;
margin: 0 auto;
width: 45%;
min-width: 100px;
}
#info_box_right {
display: inline-block;
position: relative;
margin: 0 auto;
width: 45%;
min-width: 100px;
/* margin-bottom: 20px; */
}
.info_box_sub_wrapper {
position: relative;
display: inline-block;
width: 100%;
margin: 0 auto;
text-align: center;
}
#info_box_right_text {
position: relative;
color: #4D4D4D;
}
#info_box_logo, #info_box_screenshot {
position: relative;
width: 100%;
margin: 0 auto;
background-color: transparent;
background-size: 100%;
background-repeat: no-repeat;
background-position: center;
border-style: transparent;
border-color: #4D4D4D;
border-width: 2px;
cursor: pointer;
}
.info_img {
width: 100px;
margin: 20px;
background-color: #000;
}
You can specify how you want an element to vertically align using the vertical-align CSS property.
#info_box_right {
vertical-align: top;
}
http://www.w3schools.com/cssref/pr_pos_vertical-align.asp