Right position of DIVs in a pure CSS text chat simulation - html

I am trying to create the appearance of a text chat using pure CSS. The kind of text chat where one person's texts are represented by speech bubbles on the left of the screen, and the other persons are speech bubbles on the right side of the screen.
I'm almost there, and I've created a JSFiddle example. There are two problems.
The big problem is that the bubbles with the pointer on the right side, representing the person on the right, needs to be aligned on the right side. But I can't find a way to get them to align without floating them, and if I float them, then they overlap with other bubbles and create a mess.
How do I get the class bubble-right to stick to the right side?
The second issue is that I'm using display: inline-block; which makes it so that the bubbles are only as wide as the text. I had to put white-space: pre-line; in the containing DIV in order to get the bubbles to stack properly. Unfortunately, this is creating extra space. I tried putting in line-height declarations to prevent this, but it doesn't seem to have helped.
How do I get the bubbles to stack and alternate vertically without making extra whitespace I don't need?
Here is the CSS:
.bubble-dialog {
white-space: pre-line;
line-height:0;
}
.bubble-left,
.bubble-right {
line-height: 100%;
display: inline-block;
position: relative;
padding: .25em .5em;
background: pink;
border: red solid 3px;
-webkit-border-radius: 11px;
-moz-border-radius: 11px;
border-radius: 11px;
margin-bottom: 2em;
}
.bubble-left {
margin-right:10%;
}
.bubble-right {
margin-left:10%
}
.bubble-left:after,
.bubble-left:before,
.bubble-right:after,
.bubble-right:before {
content: "";
position: absolute;
top: 21px;
border-style: solid;
border-width: 13px 17px 13px 0;
border-color: transparent pink;
display: block;
width: 0;
}
.bubble-left:after,
.bubble-left:before {
border-width: 13px 17px 13px 0;
border-color: transparent pink;
}
.bubble-right:after,
.bubble-right:before {
border-width: 13px 0 13px 17px;
border-color: transparent pink;
}
.bubble-left:after {
left: -16px;
border-color: transparent pink;
z-index: 1;
}
.bubble-left:before {
left: -19px;
border-color: transparent red;
z-index: 0;
}
.bubble-right:after {
right:-16px;
border-color: transparent pink;
z-index: 1;
}
.bubble-right:before {
right:-19px;
border-color: transparent red;
z-index: 0;
}

I don't understand your second problem very well, but as for first problem you can add this css to your left and right classes:
I add clear:both and display:block and add float as you said, and right bubbles will stick at right side; here is a fiddle:
.bubble-left,
.bubble-right {
line-height: 100%;
display: block;
position: relative;
padding: .25em .5em;
background: pink;
border: red solid 3px;
-webkit-border-radius: 11px;
-moz-border-radius: 11px;
border-radius: 11px;
margin-bottom: 2em;
clear: both;
max-width:50%;
}
.bubble-left {
float: left;
margin-right:10%;
}
.bubble-right {
float:right;
margin-left:10%
}
And as for your second problem, I don't know why the spaces are there, but with removing bottom margin of the <p> tag it gets OK so I add margin-bottom:0 to <p> tag;

Related

Border bottom and the header move together

In my nav, I am separating my section with some text and a horizontal line. For each section this repeats. I am doing this as shown below:
.navSectionHeader {
font-size: 1em;
color: #fff;
margin-left: 5px;
margin-bottom: 10px;
font-family: "Roboto";
font-weight: 700 !important;
border-bottom: 2px solid #6c6c6c;
}
/*.navSectionHeader::after {
content: ' ';
display: block;
border: 2px solid;
border-color: #6c6c6c;
margin-left: 0px !important;
}*/
The issue is, my text is now pretty much stuck to the left of the parent div. It should be with some margin to the left while keeping the bottom border start from 0px to the left. When I try to move it with margin-left: 5px; it ends up moving the border-bottom as well. I tried this with ::after as shown in the commented bit, adding !important to the end but nothing changes. Am I doing this the wrong way? Sorry, I'm a front-end noob!
Edit: The section header is in a <span> if it makes a difference.
Use padding instead of margin.
.navSectionHeader {
padding-left: 5px;
}
An example to see difference,
div {
display: inline-block;
width: 100px;
height: 20px;
border-bottom: 1px solid black;
background: red;
color: white;
}
.padding {
padding-left: 5px;
}
.margin {
margin-left: 5px;
}
<div class="margin">margin</div><br>
<div class="padding">padding</div>

Show button after the text but not outside the cell

I have the following code:
<td>
<div>
<span class ="name">Can be long, can be short</span>
<button>Test</button>
</div>
</td>
td{
white-space: no-wrap;
width:175px;
position: relative
}
button{
position:absolute;
right: 15px;
bottom: 5px;
}
What I get is
I want to show name in one line (even if it is outside the cell), but button should be always in cell (on the same line).
If name is short then it should be right after the name, if not then stick to the right of cell.
I used absolute positioning, but in this case button always sticks to the right of the cell. Not what I need for short names.
So, picture for long name is what I need, but for short name I want yellow button to show near name, not stick to the right side.
Working jsfiddle: https://jsfiddle.net/8kchkucv/
Is it possible to do this with CSS?
Andrew what you are asking is not possible with having only one css for both the buttons, either you can have something like this jsfiddle
https://jsfiddle.net/rohts76/8kchkucv/1
.but
{
cursor: pointer;
padding: 2px 5px;
margin: 5px 0px 0px 5px;
border-radius: 5px;
font-family: 'Pacifico', cursive;
font-size: 10px;
color: #FFF;
text-decoration: none;
background-color: #F2CF66;
border-bottom: 1px solid #D1B358;
text-shadow: 0px -2px #D1B358;
position:absolute;
//right: 15px;
bottom: 5px;
}
.cell{
white-space: nowrap;
width:175px;
position:relative;
}
.cell div{
margin: 0;
padding: .35em;
float: left;
width: 100%;
height: 100%;
}
tr{
background-color: #8db4e3;
background-size: 100% 100%;
}
This code will give you correct thing..

dropdown menu is visible even if you don't have your mouse on the dropdown menu

I just created a button with a dropdown menu, you can view the demo here.
In the demo I added a black background to shopping-cart-wrapper element so you can see where the problem lies.
The problem is when you hover over the button you can keep your mouse on the black background and the dropdown menu is still visible.
I only want the dropdown menu to be visible when you hover over the button or keep your mouse on the dropdown menu.
Here is the code I have:
HTML:
<div class="shopping-cart-wrapper">
<a class="shopping-cart" href="#" alt="my-shopping-cart">My Shopping Cart (0)</a>
<div class="shopping-cart-dropdown">
<div class="empty-cart"><span>Your shopping cart is empty</span></div>
</div>
</div>
CSS:
.shopping-cart-wrapper:hover .shopping-cart-dropdown {
opacity: 1;
display: block;
}
.shopping-cart-wrapper {
display: inline-block;
background: #000;
margin-top: 5px;
margin-left: 15px;
}
.shopping-cart {
border: 1px solid #d3d3d3;
color: #656565;
padding-right: 10px;
padding-top: 8px; padding-bottom: 8px;
padding-left: 40px;
font-weight: bold;
display: inline-block;
font-size: 13px;
text-align: right;
text-decoration: none;
box-shadow: 0px 1px 0px #f2f2f2;
background: #f8f8f8 url("http://placehold.it/32x32") no-repeat 0 0 ;
position: relative;
}
.shopping-cart:hover {
background: #fff url("images/cart-sprite.png") no-repeat 0 -29px ;
color: #202020;
border: 1px solid #c6c6c6;
box-shadow: 0px 1px 0px #e5e5e5;
}
.shopping-cart-dropdown {
opacity: 0;
display: none;
border: 1px solid #d3d3d3;
padding-bottom: 80px;
position: relative;
right: 49px;
width: 247px;
background: #f6f6f6;
font-size: 12px;
font-weight: bold;
}
.empty-cart{
background: #202020;
padding: 10px;
color: #fff;
text-align: center;
position: relative;
}
What's Going On
The problem here really isn't a problem, because everything is working as it is supposed to. When you hover over the container, the child is visible. Then the child is visible, the parent becomes larger to encompass it.
Current Selector:
To fix this, you have a couple options. The easiest would be to use a sibling selector instead of a parent. Select the a inside .shopping-cart-wrapper instead of .shopping-cart-wrapper itself, and use the + sibling selector.
We've got to be careful though, because we want the child to stay visible when the mouse is hovering over itself. When using the parent as a selector, this is automatic. With a sibling, we have to manually do this. We'll use both the sibling and the child itself as selectors.
Code
Working Example
Current:
.shopping-cart-wrapper:hover .shopping-cart-dropdown {
opacity: 1;
display: block;
}
Working:
.shopping-cart-wrapper a:hover + .shopping-cart-dropdown,
.shopping-cart-dropdown:hover {
opacity: 1;
display: block;
}
Further Information
http://reference.sitepoint.com/css/adjacentsiblingselector

Use CSS to make an arrow instead of rounding corners

I have a link which is a box like the SO 'Ask Question' button but I want the right of it to point like an arrow.
This http://jsfiddle.net/U4zXS/1/ is what I have so far. I have the right side rounded but I need it to be in a point like an arrow.
<a class="arrow_link" href="{$base_url}signup">GET STARTED WITH OUR <span class="purple">FREE TRIAL</span></a>
.arrow_link{
float: left;
background-color: $color-orange;
border-radius: 0 25px 25px 0;
padding: 4px 15px 6px 8px;
margin-top: -5px;
font-weight: bold;
color: $color-white;
}
a{
text-decoration: none;
}
You can try with the borders triangle method:
.arrow_link::after {
content: "";
display: block;
position: absolute;
top: 0;
left: 100%;
border-style: solid;
border-color: transparent #F78E1E;
border-width: 15px 0 15px 15px;
width: 0;
height: 0;
}
Notice that you'll also have to add position: relative to the .arrow_link itself.
Here's the updated fiddle: FIDDLE
You can use the CSS :after psuedo-element as followed:
.arrow_link { position: relative; }
.arrow_link:after {
content: '';
display: block;
border: 10px solid transparent;
border-left-color: red;
top: 0;
right: -20px;
}
This will append a psuedo-element to your a, which will show the arrow using the border trick as explained very well on CSS Tricks.
You can use a pseudo element to make the triangle at the end of the element. Here is some more info about pseudo elements that should help you get started with them.
Here is the changed css:
.arrow_link{
float: left;
background-color: $color-orange;
padding: 4px 15px 6px 8px;
margin-top: -5px;
font-weight: bold;
color: $color-white;
position: relative;
}
.arrow_link:after {
content: "";
display: block;
position: absolute;
border-left: 15px solid #f78e1e;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
left: 100%;
top: 0;
}
Finally, a fiddle: Demo
The only problem you will have is due to your element not having a fixed height, won't be a problem if your element doesn't change. CSS triangles are not the most flexible thing to use but they do the trick.
Have a look at this http://jsfiddle.net/WW32n/1/ and some references here http://nicolasgallagher.com/pure-css-speech-bubbles/demo/
<p class="triangle-isosceles right">The entire appearance is created only with CSS.</p>
and the css
.triangle-isosceles {
position:relative;
padding:15px;
margin:1em 0 3em;
color:#000;
background:#f3961c; /* default background for browsers without gradient support */
/* css3 */
background:-webkit-gradient(linear, 0 0, 0 100%, from(#f9d835), to(#f3961c));
background:-moz-linear-gradient(#f9d835, #f3961c);
background:-o-linear-gradient(#f9d835, #f3961c);
background:linear-gradient(#f9d835, #f3961c);
-webkit-border-radius:10px;
-moz-border-radius:10px;
border-radius:10px;
}
/* creates triangle */
.triangle-isosceles:after {
content:"";
position:absolute;
bottom:-15px; /* value = - border-top-width - border-bottom-width */
left:50px; /* controls horizontal position */
border-width:15px 15px 0; /* vary these values to change the angle of the vertex */
border-style:solid;
border-color:#f3961c transparent;
/* reduce the damage in FF3.0 */
display:block;
width:0;
}

Splitting a css border with a background icon

I'm trying to divide a border with a background image. I don't know if this is even possible this way. Hopefully somebody can help me figure out a good clean way to achieve this.
I'm trying to get the bottom one and that top one is what I have right now.
.tinybanner h1 {
padding-bottom: 0.5em;
margin-bottom: 50px;
border-bottom: 1px solid $green;
display: inline-block;
#include adjust-font-size-to(24px);
background: url('images/tinybanner.png') center bottom no-repeat;
}
By using the pseudo-selector :after, you can add an element after every h1:
h1 {
padding-bottom: 0.5em;
margin-bottom: 50px;
border-bottom: 1px solid green;
display: inline-block;
position: relative;
}
h1:after {
position: absolute;
left: 50%; /* center the element */
margin-left: -15px; /* shift left by (width+border)/2 */
display: block;
content: '';
width: 20px;
height: 20px;
background: green; /* this can of course be a background image, too */
border: 10px solid white; /* adds a gap to the left and right */
}
The reason why I like this approach is because it degrades nicely. If your browser doesn't support the :after pseudo-selector, you are still left with the border underneath the header (because it is set on the h1, not the pseudo element) and don't see a dangling background image (because it is set on the h1:after).
http://jsfiddle.net/stevemchey/YFXGa/
How about using an :after sudo-element with left and right borders:
.tinybanner h1 {
padding-bottom: 0.5em;
margin-bottom: 50px;
display: inline-block;
#include adjust-font-size-to(24px);
background: url('http://placekitten.com/10/20') center bottom no-repeat;
}
.tinybanner h1:after {
height:1px;
content:'';
display:block;
border-left: 40px solid #00ff00;
border-right:40px solid #00ff00;
}
http://jsfiddle.net/bhlaird/XSdbs/