How can I left align and right align my chat bubbles? - html

I have created two chat bubbles which one of them I need to be left aligned and other one I need to be right aligned .As of now my css grow both till the end like below image .
As of now I do not want to hardcode the width and want the bubble to grow with chat text and both one should be left aligned and other one should be right aligned like below:
CSS:
.speech-wrapper{
padding: 5px 6px;
}
.chatbox {
padding: 5px;
margin-left: 5px;
margin-right: 5px;
margin-top:0px;
background: #075698;
color: #FFF;
position: relative;
border-radius: 10px;
overflow-wrap: break-word;
word-wrap: break-word;
hyphens: auto;
box-shadow: 0 8px 6px -6px black;
}
.chatbox_other{
height:auto;
padding: 5px;
margin-left: 5px;
margin-right: 5px;
margin-top:0px;
background: #DCDCDC;
color: #000;
position: relative;
border-radius: 10px;
overflow-wrap: break-word;
word-wrap: break-word;
hyphens: auto;
box-shadow: 0 8px 6px -6px black;
}
.name_other{
font-weight: 600;
font-size: 12px;
margin: 0px 0px 9px;
color: #1970b0;
}
.name_other1{
font-weight: 600;
font-size: 12px;
margin: 0px 0px 9px;
color: #ba006e;
}
.name_other2{
font-weight: 600;
font-size: 12px;
margin: 0px 0px 9px;
color: #007670;
}
.name_other3{
font-weight: 600;
font-size: 12px;
margin: 0px 0px 9px;
color: #3b0256;
}
.name_other4{
font-weight: 600;
font-size: 12px;
margin: 0px 0px 9px;
color: #00512b;
}
.name_other5{
font-weight: 600;
font-size: 12px;
margin: 0px 0px 9px;
color: #a91024;
}
.name_other6{
font-weight: 600;
font-size: 12px;
margin: 0px 0px 9px;
color: #b8471b;
}
.name_other7{
font-weight: 600;
font-size: 12px;
margin: 0px 0px 9px;
color: #7f1c7d;
}
.timestamp_other{
font-size: 11px;
position: absolute;
bottom: 0px;
right: 10px;
text-transform: uppercase; color: #999
}
.timestamp{
font-size: 11px;
position: absolute;
bottom: 0px;
right: 10px;
text-transform: uppercase; color: #fff
}
/* speech bubble 13 */
.name{
font-weight: 600;
font-size: 12px;
margin: 0px 0px 9px;
color: #ffffff;
}
.triangle.left-top:after {
content: ' ';
position: absolute;
width: 0;
height: 0;
left: -10px;
right: auto;
top: 0px;
bottom: auto;
border: 22px solid;
border-color: #DCDCDC transparent transparent transparent;
z-index: -1;
}
.triangle.right-top:before {
content: ' ';
position: absolute;
width: 0;
height: 0;
left: auto;
right: -10px;
top: 0;
bottom: auto;
border: 32px solid;
border-color: #075698 transparent transparent
transparent;
z-index: -1;
}
.alt{
margin: 0 0 0 60px;
}
HTML:
<div class="speech-wrapper">
<div class="chatbox triangle right-top alt">
<div class="txt">
<p class="name">Apple TestUser1</p>Hi<span class="timestamp">10:20 pm</span></div>
</div>
<div class="speech-wrapper">
<div class="chatbox_other triangle left-top">
<div class="txt">
<p class="name">Apple TestUser1</p>Hi<span class="timestamp">10:20 pm</span>
</div>
</div>
</div>
</div>
I have tried uisng float left but while reducing the windows size the chat started overlapping on eachother
For testing out try below link
https://codepen.io/rajesh-kumar-dash/pen/KbvqQX

I think using float: right; for the right bubble and for the left bubble: float: left; with width: auto; should work

The "dirty" way to do it is by adding a after the divs just to clear the float:
<div class="speech-wrapper"><div class="chatbox triangle right-top alt"><div class="txt"><p class="name">Apple TestUser1</p>Hi<span class="timestamp">10:20 pm</span></div></div>
<div style="clear:both"></div>
<div class="speech-wrapper"><div class="chatbox_other triangle left-top"><div class="txt"><p class="name">Apple TestUser1</p>Hi<span class="timestamp">10:20 pm</span></div></div>
<div style="clear:both"></div>
The cleaner way to do it is called "Clearfix". I suggest you take a look on these two links to understand it and use on your code:
https://www.w3schools.com/css/css_float.asp
https://css-tricks.com/snippets/css/clear-fix/

If you want the size of your box as large as the text in it, you have to set "display: inline-block";
To make sure your box wont get bigger then a certain size use "max-width".
With "overflow-wrap: break-word" your text breaks if it reaches the max-width.

Related

I want this button on top of div box

I want this button on top of the div box, but I have no idea what css code I should use.
This below is what I want to do, but I have no idea how to do
What I want to do
I tried a lot of different ways including padding and margin, but I can't get it to work.
.wrapper {
background: white;
}
.TEST1{
float:right;
position: relative;
}
<div class="wrapper row"
style="padding: 10px 30px; position: fixed; bottom: 0; border-top: 1px solid #ccc; box-shadow: 0px 2px 10px #888888;">
<button type="button" class="TEST1" id="TEST!">Close</button>
<p class="col-md-10"
astyle="color: #262626; font-size: 12px; line-height: 17px; letter-spacing: .1px; padding: 0 30px 0 0;">TEST TEST TEST
</p>
<button class="col-xs-12 col-md-2 btn-close-cookie-notification"
style="background-color: black; border: none; color: white; padding: 13px; cursor: pointer; max-height: 40px; font-size: 12px; position: relative;">OK</button>
</div>
Please, Check this code
HTML File
<div class="wrapper">
<div
class="row"
style="
padding: 10px 30px;
position: fixed;
bottom: 0;
border-top: 1px solid #ccc;
box-shadow: 0px 2px 10px #888888;
"
>
<button type="button" class="TEST1" id="TEST!">Close</button>
<p
class="col-md-10"
astyle="color: #262626; font-size: 12px; line-height: 17px; letter-spacing: .1px; padding: 0 30px 0 0;"
>
TEST TEST TEST
</p>
<button
class="col-xs-12 col-md-2 btn-close-cookie-notification"
style="
background-color: black;
border: none;
color: white;
padding: 13px;
cursor: pointer;
max-height: 40px;
font-size: 12px;
position: relative;
"
>
OK
</button>
</div>
</div>
CSS File
.wrapper {
background: white;
position: relative;
}
.TEST1 {
position: absolute;
top: -10px;
right: -10px;
z-index: 999;
}
Demo link: https://stackblitz.com/edit/web-platform-nd9jej?file=styles.css
Note: Please add top and right css according your usability.
.TEST1 {
position: absolute;
top: -22px;
right: 0;
}

How to align my div to the right side of container per element?

Hope your all well.
Is it possible to align my div to the right side within my container? I try using align functions but does not seem to work. is it possible?
Note, the alignment solution should be for div (chatline) and HTML code only, as i need another div to align (chatline) on the right or left etc. so please don't use CSS alignment on the hold container.
Any help would be grateful here. thanks Yummi
body {
background-color: #6B6B6B;
margin: 50px;
font-family: Arial;
color: darkgrey;
font-size: 14px;
line-height: .3;
letter-spacing: .5px;
}
#chattext {
font-family: Arial;
color: grey;
font-size: 12px;
line-height: 1.1;
letter-spacing: .5px;
}
.chatbox {
position: absolute;
width: 400px;
padding: 15px;
padding-top: 5px;
border-radius: 0px 0px 30px 30px;
background-color: rgba(0, 0, 0, .4);
grid-template-columns: 500px;
display: grid;
}
.bubble {
position: absolute;
max-width: 200px;
padding: 15px;
padding-top: 10px;
border-radius: 0px 30px 30px 30px;
background-color: rgba(0, 0, 0, .3);
}
<div class="chatbox">
<div style="height:200px">
<p class="bubble" id="chattext">This should be right > please use htnl code on this div to align</p>
<p style="margin-top:70px;" class="bubble" id="chattext">stay left</p>
</div>
</div>
You can define new class and use it in every bubble you want it in right
.right_chat {
right:0;
}
another advice id prefer to use just for one element so in my code i change it to class and use it in html code
body {
background-color: #6B6B6B;
margin: 50px;
font-family: Arial;
color: darkgrey;
font-size: 14px;
line-height: .3;
letter-spacing: .5px;
}
.chattext {
font-family: Arial;
color: grey;
font-size: 12px;
line-height: 1.1;
letter-spacing: .5px;
}
.right_chat {
right:0;
}
.chatbox {
position: absolute;
width: 400px;
padding: 15px;
padding-top: 5px;
border-radius: 0px 0px 30px 30px;
background-color:rgba(0, 0, 0, .4);
grid-template-columns: 500px;
display: grid;
}
.bubble {
position: absolute;
max-width:200px;
padding: 15px;
padding-top: 10px;
border-radius: 0px 30px 30px 30px;
background-color:rgba(0, 0, 0, .3);
}
<div class="chatbox">
<div style="height:200px"><p class="bubble chattext right_chat" id="">This should be right > please use htnl code on this div to align</p><p style="margin-top:70px;" class="bubble chattext">stay left</p></div>
</div>
Is this what you want?
I didn't change the default behavior of the bubble class. Since the bubble is position: absolute I created one extra class named right that you can add on each bubble you want to be aligned on the right.
body {
background-color: #6B6B6B;
margin: 50px;
font-family: Arial;
color: darkgrey;
font-size: 14px;
line-height: .3;
letter-spacing: .5px;
}
#chattext {
font-family: Arial;
color: grey;
font-size: 12px;
line-height: 1.1;
letter-spacing: .5px;
}
.chatbox {
position: absolute;
width: 400px;
padding: 15px;
padding-top: 5px;
border-radius: 0px 0px 30px 30px;
background-color:rgba(0, 0, 0, .4);
grid-template-columns: 500px;
display: grid;
}
.bubble {
position: absolute;
max-width:200px;
padding: 15px;
padding-top: 10px;
border-radius: 0px 30px 30px 30px;
background-color:rgba(0, 0, 0, .3);
}
.message-wrapper .bubble.right {
right: 0;
}
<div class="chatbox">
<div class="message-wrapper" style="height:200px">
<p class="bubble right" id="chattext">This should be right > please use htnl code on this div to align</p>
<p style="margin-top:70px;" class="bubble" id="chattext">stay left</p>
</div>
</div>

HTML/CSS: Display image in semicircle in top of modal box

I have a requirement of displaying the image/icon on top of the modal box in a semicircle. Though I have achieved it with the help of below code, but the only issue is whenever my form in the modal box goes for a validation check, displaying any error, my semicircle doesn't get adjusted accordingly, rather it stays at its position. Here, I have attached the screen shot of what exactly I am looking for and HTML/css code I have used to display the semicircle with image/icon at the top.
.modal {
font-family: Avenir-Medium;
font-size: 16px;
font-weight: 900;
font-style: normal;
font-stretch: normal;
display: block;
/*Hidden by default */
position: fixed;
/* Stay in place */
z-index: 1;
/* Sit on top */
left: 0;
top: 0;
width: 100%;
/* Full width */
height: 100%;
/* Full height */
overflow: auto;
/* Enable scroll if needed */
background-color: rgb(0, 0, 0);
/* Fallback color */
background-color: rgba(0, 0, 0, 0.3);
/* Black w/ opacity */
-webkit-animation-name: slideIn;
/* Fade in the background */
-webkit-animation-duration: 2.0s;
/* Fade in the background */
;
}
/* Modal Content */
.modal-content {
position: fixed;
bottom: 0;
background-color: #fefefe;
width: 92%;
left: 14px;
-webkit-animation-name: fadeIn;
-webkit-animation-duration: 0.5s;
border-radius: 16px 16px 0px 0px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
border: none;
top: auto;
}
.modal-wrapper {
line-height: 45px;
border: 1px solid #e7e9ea;
border-radius: 6px 6px 0px 0px;
background-color: white;
margin: auto;
}
.modal-wrapper::after {
background: url("../../../../images/mobile/img-payment_38.png") no-repeat 22px 10px;
background-size: 50%;
background-color: #fff;
content: '';
width: 78px;
height: 45px;
position: absolute;
left: 0;
right: 0;
margin: auto;
border-radius: 78px 78px 0 0;
border-left: 1px solid #e7e9ea;
border-top: 1px solid #e7e9ea;
border-right: 1px solid #e7e9ea;
border-bottom: 3px solid white;
bottom: 300px;
}
.close-btn {
position: absolute;
vertical-align: top;
top: 4px;
left: 320px;
width: 18px;
height: 18px;
}
.container-div-creditCard {
margin: 12px 20px 0px 20px;
}
.container-div-creditCard>img {
position: absolute;
bottom: 154px;
right: 30px;
}
.credit-card-modal-label {
font-family: AvenirHeavy;
font-size: 13px;
color: #1d3444;
text-align: center;
font-weight: 200;
height: 24px;
margin-left: 31px;
}
.input-modal {
width: 100%;
height: 44px;
}
.input-spacing {
margin-top: 15px;
}
.credit-input-modal {
border: solid 1px #e7e9ea;
border-radius: 5px;
font-family: Avenir-Book;
font-size: 14px;
font-weight: normal;
color: #8589a1;
line-height: initial;
padding: 13px 42px 12px 15px;
}
.credit-expiry-input-modal {
padding: 13px 27px 12px 10px;
border: solid 1px #e7e9ea;
border-radius: 5px;
font-family: Avenir-Book;
font-size: 14px;
font-weight: normal;
color: #8589a1;
display: inline-block;
line-height: initial;
width: 65%;
height: 44px;
}
.credit-cvc-input-modal {
width: 30%;
padding: 17px 5px 12px 10px;
border: solid 1px #e7e9ea;
border-radius: 5px;
font-family: Avenir-Book;
font-size: 14px;
font-weight: normal;
color: #8589a1;
line-height: initial;
height: 44px;
}
.cvvDisc {
-webkit-text-security: disc;
}
.credit-submit-button {
width: 100%;
padding: 13px;
margin-top: 15px;
border: solid 1px #e7e9ea;
border-radius: 5px 5px 5px 5px;
background: linear-gradient(to right, #e32490, #ed1a3d);
color: white;
margin-bottom: 20px;
font-family: Avenir-Book;
font-weight: normal;
font-size: 14px;
line-height: initial;
}
.errorMsg {
font-family: Avenir-Book;
font-weight: normal;
color: #ED1A3D;
font-size: 12px;
}
<div id="modalCCDetails" class="modal">
<div class="modal-content modal-wrapper">
<div class="container-div-creditCard">
<label class="credit-card-modal-label">ENTER YOUR CREDIT CARD DETAILS</label>
<input name="cc_name" class="input-modal credit-input-modal" type="text" placeholder="Name printed on Credit Card" onChange={this.handleUserInput} />
<span class="errorMsg"></span>
<input name="cc_number" class="input-modal credit-input-modal input-spacing" type="tel" maxLength="16" onKeyPress={(e)=> this.handleCCOnKeyPress(e)} placeholder="16 digit credit card number" />
<span class="errorMsg"></span>
<input name="cc_expDate" class="credit-expiry-input-modal" type="text" placeholder="Expiry MM-YYYY" />
<div class="device-divider" />
<input name="cc_cvc" class="credit-cvc-input-modal cvvDisc" type="tel" placeholder="CVC" maxLength="3" />
<span class="errorMsg"></span>
</div>
<button class="credit-submit-button">Submit Payment</button>
</div>
</div>
</div>
NOTE: This is a mobile view screenshot
Just adjust your css code into something like this:
.modal-wrapper::after {
background: url("../../../../images/mobile/img-payment_38.png") no-repeat 22px 10px;
background-size: 50%;
background-color: #fff;
content: '';
width: 78px;
height: 45px;
position: absolute;
left: 0;
right: 0;
margin: auto;
border-radius: 78px 78px 0 0;
border: 1px solid #e7e9ea;
border-bottom: 3px`enter code here` solid white;
top: -48px;
}
Just remove the bottom: 300px; and replace with top: -48px; or any value that you want.
please add top:-15px; and removed bottom:300px; in class .modal-wrapper::after { top: -15px; }, u will see the image move up

HTML / CSS: Div not expanding to height of content

I've got a few div elements that aren't expanding to match the height of their content. I have read that this can be caused by float-ed content; This content isn't float-ed - although I am beginning to feel like I should throw my computer in a river. Does that count?
code:
#interaction-options-container.display-dialogue {
left: 15%;
width: 70%;
}
#interaction-options-container.full-border, .dialogue-container.full-border {
border: 1px solid #33ffff;
}
#interaction-options-container {
margin: 4px 0px 4px 0px;
z-index: 100;
position: absolute;
left: 35%;
bottom: 4%;
width: 30%;
line-height: 1.4;
opacity: 0.75;
}
#interaction-options-container .heading {
font-size: 16px;
color: black;
padding: 0.1px 12px 0.1px 12px;
background-color: grey;
}
.heading {
font-weight: bold;
font-size: 1.5em;
padding: 8px 12px 0px 12px;
}
#interaction-options-container p {
margin: 8px 0px 8px 0px;
}
#interaction-options-container .dialogue p {
margin: 4px 0px 4px 0px;
}
#interaction-options-container .button, #interaction-options-container .evidence-options-container .button {
cursor: pointer;
color: white;
font-size: 14px;
padding: 0.1px 12px 0.1px 12px;
background-color: #333333;
opacity: 0.85;
border-bottom: 1px solid #8d8d8d;
}
#interaction-options-container .dialogue-container {
padding: 0px;
margin: 0px;
width: 100%;
height: 32px;
background-color: #333333;
float: none;
}
#interaction-options-container .dialogue {
text-align: center;
margin: auto;
font-size: 16px;
font-weight: bold;
padding: 1px 12px 1px 12px;
color: white;
background-color: #333333;
}
.dialogue-container .dialogue.option-divider {
border-bottom: 1px solid #333333;
}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
<div class="hud-element display-dialogue full-border" id="interaction-options-container">
<div class="heading"><p>Choose a reply:</p></div>
<div class="dialogue-container button">
<div class="dialogue option-divider"><p>Option one here</p></div>
</div>
<div class="dialogue-container button">
<div class="dialogue option-divider"><p>Option two here</p></div>
</div>
<div class="dialogue-container button">
<div class="dialogue option-divider"><p>Option three here</p></div>
</div>
<div class="dialogue-container button">
<div class="dialogue"><p>Option four here. As an example this text should be long enough to require wrapping to a new line. I will therefore have to keep typing until I've added enough text to sufficiently fill the horizontal with of the containing div. Also, thanks for potentially answering my question, which I will get to below...</p></div>
</div>
</div>
The problem is, when a piece of dialogue requires wrapping to a new line, the .dialogue-container .button div does not expand in height to match the height of the .dialogue div. The inner divs therefore extend past the border lines, which looks bad.
If anyone has any pointers, my computer will thank you.
Cheers.
#interaction-options-container .dialogue-container {
padding: 0px;
margin: 0px;
width: 100%;
//height: 32px;
background-color: #333333;
float: none;
}

How to create a speech bubble with css only

I want to make a speech bubble and I'm almost achieving my goal. Just a simple thing that is driving me crazy.
Check HERE to see my code and what I need.
I tried this:
HTML:
<div class="date">
03 Fev 14
</div>
CSS:
.date{
display: block;
width: 50px;
font-weight: 400;
background-color: #00a1e0;
color: #FFFFFF;
font-size: 11px;
text-transform: uppercase;
padding: 10px 15px;
position: relative;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 0px;
margin-bottom: 20px;
}
.date:after {
content: '';
position: absolute;
border-style: solid;
border-width: 10px 6px 0;
border-color: #00a1e0 transparent;
display: block;
width: 0;
z-index: 1;
bottom: -10px;
left: 0px;
}
As you can see, at the moment I have a triangle with two angles of 45degrees, and I want it to have an angle of 90degrees on top aligned to the left.
How can I achieve this without the use of an additional image?
You need to add the last value for border-width. Try this:
.date:after {
border-width: 10px 10px 0 0;
}
.date {
display: block;
width: 50px;
font-weight: 400;
background-color: #00a1e0;
color: #FFFFFF;
font-size: 11px;
text-transform: uppercase;
padding: 10px 15px;
position: relative;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 0px;
margin-bottom: 20px;
}
.date:after {
content: '';
position: absolute;
border-style: solid;
border-width: 10px 10px 0 0;
border-color: #00a1e0 transparent;
display: block;
width: 0;
z-index: 1;
top: 100%;
left: 0px;
}
<h3>What I want: (image)</h3>
<img src="http://i.imgur.com/wlyK9EN.png">
<br>
<br>
<h3>What I have:</h3>
<div class="date">
03 Fev 14
</div>