how to apply css position:absolute correctly? - html

the problem is div, called 'dragger_container' doen't behave as i expect, and gets out from the parent div. it is not acceptable, cause it's an element that shows user scroll progress (it's a jquery plugin mCustomScrollBar) and interacts with user.
ask anyone for help.
thanks in advance
ps
cannot attach screen cause of reputation, uploaded it here:
screen_url
.mcs_my_container
{
width: 100%;
height: 100%;
}
.mcs_my_container .customScrollBox
{
margin-top: 10px;
position: relative;
height: 80%;
width: 100%;
overflow:hidden;
border: 1px solid green;
display: block;
}
.mcs_my_container .customScrollBox .container
{
position: absolute;
width: 70%;
top: 0;
float: left;
margin-left: 20px;
}
.mcs_my_container .customScrollBox .content
{
clear: both;
}
.mcs_my_container .dragger_container
{
position: absolute;
/*top: 10px !important;*/
width: 2px;
/*height: 50px;50px
height: 100%;*/
height: 110px;
top: 0px;
right: 20px;
float: right;
background: #000;
cursor: s-resize;
-moz-border-radius: 2px;
-khtml-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
cursor: s-resize;
}
.mcs_my_container .dragger
{
position: absolute;
width: 4px;
/*height: 100%;*/
height: 10px;/* !important;*/
background: #999;
text-align: center;
line-height: 10px;
color: #666;
overflow: hidden;
cursor: pointer;
-moz-border-radius: 2px;
-khtml-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
margin-left: -1px;
}
.mcs_my_container .dragger_pressed
{
position: absolute;
width: 6px;
margin-left: -2px;
height: 10px;
background: #999;
text-align: center;
line-height: 10px;
color: #666;
overflow: hidden;
-moz-border-radius: 4px;
-khtml-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
cursor: s-resize;
}
.divNoteText
{
position: static;
border: 1px solid red;
word-wrap: break-word;
}

You need to add position: relative to the parent container of dragger_container that you want it to be positioned within.
If you don't do this then dragger_container will be positioned absolutely to the nearest parent element that is relatively positioned, or if there isnt one then it will be positioned within body.

Related

Pseudo Element not visible

Trying to create a "chat bubble" type of thing and here is my code. The little triangle is made via a pseudo element ::after but I can't make it show.
Any ideas what I am doing wrong?
.playernamechat.self-message {
width: auto;
background-color: blue;
border-radius: 12px;
padding: 5px 10px;
margin-left: 5px;
display: inline-block;
max-width: 280px;
overflow: hidden;
float: left;
position: relative;
color: white;
}
.self-message::after {
content: "";
position: absolute;
top: 50%;
right: 100%;
margin-top: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
<span class="playernamechat self-message">hello</span>
Actually, it is showing but hidden. In your CSS remove overflow: hidden;. See below:
.playernamechat.self-message {
width: auto;
background-color: blue;
border-radius: 12px;
padding: 5px 10px;
margin-left: 5px;
display: inline-block;
max-width: 280px;
/*overflow: hidden;*/
float: left;
position: relative;
color: white;
}
.self-message::after {
content: "";
position: absolute;
top: 50%;
right: 100%;
margin-top: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
<span class="playernamechat self-message">hello</span>

How to place a triangle on my div to make it look like a speech bubble?

I created a simple div for my comments section.
I would like to give it the appearance of a speech bubble by having a triangle on the left or any other effect that would make it look like a speech bubble coming from the left.
How can I achieve that without using an image ?
image
html
<div class='comment'></div>
css
.comment {
margin-left: 10px;
height: 80px;
display: inline-block;
color: white;
width: 400px;
border: 1px solid white;
padding: 10px;
border-radius: 5px;
overflow: hidden;
}
Try this
.comment {
margin-left: 10px;
height: 80px;
display: inline-block;
color: white;
width: 400px;
border: 1px solid white;
padding: 10px;
border-radius: 5px;
position: relative;
background-color: #fff;
border:1px solid #000;
}
.comment::before{
content:"";
position: absolute;
top:20px;
left:-12px;
margin:auto;
height: 20px;
width: 20px;
border:1px solid #fff;
transform:rotate(45deg);
background-color: #fff;
border-bottom:1px solid #000;
border-left:1px solid #000;
}
<div class='comment'></div>
style accordingly,
hope this helps...
I hope to help you:
.comment {
position: relative;
margin-left: 50px;
margin-top: 50px;
height: 50px;
display: inline-block;
width: 200px;
padding: 10px;
border-radius: 5px;
background: skyblue;
color: #FFF;
}
.comment:before, .comment:after {
content: '';
border-radius: 100%;
position: absolute;
width: 50px;
height: 50px;
z-index: -1;
}
.comment:after {
background-color: #fff;
bottom: -30px;
left: 55px;
}
.comment:before {
background-color: skyblue;
bottom: -20px;
left: 70px;
}
<div class='comment'>Hello,World!</div>
I like Nicholas Gallagher's work best, see his demo page.
This is lifted off his page and is not my own work.
<style>
/* Bubble with an isoceles triangle
------------------------------------------ */
.triangle-isosceles {
position: relative;
padding: 15px;
margin: 1em 0 3em;
color: #000;
background: #f3961c;
border-radius: 10px;
background:linear-gradient(#f9d835, #f3961c);
}
/* creates triangle */
.triangle-isosceles:after {
content: "";
display: block; /* reduce the damage in FF3.0 */
position: absolute;
bottom: -15px;
left: 50px;
width: 0;
border-width: 15px 15px 0;
border-style: solid;
border-color: #f3961c transparent;
}
</style>
<p class="triangle-isosceles">This is a quote. Hello world. text goes here.</p>

Can't figure out some CSS styling

i have some CSS styling issues. first thing i have a from with 2 inputs and a button. the button is perfect positiond when i resize the window but the inputs dance around, why?
and het h2 this is appended when the button is pushed, the little arrow has to be always in the middle. Also the text needs to be always in the middle of the pop up, horizontal and vertical. Is this posible? and how?
here is the form:
#lname, #fname {
width: 90%;
height: 50px;
margin-top: 6%;
border-radius: 5px;
background-color: #1e2228;
color: #ddd;
border: 0px;
font-size: 2em;
position: absolute;
text-align: center;
}
#fname {
left: 40px;
top: 18px;
}
#lname {
left: 40px;
top: 84px;
}
#btn {
width: 100%;
height: 50px;
margin-top: 72px;
border-radius: 0 0 5px 5px;
background-color: #1e2228;
color: #ddd;
border: 0px;
font-size: 2em;
position: absolute;
left: 0px;
top: 128px;
}
here is the pop up window:
h2 {
margin: auto;
margin-top: 100px;
position: relative;
width: 50%;
height: 205px;
padding: 0px;
background: #2F3742;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
text-align: center;
font-size: 2em;
color: #8092AA;
margin: 100px auto 0 auto;
padding-top: 6%;
}
h2:after {
content: '';
position: absolute;
border-style: solid;
border-width: 0 20px 20px;
border-color: #2F3742 transparent;
display: block;
width: 0;
z-index: 1;
top: -20px;
left: 355px;
}
ofcourse you have to see this in action! here you go! http://codepen.io/shiva112/pen/dGMrWB
Why do you use absolute positioning? It's a really mess, but just add for your input elements margin-left:5%. For your heading arrow: h2:after{left:50%; margin-left:-20px; }And if you want to center the text vertical and horizontal, you need to wrap your h2 text content in span or any other element you like. Then set your h2 element style to: { display:table; width:100%; } and his child element to: { displat:table-cell; vertical-align:middle; }

how can set a div center of other div with CSS?

for example i designed a div for border style and i designed another div to center of that , how can i set it to center of larger div?
.Profile_Photo_Border {
border: 3px solid #052d31;
height: 90px;
width: 90px;
border-radius: 3px;
}
.Profile_Photo {
background-color:#005e67;
height: 80px;
width: 80px;
border-radius: 3px;
alignment-adjust:middle;
text-align:center;
}
<div class="Profile_Photo_Border">
<div class="Profile_Photo"></div>
</div>
Add the following style display: flex; to the parent div and
margin: 0 auto;
align-self: center;
to the child div to align it center horizontally as well as vertically.
So the styles become:
.Profile_Photo_Border {
border: 3px solid #052d31;
height: 90px;
width: 90px;
border-radius: 3px;
display: flex;
}
.Profile_Photo {
background-color:#005e67;
height: 80px;
width: 80px;
border-radius: 3px;
alignment-adjust:middle;
text-align:center;
margin: 0 auto;
align-self: center;
}
See the fiddle: "https://jsfiddle.net/ukgnnp4k/"
See the screenshot:
Try changing your CSS to:
.Profile_Photo_Border {
border: 3px solid #052d31;
height: 90px;
width: 90px;
border-radius: 3px;
position: relative;
}
.Profile_Photo {
background-color: #005e67;
height: 80px;
width: 80px;
border-radius: 3px;
text-align:center;
position: absolute;
top: 50%;
left: 50%;
margin-left: -40px;
margin-top: -40px;
}
This link also might be helpful:
https://css-tricks.com/centering-css-complete-guide/
Your second div has 10px size lesser than the first one in height and width.
So to centralize the middle one add margin:5px;to the second div, Profile_Photo.
You can add this css.
.Profile_Photo_Border {
border: 3px solid #052d31;
height: 90px;
width: 90px;
border-radius: 3px;
}
.Profile_Photo {
background-color:#005e67;
height: 80%;
width: 80%;
border-radius: 3px;
text-align:center;
margin:10px auto;
}
Use this http://jsfiddle.net/18yao91v/244/
.Profile_Photo {
background-color:#005e67;
height: 80px;
width: 80px;
border-radius: 3px;
margin: 5px auto;
}
If the outer div and inner div has fixed width, then you can use css position to align inner element.
See below CSS.
.Profile_Photo_Border {
border: 3px solid #052d31;
height: 90px;
width: 90px;
border-radius: 3px;
position: relative;
}
.Profile_Photo {
background-color:#005e67;
height: 80px;
width: 80px;
border-radius: 3px;
/* alignment-adjust:middle; No need to use this. */
text-align:center;
position: absolute;
top: 5px;
left: 5px;
}
<div class="Profile_Photo_Border">
<div class="Profile_Photo"></div>
</div>
Here are my 2 cents, I used the display:table.cell css style:
.Profile_Photo_Border {
border: 3px solid #052d31;
height: 150px;
width: 150px;
border-radius: 3px;
display: table-cell; /*added*/
vertical-align: middle; /*added*/
}
.Profile_Photo {
background-color: #005e67;
height: 80px;
width: 80px;
border-radius: 3px;
text-align: center; /*added*/
margin: auto; /*added*/
}
Here's another way of centering the div inside a div irrespective of width and height - Codepen
.Profile_Photo_Border {
border: 3px solid #052d31;
height: 90px;
width: 90px;
border-radius: 3px;
position: relative;
}
.Profile_Photo {
background-color:#005e67;
height: 80px;
width: 80px;
border-radius: 3px;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
}
And a guide from CSS Tricks for centering the div.
Another guide from CSS Tricks on Flexbox which is another better way.
Hope this might help you understand better.

Styling a button

http://jsfiddle.net/eS7bC/5/
button[type=submit] {
width: 101px; height: 16px;
background-color: #f68830;
-webkit-border-radius: 9px; -moz-border-radius: 9px; border-radius: 9px;
border: none;
cursor:pointer;
}
button[type=submit]:hover::after {
content:'';
background-color: #f68830;
width:6px; height:6px;
-webkit-border-radius: 50%; -moz-border-radius: 50%; border-radius: 50%;
vertical-align:middle;
float: right;
background-color: #d9e4ea;
margin: 0; padding: 0;
}
I have a button which changes it's style on hover. It works and looks fine on Chrome but there are problems in other browsers. On Firefox the dot that appears on hover is a bit out of place and the button moves when you hover or click on it. IE has similar issues to Firefox. The question is How do I style it to behave and look identical in all browsers?
This is because of the float: right attribute. Try this
button[type=submit] {
width: 101px; height: 16px;
background-color: #f68830;
webkit-border-radius: 9px; -moz-border-radius: 9px; border-radius: 9px;
border: none;
cursor:pointer;
margin: 0; padding: 0;
position: relative;
}
button[type=submit]:hover::after {
content:'';
background-color: #f68830;
width:6px; height:6px;
webkit-border-radius: 50%; -moz-border-radius: 50%; border-radius: 50%;
position: absolute;
right: 6px;
top: 5px;
background-color: #d9e4ea;
margin: 0; padding: 0;
}
jsFiddle
You can also make the ::before or ::after absolute to prevent any issues. Also allows you to position it where-ever you want.
button[type=submit] {
width: 101px; height: 16px;
background-color: #f68830;
webkit-border-radius: 9px; -moz-border-radius: 9px; border-radius: 9px;
border: none;
cursor:pointer;
}
:hover::before {
content:'';
background-color: #f68830;
width:6px; height:6px;
webkit-border-radius: 50%; -moz-border-radius: 50%; border-radius: 50%;
vertical-align:middle;
float: right;
background-color: #d9e4ea;
margin: 0; padding: 0;
border: none;
cursor: pointer;
}
button[type=submit]::before {
overflow:hidden;
position:absolute;
left: 30px;
top; 5px;
}