How can I recreate GitHub's repositories language list using CSS only? Something like this, for example:
I started with a list of divs but I cannot figure out how to draw the dots using CSS...
<div>
<div>C 90%</div>
<div>Assembly 5.8%</div>
<div>Makefile 2.9%</div>
<div>C++ 0.5%</div>
</div>
You can use ::before pseudo element to add the dots before each item.
https://developer.mozilla.org/en-US/docs/Web/CSS/::before
Something like this:
div > div {
position: relative;
margin-left: 10px;
}
div > div:before {
content: '';
position: absolute;
height: 5px;
width: 5px;
right: 100%;
margin-right: 5px;
top: calc(50% - 2.5px);
border-radius: 2px;
background: red;
}
<div>
<div>C 90%</div>
<div>Assembly 5.8%</div>
<div>Makefile 2.9%</div>
<div>C++ 0.5%</div>
</div>
Okay I managed to do something similar:
<div class="rows">
<div class="dot" style="color: #555555;"></div>
<div class="child">C 90%</div>
</div>
<div class="rows">
<div class="dot" style="color: #6E4C13;"></div>
<div class="child">Assembly 5.8%</div>
</div>
<div class="rows">
<div class="dot" style="color: #427819;"></div>
<div class="child">Makefile 2.9%</div>
</div>
.rows {
text-align: center;
display: inline-block;
vertical-align: middle;
margin-right: 10px;
}
.dot, .child {
vertical-align: middle;
display: inline-block;
}
.rows > .dot {
position: relative;
margin-left: 10px;
margin-bottom: 10px;
}
.rows > .dot:before {
content: '';
position: absolute;
height: 10px;
width: 10px;
right: 100%;
margin-right: 5px;
top: 20%;
border-radius: 10px;
background-color: currentColor;
}
The dot colour is managed from the style attribute. The last thing left to do is to change the font of the language name(e.g. Assembly) and of the percentage(e.g. 5.8%), after that result is very similar to GitHub's.
Related
I'm trying to do two things here but can't make either work. I've never played with CSS before so I've just been sitting on jsfiddle for a few hours trying to just make this basic div table
The first thing I'm trying to do is get 30px border spacing working. I've tried to enter it everywhere in the CSS and all the cells are still attached instead of having space between them
The second thing is the hover effect. I would like a message to pop up on each cell, but the way I have it now, when you put your mouse over the cell, it shows the hover effect on the entire row
any help would be appreciated. Here's my current code
.BestSeller {
border-spacing: 30px;
display: table;
background-color: #fafafa;
text-align: center;
border-collapse: collapse;
width: 100%;
position: relative;
}
.BestSellerRow {
display: table-row;
}
.BestSellerBody {
display: table-row-group;
}
.BestSellerCell {
display: table-cell;
border: 1px solid #ececec;
padding: 10px;
}
.BestSellerTextBox {
background-color: #ff9225;
display: inline-block;
border-radius: 3px;
cursor: pointer;
color: #ffffff;
padding: 3px 75px;
text-decoration: none;
}
.BestSellerTextBox:hover {
background-color: #ff9f3f;
color: #ffffff;
}
.BestSellerOverlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
}
.BestSellerCell:Hover .BestSellerOverlay {
height: 50%;
}
.BestSellerOverlayText {
white-space: nowrap;
color: white;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="BestSeller">
<div class="BestSellerBody">
<div class="BestSellerRow">
<div class="BestSellerCell">I Like Eggs<br><br><br><br><br><br><br><br><br>
<div class="BestSellerOverlay">
<div class="BestSellerOverlayText">Hello World</div>
</div>
</div>
<div class="BestSellerCell">This is just a quick test </div>
<div class="BestSellerCell">This is just a quick test </div>
<div class="BestSellerCell">This is just a quick test </div>
</div>
<div class="BestSellerRow">
<div class="BestSellerCell">I Like Eggs<br><br><br><br><br><br><br><br><br>
<div class="BestSellerOverlay">
<div class="BestSellerOverlayText">Why This No Work</div>
</div>
</div>
<div class="BestSellerCell">This is just a quick test </div>
<div class="BestSellerCell">This is just a quick test </div>
<div class="BestSellerCell">This is just a quick test </div>
</div>
</div>
</div>
Firstly, border-spacing work with border-collapse : separate. Add that to .BestSeller and it will do the work. More refer to the MDN.
Secondly, you set .BestSellerOverlay to position: absolute, which is a good start. However, absolute positions the element to its nearest positioned ancestor.. If there is no nearest positioned ancestor, it will fallback to the viewport. Which is the result you see, the overlay attached to the bottom to the page. I apply position: relative to .BestSellerCell, such the overlay will stick to the cell.
.BestSeller {
display: table;
background-color: #fafafa;
text-align: center;
border-collapse: separate;
border-spacing: 30px;
width: 100%;
position: relative;
}
.BestSellerRow {
display: table-row;
}
.BestSellerBody {
display: table-row-group;
}
.BestSellerCell {
display: table-cell;
border: 1px solid #ececec;
padding: 10px;
position: relative;
}
/*==============================================================================
#BestSellerTextBox
==============================================================================*/
.BestSellerTextBox {
background-color: #ff9225;
display: inline-block;
border-radius: 3px;
cursor: pointer;
color: #ffffff;
padding: 3px 75px;
text-decoration: none;
}
.BestSellerTextBox:hover {
background-color: #ff9f3f;
color: #ffffff;
}
/*==============================================================================
#HoverOverlay For Best Selelr
==============================================================================*/
.BestSellerOverlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
}
.BestSellerCell:Hover .BestSellerOverlay {
height: 50%;
}
.BestSellerOverlayText {
white-space: nowrap;
color: white;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="BestSeller">
<div class="BestSellerBody">
<div class="BestSellerRow">
<div class="BestSellerCell">
I Like Eggs<br> <br> <br> <br> <br> <br> <br> <br> <br>
<div class="BestSellerOverlay">
<div class="BestSellerOverlayText">Hello World</div>
</div>
</div>
<div class="BestSellerCell">This is just a quick test</div>
<div class="BestSellerCell">This is just a quick test</div>
<div class="BestSellerCell">This is just a quick test</div>
</div>
<div class="BestSellerRow">
<div class="BestSellerCell">
I Like Eggs<br> <br> <br> <br> <br> <br> <br> <br> <br>
<div class="BestSellerOverlay">
<div class="BestSellerOverlayText">Why This No Work</div>
</div>
</div>
<div class="BestSellerCell">This is just a quick test</div>
<div class="BestSellerCell">This is just a quick test</div>
<div class="BestSellerCell">This is just a quick test</div>
</div>
</div>
</div>
I advise you to use grid.layoutit, where you'll be able to design tables using the grid layout display.
Try with below code. Where I have made changes.
//CSS
.BestSellerCell {
/* display: table-cell; */
border: 1px solid #ececec;
padding: 10px;
margin: 21px;
float: left;
height: 200px;
}
.BestSellerCell:hover{
background-color:red;
}
.child-span{display:none;}
//HTML -- for each div I have added the child span
<div class="BestSellerCell"><span class="child-span">child span</span> This is just a quick test </div>
//Script -- I have added the mouse event
$('.BestSellerCell').mouseenter(function(){
$(this).find('.child-span').show();
});
$('.BestSellerCell').mouseleave(function(){
$(this).find('.child-span').hide();
});
I have square navigation buttons where I want to visually show which are active, for example using:
At the moment I use background: linear-gradient for this purpose. This however is hard to animate and I therefore am looking for alternatives. The HTML structures looks like:
<div class='navigation-button'>
<div class='navigation-button-container'>
<i class='fa fa-bars'></i>
</div>
</div>
with corresponding CSS:
.navigation-button {
width: 50px;
height: 50px;
background: purple;
}
.navigation-button-container {
width: 100%;
height: 100%;
text-align: center;
}
.navigation-button-container i {
margin-top: 25%;
margin-bottom: 25%;
color: white;
}
.active {
background: linear-gradient(right, blue 0%, blue 10%, rgba(0,0,0,0) 10%);
}
The active class can be applied to the navigation-button-container to get the desired effect. I want to however fade this in and out and as I understand linear-gradients cannot be animated.
I have looked in adding a element before the navigation-button-container and animate it's width and using the CSS ::before syntax but neither seemed to be of help. Is there an efficient CSS way to get the desired effect using #keyframes or transition?
Is this what you needed? There is a ::before pseudo-element on .nb-container which has a width transition.
.nb {
background-color: #f00;
display: block;
height: 50px;
width: 50px;
}
.nb-container {
width: 100%;
height: 100%;
position: relative;
text-align: center;
}
.nb-container i {
color: white;
display: inline-block;
margin: 25% 0 25%;
}
.nb-container ::before {
background-color: #00f;
content: "";
display: block;
height: 100%;
left: 0;
position: absolute;
top: 0;
transition: width .2s;
width: 0;
}
.nb-container:hover ::before, .nb-container:focus ::before {
width: 20%;
}
Mouse over the elements to see the effect:
<div class="nb">
<div class="nb-container">
<i class="fa fa-bars">∆</i>
</div>
</div>
<div class="nb">
<div class="nb-container">
<i class="fa fa-bars">®</i>
</div>
</div>
<div class="nb">
<div class="nb-container">
<i class="fa fa-bars">©</i>
</div>
</div>
The ::before element is very versatile in the way it can be animated. So if you wanted a fade-in instead of a slide-in:
.nb {
background-color: #f00;
display: block;
height: 50px;
width: 50px;
}
.nb-container {
width: 100%;
height: 100%;
position: relative;
text-align: center;
}
.nb-container i {
color: white;
display: inline-block;
margin: 25% 0 25%;
}
.nb-container ::before {
background-color: #00f;
content: "";
display: block;
height: 100%;
left: 0;
opacity: 0;
position: absolute;
top: 0;
transition: opacity .2s;
width: 20%;
}
.nb-container:hover ::before, .nb-container:focus ::before {
opacity: 1;
}
Mouse over the elements to see the effect:
<div class="nb">
<div class="nb-container">
<i class="fa fa-bars">∆</i>
</div>
</div>
<div class="nb">
<div class="nb-container">
<i class="fa fa-bars">®</i>
</div>
</div>
<div class="nb">
<div class="nb-container">
<i class="fa fa-bars">©</i>
</div>
</div>
I've come up with what seems like a very hacky, non-semantic way to code a design that I'd like to use. Basically, it's a set of 4 equal-sized circles, distributed so their centers are the same as those of equilateral triangles. I've used a bunch of presentational divs to solve two issues: (1) to get the spacing of the circles right, I need their bounding boxes to overlap; and (2) to vertically space text in the circles without changing their size, it seems like I need to use display:table in my CSS.
It works, but I hate it, and I feel like there has to be a better way. I am new to CSS, and this method is the result of a fair amount of research about how to solve this design problem.
The design is at this codepen: http://codepen.io/bhagerty/pen/rejEPZ
(I put borders on a bunch of the elements just to show the structure.)
Here is the HTML:
<body>
<h1 id="home_title">test</h1>
<div id="container_1">
<div id="picture" class="box">
<div class="circle_outer">
<div class="circle_inner">
<div class="inner-text">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/%22In_Which_We_Serve%22_Advertisement_1943.jpg/1024px-%22In_Which_We_Serve%22_Advertisement_1943.jpg" width=100%; />
</div>
</div>
</div>
</div>
<div id="dog" class="box">
<div class="circle_outer">
<div class="circle_inner">
<div class="inner-text">
dog
</div>
</div>
</div>
</div>
<div id="shoes" class="box">
<div class="circle_outer">
<div class="circle_inner">
<div class="inner-text">
shoes
</div>
</div>
</div>
</div>
<div id="dance" class="box">
<div class="circle_outer">
<div class="circle_inner">
<div class="inner-text">
dance
</div>
</div>
</div>
</div>
<div id="footer_1">
Footer<br>
test
</div>
</div>
</body>
Here is the CSS:
* {
box-sizing: border-box;
padding: 0;
margin: 0;
font-size: 16px;
}
h1#home_title {
text-align: center;
font-size: 3rem;
margin: 0;
padding: .1rem 0 .5rem 0;;
background-color: grey;
}
div#container_1 {
border: green solid 5px;
width: 320px;
margin: auto;
position: relative;
}
div.box {
border: red solid 1px;
position: absolute;
width: 53.6%;
text-align: center;
background-color: transparent;
}
/*pseudo-element to give relative height,
per http://jsfiddle.net/simevidas/PFPDU/
and http://www.mademyday.de/css-height-equals-width-with-pure-css.html */
div.box::before {
content: "";
display: block;
padding-top: 100%;
height: 0;
}
/* if inner text has position relative, it influences the size of the containing box */
/*setting all of the positions to zero forces it inside the circle for some reason */
.circle_outer {
position: absolute;
overflow: hidden;
border: black solid 2px;
border-radius: 50%;
/* to create breathing room all around, set top and left to 1/2 of 100% - width (where width = height) */
top: 5%;
left: 5%;
width: 90%;
height: 90%;
}
.circle_inner {
/* border: grey solid 5px; */
display: table;
width: 100%;
height: 100%;
}
.inner-text {
display: table-cell;
/* border: green solid 2px; */
font-size: 2em;
vertical-align: middle;
}
/*First bounding box is at upper left corner */
div#picture {
overflow: hidden;
left: 0;
margin-top: 0;
}
/*Percent positions all based on W, derived from fact
that bounding boxes circumscribe tangent circles, and
circle centers are connected by equilateral triangles */
div#dog {
left: 46.4%;
margin-top: 26.8%;
}
div#shoes {
left: 0;
margin-top: 53.6%;
}
div#dance {
left: 46.4%;
margin-top: 80.4%;
}
div#footer_1 {
border: red solid 2px;
position: relative;
width: 100%;
left: 0;
margin-top: 137%;
text-align: center;
background-color: blue;
}
I much appreciate any thoughts or help. Thanks!
Well, IMO what you've done is really good. I wouldn't be too concerned about the extra divs.
But, it can be done with fewer divs, making use of float and margins.
Codepen is here
html {
font-size: 16px;
}
h1#home_title {
text-align: center;
font-size: 3rem;
margin: 0;
padding: .1rem 0 .5rem 0;;
background-color: grey;
}
div#container_1 {
border: green solid 5px;
width: 320px;
margin: auto;
position: relative;
box-sizing: border-box;
}
div.box {
border: red solid 1px;
position: relative;
float:left;
width: 53.6%;
text-align: center;
background-color: transparent;
box-sizing:border-box;
margin-bottom:-27%;
}
div.box:nth-child(2n) {
float:right;
}
div.box:nth-child(2n+1) {
float:left;
}
/*pseudo-element to give relative height,
per http://jsfiddle.net/simevidas/PFPDU/
and http://www.mademyday.de/css-height-equals-width-with-pure-css.html */
div.box::before {
content: "";
display: block;
padding-top: 100%;
height: 0;
}
/* if inner text has position relative, it influences the size of the containing box */
/*setting all of the positions to zero forces it inside the circle for some reason */
.featuring {
position: absolute;
overflow: hidden;
border: black solid 2px;
border-radius: 50%;
/* to create breathing room all around, set top and left to 1/2 of 100% - width (where width = height) */
top: 5%;
left: 5%;
width: 90%;
height: 90%;
font-size: 2em;
}
.featuring:before {
content:'';
margin-left:-0.25em;
display:inline-block;
vertical-align:middle;
height:100%;
}
/*Percent positions all based on W, derived from fact
that bounding boxes circumscribe tangent circles, and
circle centers are connected by equilateral triangles */
div#footer_1 {
border: red solid 2px;
position: relative;
width: 100%;
left: 0;
margin-top: 137%;
text-align: center;
background-color: blue;
clear:both;
}
<body>
<h1 id="home_title">test</h1>
<div id="container_1">
<div id="picture" class="box">
<div class="featuring">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/%22In_Which_We_Serve%22_Advertisement_1943.jpg/1024px-%22In_Which_We_Serve%22_Advertisement_1943.jpg" width=100%; />
</div>
</div>
<div id="dog" class="box">
<div class="featuring">
dog
</div>
</div>
<div id="shoes" class="box">
<div class="featuring">
shoes
</div>
</div>
<div id="dance" class="box">
<div class="featuring">
dance
</div>
</div>
<div id="footer_1">
Footer<br>
test
</div>
</div>
</body>
I have a container with 2 children.
One child has dynamic width and at it's maximum width can fill the container
The other child has fixed width and starts off being hidden as it's starting point is to the right of the overflow:hidden container
What I want is the fixed-width child to move to the left so that it exactly fits into the right of the container such that
a) If both children fit into the container - the other element should say put on the left and
b) If there is no room for both elements - the fixed-width element should push the other element to the left as much as it needs to in order to fit into the right of the container.
Here is what I tried:
Attempt #1
.container {
width: 200px;
height: 50px;
border: 1px solid green;
overflow: hidden;
white-space: noWrap;
}
span {
height: 50px;
display: inline-block;
}
.child1 {
background: aqua;
float: right;
width: 50px;
margin-right: -50px;
transition: margin .2s;
}
.container:hover .child1 {
margin-right: 0;
}
.child2 {
background: tomato;
//width: 100%;
}
<div class="container">
<span class="child1">Fixed</span>
<span class="child2">Dynamic Width</span>
</div>
<div class="container">
<span class="child1">Fixed</span>
<span class="child2">Here is a Dynamic Width box</span>
</div>
Condition a) Succeeds but condition b) Fails
Attempt #2
.container {
width: 200px;
height: 50px;
border: 1px solid green;
overflow: hidden;
white-space: noWrap;
}
span {
height: 50px;
display: inline-block;
}
.child2 {
background: aqua;
width: 50px;
margin: 0;
float: right;
margin-right: -50px;
transition: margin .2s;
}
.container:hover .child1 {
margin-left: -50px;
}
.container:hover .child2 {
margin: 0;
}
.child1 {
background: tomato;
transition: margin .2s;
}
<div class="container">
<span class="child1">Dynamic Width</span>
<span class="child2">Fixed</span>
</div>
<div class="container">
<span class="child1">Here is a Dynamic Width box</span>
<span class="child2">Fixed</span>
</div>
Condition a) Fails and condition b) Succeeds
Can both conditions be fulfilled with CSS alone?
PS: The markup which I provided in the demos may be modified. Also CSS3 including flexbox is also fine.
Here is a CSS only solution.
The trick is to use this basic rule:
Consider two or more inline elements rendered side by side.
If you increase the width of the first element, the second elements is pushed to the right.
The problem is that you need the elements to move to the left. I solved this by inverting the X direction to the child elements scaleX(-1) and re-inverting again the container.
To help you better understand this, you can comment out the transform: scaleX(-1); in the jsfiddle link below, and watch what happens.
The beauty of this is that you don't need to know the width of the .child2. You just need to push it to the left.
.container {
width: 200px;
height: 50px;
border: 1px solid green;
overflow: hidden;
white-space: nowrap;
text-align: right;
transform: scaleX(-1);
}
span {
height: 50px;
display: inline-block;
transform: scaleX(-1);
}
.child1 {
background: aqua;
width: 50px;
margin-left: -50px;
float: left;
transition: margin-left .2s;
text-align: left;
}
.child2 {
background: tomato;
}
.container:hover .child1 {
margin-left: 0;
}
<div class="container">
<span class="child1">Fixed</span>
<span class="child2">Dynamic Width</span>
</div>
<div class="container">
<span class="child1">Fixed</span>
<span class="child2">Here is a Dynamic Width box</span>
</div>
Also on jsfiddle
Solution 2
Another slightly simpler solution is to use direction: rtl; on the container. By reversing the direction of inline elements from right to left, we achieve the same effect without the need to use CSS3 transformations.
See http://jsfiddle.net/epfqjtft/12/
Since css can't do conditional statements (bar media queries), I don't think this is truly possible with css alone.
update
I have seen that it is in fact possible using CSS3 transforms (which works in modern browsers). but just in case some users might want older browser support which CSS3 transforms cant provide, i'll leave this here anyway.
Apart from that, I've used positioning instead of floats to 'clean up' the styling (and attempted the jquery):
$('.container').hover(function() {
var parentWidth = $(this).width();
var thisWidth = $(this).find(".child1").width() + 50; /*i.e. width of fixed box*/
if (parentWidth < thisWidth) { /*if it doesn't fit, move it!*/
$(this).find('.child1').addClass("moveLeft");
}
}, function() {
$(this).find(".child1").removeClass("moveLeft");
});
.container {
width: 200px;
height: 50px;
border: 1px solid green;
overflow: hidden;
white-space: noWrap;
position: relative;
}
span {
height: 50px;
display: inline-block;
}
.child2 {
background: aqua;
width: 50px;
margin: 0;
position: absolute;
top: 0;
right: -50px;
transition: all .2s;
}
.child1 {
background: tomato;
transition: all .2s;
position: absolute;
top: 0;
left: 0;
}
.container:hover .child2 {
right: 0;
}
.moveLeft:hover {
left: -50px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<span class="child1">Dynamic Width</span>
<span class="child2">Fixed</span>
</div>
<div class="container">
<span class="child1">Here is a Dynamic Width box</span>
<span class="child2">Fixed</span>
</div>
As for your 'solution', you will have to test if the child + 50px is greater than the parent width, if so, move child1. If not, no action is needed.
Okay, I changed LinkinTED's code a little bit. Try this:
http://jsfiddle.net/epfqjtft/9/
Of course, I don't know if it's something you can work with. These types of problems should be solved with Jquery.
.container {
width: 200px;
height: 50px;
border: 1px solid green;
display: table;
table-layout: fixed;
transition: all 2s;
}
span {
height: 50px;
display: table-cell;
transition: all .2s;
}
.child1 {
background: tomato;
width: 100%;
}
.child2 {
background: aqua;
width: 0px;
overflow: hidden;
transition: all .2s;
}
.container:hover .child2 {
width: 50px;
}
<div class="container">
<div class="wrapper">
<span class="child1">Dynamic Width</span>
</div>
<span class="child2">Fixed</span>
</div>
<div class="container">
<div class="wrapper">
<span class="child1">Here is a Dynamic Width box</span>
</div>
<span class="child2">Fixed</span>
</div>
.container {
width: 250px;
height: 40px;
border: 1px solid read;
overflow: hidden;
white-space: nowrap;
text-align: right;
transform: scaleX(-1);
}
span {
height: 50px;
display: inline-block;
transform: scaleX(-1);
}
.child1 {
background: pink;
width: 50px;
margin-left: -50px;
float: left;
transition: margin-left .3s;
text-align: left;
}
.child2 {
background: #####;
}
.container:hover .child1 {
margin-left: 0;
}
<div class="container">
<span class="child1">Fixed</span>
<span class="child2">Dynamic Width</span>
</div>
<div class="container">
<span class="child1">Fixed</span>
<span class="child2">Here is Dynamic Width box</span>
</div>
I'm writing an online chatting widget and I plan to design it as Facebook's.
In my page, a bar is fixed on the bottom, and every chat rooms are contained in that bar.
While the bar's height is fixed, the chat rooms cannot extend its height outside the bar.
Is there any method to achieve this? I have used z-index, !important, and overflow, but all failed.
CSS:
#SNbar {
background-color: rgba(203, 203, 203, 0.80);
position: fixed;
bottom: 0;
width: 100%;
height: 25px;
z-index: 900;
overflow: visible;
}
#chatSessions {
position: relative;
bottom: 0;
float:right;
z-index: 901;
}
.chatSession {
/*
position: fixed;
bottom: 0;
*/
padding: 0 10px 0 0;
width: 260px;
float: right;
z-index: 999;
}
.CStitle {
height: 25px;
background-color:#3B5998;
cursor: pointer;
}
.CStitle .titleText{
text-decoration: none;
font-weight:bold;
color: #FFFFFF;
text-decoration: none;
line-height:2em;
}
.CSbody {
background-color: #FFFFFF;
opacity: 1.0;
display: none;
height: 0 !important;
}
.opened{
min-height: 260px !important;
display: block;
}
.CSMsgContainer {
overflow-y: scroll;
height: 210px;
}
HTML:
<div id="SNbar">
<div id="chatSessions">
<div class="chatSession" id="Div4">
<div class="CStitle" onclick="toggleChatSession(this)"><span class="titleText">Title (With Whom)</span> </div>
<div class="CSbody">
<div class="CSMsgContainer">
<div class="message">b: test1</div>
<div class="message">b: this is used to test css</div>
<div class="message">a: This may be help</div>
</div>
</div>
</div>
<div class="chatSession" id="Div8">
<div class="CStitle" onclick="toggleChatSession(this)"><span class="titleText">Title (With Whom)</span></div>
<div class="CSbody">
<div class="CSMsgContainer">
<div id="Div9" class="message">d: hi C!!</div>
<div id="Div10" class="message">c: Hello D~~</div>
<div id="Div11" class="message">
c: We are the second chat session
</div>
</div>
</div>
</div>
</div>
</div>
position:absolute for the inner container is what you want. Then you can put it anywhere you want. Best is probably to set position:relative to the parent container, so that the position of the inner containers will using the parent as "base".
If I am not wrong, from this when you click on .CStitle, you are toggling the CSbody. So for this, you can set position relative to chatSession class and to the CSbody, give position absolute.
.chatSession {
position: relative;
padding: 0 10px 0 0;
width: 260px;
float: right;
z-index: 999;
}
.CStitle {
height: 25px;
background-color:#3B5998;
cursor: pointer;
}
.CSbody {
position:absolute;
background-color: #FFFFFF;
opacity: 1.0;
display: none;
height: 0;
bottom:25px;
}
.opened{
min-height: 260px;
display: block;
}
.CSMsgContainer {
overflow-y: scroll;
height: 210px;
}
Hope this helps.
try adding this
#SNbar {
height: 25px;
max-height: 25px;
}