Why is this not workin on SCSS - css

I am trying to make this to work and I don't why isn't working since this is one of the idiosyncrasies of SCSS:
This is the HTML:
<div class="btn btn-wrapper">
<div class="btn-container mob-only">
<a class="btn btn-red" href="#" target="_blank">
<span class="mob-only">Schedule Appointment</span>
</a>
</div>
</div>
SCSS:
.btn {
&-wrapper {
width: 100%;
// border: 1px solid red;
position: absolute;
left: 0;
right: 0;
bottom: 0;
margin: -7vw 0px;
&-container {
&-red {
color: white;
background: $red;
padding: 10px;
width: 85%;
border-radius: 0;
margin: 10px;
font-size: 7vw;
}
}
}
}
What am I doing wrong?

&- will prepend the parent selector to the rule.
So,
&-wrapper will be .btn-wrapper
&-container will be .btn-wrapper-container
&-red will be .btn-wrapper-container-red
You can solve it by reducing the nesting, but this wont help if you want to select only .btn-red inside .btn-container.
For selecting the most relevant element and having the same nesting structure like you have, you can create a variable name in the parent selector and assign that in the nesting. I have added both the approaches below.
Approach 1
.btn {
&-wrapper {
width: 100%;
// border: 1px solid red;
position: absolute;
left: 0;
right: 0;
bottom: 0;
margin: -7vw 0px;
}
&-red {
color: white;
background: $red;
padding: 10px;
width: 85%;
border-radius: 0;
margin: 10px;
font-size: 7vw;
}
}
Approach 2
.btn {
$root: &;
#{$root}-wrapper {
width: 100%;
// border: 1px solid red;
position: absolute;
left: 0;
right: 0;
bottom: 0;
margin: -7vw 0px;
#{$root}-container {
#{$root}-red {
color: white;
background: 'red';
padding: 10px;
width: 85%;
border-radius: 0;
margin: 10px;
font-size: 7vw;
}
}
}
}

All your selectors are nested and are extending each other by name. In your case you are generating the three classes .btn, .btn-wrapper and .btn-wrapper-container-red.
You are probably looking to do:
.btn {
&-wrapper { ... }
&-container { ... }
&-red { ... }
}
This will generate the four classes .btn, .btn-wrapper, .btn-container and .btn-red.

at first sight, you nested selectors in a wrong way, your code generates styles for btn-wrapper, btn-wrapper-container, btn-wrapper-container-red, this will generate btn-wrapper btn-container btn-red selectors:
html:
<div class="btn btn-wrapper">
<div class="btn-container mob-only">
<a class="btn btn-container-red" href="#" target="_blank">
<span class="mob-only">Schedule Appointment</span>
</a>
</div>
</div>
scss:
.btn {
&-wrapper {
width: 100%;
// border: 1px solid red;
position: absolute;
left: 0;
right: 0;
bottom: 0;
margin: -7vw 0px;
}
&-container {
&-red {
color: white;
background: $red;
padding: 10px;
width: 85%;
border-radius: 0;
margin: 10px;
font-size: 7vw;
}
}
}

Related

How to transform/transition div without moving the text?

I created an overlay menu for the responsive menu of website. every thing is OK but when the menu will be closed, the texts (in menu) will be gathered and moved individually and then disappear but I want them to slide out without moving texts.
I tried these HTML:
<section class="overlaysection">
<div id="myoverlaynav" class="overlay">
×
<div class="overlay-content">
<li><a>num one one one one</a></li>
<li><a>num two two two two</a></li>
<li><a>num three three three three</a></li>
<li><a>num four four four four four</a></li>
</div>
</div>
<div class="overlaybtndiv" onclick="openNav()">
<button class="overlaybtn">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<h2>The Menu</h2>
</div>
</section>
CSS Codes:
#media (min-width: 631px){
.overlaysection {
display: none;
}
}
.overlaysection .overlay {
height: 100%;
width: 0;
position: fixed;
/* z-index: 1; */
z-index: 999999;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
direction:rtl;
}
.overlaysection a.closebtn {
position: absolute;
font-size: 40px;
padding: 0;
line-height: 40px;
top: 10px;
right: 10px;
color: #eee;
}
.overlaysection .overlay-content {
position: relative;
width: 100%;
text-align: center;
margin-top: 40px;
}
.overlaysection .overlay a {
display: block;
transition: 0.3s;
text-align: left;
color: #eee;
padding: 8px 8px 8px 20px;
text-decoration: none;
}
.overlaysection .overlay a:hover,
.overlaysection .overlay a:focus {
color: #f1f1f1;
}
.overlaysection .overlaybtndiv {
display: block;
padding: 6px 8px;
position: relative;
}
.overlaysection .overlaybtndiv h2 {
font-size: 14px;
color: black;
line-height: 40px;
margin-right: 10px;
}
.overlaysection .overlaybtn {
border-color: transparent !important;
float: right;
padding: 5px;
background: white;
outline: 0;
}
.overlaysection .overlaybtn .icon-bar {
display: block;
height: 2px;
border-radius: 1px;
padding: 1.5px;
width: 28px;
background-color: black !important;
margin-top: 5px;
}
.overlaysection .overlaybtn .icon-bar:first-child {
margin-top: 3px !important;
}
.
javascript codes:
function openNav() {
document.getElementById("myoverlaynav").style.width = "80%";
}
function closeNav() {
document.getElementById("myoverlaynav").style.width = "0%";
}
you can see this menu in https://end-eng.com/grammar/auxiliary-modal-verbs-in-english/ and this menu is like https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_sidenav
Add min-width and float:left to .overlay-content.
.overlaysection .overlay-content {
position: relative;
width: 100%;
text-align: center;
margin-top: 50px;
min-width: 270px;
float: left;
}
right now what happening is when close navbar its width is reduced so thus your li tag width to so, just give your li tag fixed width and your problem will be solved like.
#media (min-width: 631px){
.li {
width : 200px;
}
}
and only give this in media query for smaller devices otherwise it will replicate in whole website.
It's because you're using width's to control the display.
Instead of this, I suggest that you toggle a "shown" class to your overlay.
By default on your ".overlaysection .overlay" css, change the width to 100% and left to -100%;
Then on the "shown" class set the left to 0. Change the JS to toggle the
shown class and it should then slide out from the left without changing the text orientation.
function openNav() {
document.getElementById("myoverlaynav").classList.toggle('shown');
}
function closeNav() {
document.getElementById("myoverlaynav").classList.toggle('shown');
}
#media (min-width: 631px){
.overlaysection {
display: none;
}
}
.overlaysection .overlay {
height: 100%;
width: 100%;
position: fixed;
/* z-index: 1; */
left: -100%;
z-index: 999999;
top: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
direction:rtl;
}
.overlaysection a.closebtn {
position: absolute;
font-size: 40px;
padding: 0;
line-height: 40px;
top: 10px;
right: 10px;
color: #eee;
}
.overlaysection .overlay-content {
position: relative;
width: 100%;
text-align: center;
margin-top: 40px;
}
.overlaysection .overlay a {
display: block;
transition: 0.3s;
text-align: left;
color: #eee;
padding: 8px 8px 8px 20px;
text-decoration: none;
}
.overlaysection .overlay a:hover,
.overlaysection .overlay a:focus {
color: #f1f1f1;
}
.overlaysection .overlaybtndiv {
display: block;
padding: 6px 8px;
position: relative;
}
.overlaysection .overlaybtndiv h2 {
font-size: 14px;
color: black;
line-height: 40px;
margin-right: 10px;
}
.overlaysection .overlaybtn {
border-color: transparent !important;
float: right;
padding: 5px;
background: white;
outline: 0;
}
.overlaysection .overlaybtn .icon-bar {
display: block;
height: 2px;
border-radius: 1px;
padding: 1.5px;
width: 28px;
background-color: black !important;
margin-top: 5px;
}
.overlaysection .overlaybtn .icon-bar:first-child {
margin-top: 3px !important;
}
#myoverlaynav.shown {
left: 0;
}
<section class="overlaysection">
<div id="myoverlaynav" class="overlay">
×
<div class="overlay-content">
<li><a>num one one one one</a></li>
<li><a>num two two two two</a></li>
<li><a>num three three three three</a></li>
<li><a>num four four four four four</a></li>
</div>
</div>
<div class="overlaybtndiv" onclick="openNav()">
<button class="overlaybtn">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<h2>The Menu</h2>
</div>
</section>

Change background based on different hovered element

When hovering on each circle at the corner, background color in the main area should be changed so matches the color of the circle, and there is an adequate paragraph showing at the same time.
I have tried transition, opacity... but couldn't get it work.
Note, HTML has to be untouched.
* {
margin: 0;
padding: 0;
}
body {
position: relative;
height: 100vh;
text-align: center;
}
p {
font-family: Arial, Helvetica, sans-serif;
color: white;
}
.bg {
position: relative;
height: 100vh;
background-color: #333;
}
.circle {
height: 10px;
width: 10px;
border-radius: 50%;
border: white solid 2px;
z-index: 1;
}
.red.circle {
position: absolute;
top: 10%;
left: 10%;
background-color: red;
}
.green.circle {
position: absolute;
top: 10%;
right: 10%;
background-color: green;
}
.blue.circle {
position: absolute;
bottom: 10%;
left: 10%;
background-color: blue;
}
.orange.circle {
position: absolute;
bottom: 10%;
right: 10%;
background-color: orange;
}
p.red {
display: none;
background-color: red;
line-height: 100vh;
}
p.green {
display: none;
background-color: green;
line-height: 100vh;
}
p.blue {
display: none;
background-color: blue;
line-height: 100vh;
}
p.orange {
display: none;
background-color: orange;
line-height: 100vh;
}
<div class="red circle"></div>
<div class="green circle"></div>
<div class="blue circle"></div>
<div class="orange circle"></div>
<div class="bg">
<p class="red">Czerwony</p>
<p class="green">Zielony</p>
<p class="blue">Niebieski</p>
<p class="orange">Pomarańczowy</p>
</div>
Since they are somewhat in the same hierarchy, you can take advantage of the ~ general sibling selector which matches the second element only if it follows the first element (though not necessarily immediately):
/* added */
.red.circle:hover ~ .bg {
background-color: red;
}
.green.circle:hover ~ .bg {
background-color: green;
}
.blue.circle:hover ~ .bg {
background-color: blue;
}
.orange.circle:hover ~ .bg {
background-color: orange;
}
.red.circle:hover ~ .bg p.red { display: block; }
.green.circle:hover ~ .bg p.green { display: block; }
.blue.circle:hover ~ .bg p.blue { display: block; }
.orange.circle:hover ~ .bg p.orange { display: block; }
/* end of edit */
* {
margin: 0;
padding: 0;
}
body {
position: relative;
height: 100vh;
text-align: center;
}
p {
font-family: Arial, Helvetica, sans-serif;
color: white;
}
.bg {
position: relative;
height: 100vh;
background-color: #333;
transition: background-color 0.5s ease-in;
}
.circle {
height: 10px;
width: 10px;
border-radius: 50%;
border: white solid 2px;
z-index: 1;
}
.red.circle {
position: absolute;
top: 10%;
left: 10%;
background-color: red;
}
.green.circle {
position: absolute;
top: 10%;
right: 10%;
background-color: green;
}
.blue.circle {
position: absolute;
bottom: 10%;
left: 10%;
background-color: blue;
}
.orange.circle {
position: absolute;
bottom: 10%;
right: 10%;
background-color: orange;
}
p {
transition: background-color 1s ease-in;
}
p.red {
display: none;
background-color: red;
line-height: 100vh;
}
p.green {
display: none;
background-color: green;
line-height: 100vh;
}
p.blue {
display: none;
background-color: blue;
line-height: 100vh;
}
p.orange {
display: none;
background-color: orange;
line-height: 100vh;
}
<div class="red circle"></div>
<div class="green circle"></div>
<div class="blue circle"></div>
<div class="orange circle"></div>
<div class="bg">
<p class="red">Czerwony</p>
<p class="green">Zielony</p>
<p class="blue">Niebieski</p>
<p class="orange">Pomarańczowy</p>
</div>
You can add transition on the .bg class for the desired effect.
I would simplify your code to rely on pseudo element and data-attribute for background and content. It will be then easier to control as you don't need any complex selector:
body {
margin: 0;
background: #333;
min-height: 100vh;
}
.circle {
position: absolute;
height: 10px;
width: 10px;
border-radius: 50%;
border: white solid 2px;
}
.circle::before {
content: attr(data-text);
font-family: Arial, Helvetica, sans-serif;
text-align: center;
color: white;
line-height: 100vh;
font-size: 80px;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: -2;
background: inherit;
opacity: 0;
transition: 1s;
}
.circle:hover::before {
opacity: 1;
}
.circle.red {
top: 10%;
left: 10%;
background: red;
}
.circle.green {
top: 10%;
right: 10%;
background: green;
}
.circle.blue {
bottom: 10%;
left: 10%;
background: blue;
}
.circle.orange {
bottom: 10%;
right: 10%;
background: orange;
}
<div class="circle red" data-text="Czerwony"></div>
<div class="circle green" data-text="Zielony"></div>
<div class="circle blue" data-text="Niebieski"></div>
<div class="circle orange" data-text="Pomarańczowy"></div>
The css only solution of #soulshined is great, but just in case anyone wants to use javascript - here's a hint:
const bg = document.querySelector(".bg");
const circles = document.querySelectorAll(".circle");
circles.forEach(circle => circle.addEventListener("mouseenter", (e) => {
const style = getComputedStyle(e.target);
const backgroundColor = style.backgroundColor;
bg.style.backgroundColor = backgroundColor;
}))

css vertical form steps indicator?

I'm trying to create a vertical form steps indicator using css.
I found this https://codepen.io/erwinquita/pen/ZWzVRE which works fine in the codepen but when I try to copy the code from there and use it in my html page, the green circles do not show up!
I even copied the code and pasted it in jsfiddle but the same issue accrued.
this is the code:
.wrapper {
width: 330px;
font-family: 'Helvetica';
font-size: 14px;
border: 1px solid #CCC;
}
.StepProgress {
position: relative;
padding-left: 45px;
list-style: none;
&::before {
display: inline-block;
content: '';
position: absolute;
top: 0;
left: 15px;
width: 10px;
height: 100%;
border-left: 2px solid #CCC;
}
&-item {
position: relative;
counter-increment: list;
&:not(:last-child) {
padding-bottom: 20px;
}
&::before {
display: inline-block;
content: '';
position: absolute;
left: -30px;
height: 100%;
width: 10px;
}
&::after {
content: '';
display: inline-block;
position: absolute;
top: 0;
left: -37px;
width: 12px;
height: 12px;
border: 2px solid #CCC;
border-radius: 50%;
background-color: #FFF;
}
&.is-done {
&::before {
border-left: 2px solid green;
}
&::after {
content: "✔";
font-size: 10px;
color: #FFF;
text-align: center;
border: 2px solid green;
background-color: green;
}
}
&.current {
&::before {
border-left: 2px solid green;
}
&::after {
content: counter(list);
padding-top: 1px;
width: 19px;
height: 18px;
top: -4px;
left: -40px;
font-size: 14px;
text-align: center;
color: green;
border: 2px solid green;
background-color: white;
}
}
}
strong {
display: block;
}
}
<div class="wrapper">
<ul class="StepProgress">
<li class="StepProgress-item is-done"><strong>Post a contest</strong></li>
<li class="StepProgress-item is-done"><strong>Award an entry</strong>
Got more entries that you love? Buy more entries anytime! Just hover on your favorite entry and click the Buy button
</li>
<li class="StepProgress-item current"><strong>Post a contest</strong></li>
<li class="StepProgress-item"><strong>Handover</strong></li>
<li class="StepProgress-item"><strong>Provide feedback</strong></li>
</ul>
</div>
I don't understand what I am missing.
could someone please advice on this issue?
In the codepen link you've provided, LESS CSS Preprocessor has been used. That's why you couldn't replicate the same code with jsfiddle or your local instance. Simply, the CSS isn't working in your case, you are viewing the plain html because when you use the css preprocessor, browser can't render it directly.
If you want this code to work in jsfiddle, then you have to select SCSS as the language in the dropdown menu named as css in the css box. Here's the link that shows it is working: https://jsfiddle.net/9k67r0eg/1/
And if you want to use it in your local browser, then you may want to compile it. Check it here: http://lesscss.org/
However, the LESS can be converted to pure css also. Here's the converted code which you can use directly:
.wrapper {
width: 330px;
font-family: 'Helvetica';
font-size: 14px;
border: 1px solid #CCC;
}
.StepProgress {
position: relative;
padding-left: 45px;
list-style: none;
}
.StepProgress::before {
display: inline-block;
content: '';
position: absolute;
top: 0;
left: 15px;
width: 10px;
height: 100%;
border-left: 2px solid #CCC;
}
.StepProgress-item {
position: relative;
counter-increment: list;
}
.StepProgress-item:not(:last-child) {
padding-bottom: 20px;
}
.StepProgress-item::before {
display: inline-block;
content: '';
position: absolute;
left: -30px;
height: 100%;
width: 10px;
}
.StepProgress-item::after {
content: '';
display: inline-block;
position: absolute;
top: 0;
left: -37px;
width: 12px;
height: 12px;
border: 2px solid #CCC;
border-radius: 50%;
background-color: #FFF;
}
.StepProgress-item.is-done::before {
border-left: 2px solid green;
}
.StepProgress-item.is-done::after {
content: "✔";
font-size: 10px;
color: #FFF;
text-align: center;
border: 2px solid green;
background-color: green;
}
.StepProgress-item.current::before {
border-left: 2px solid green;
}
.StepProgress-item.current::after {
content: counter(list);
padding-top: 1px;
width: 19px;
height: 18px;
top: -4px;
left: -40px;
font-size: 14px;
text-align: center;
color: green;
border: 2px solid green;
background-color: white;
}
.StepProgress strong {
display: block;
}
<div class="wrapper">
<ul class="StepProgress">
<li class="StepProgress-item is-done"><strong>Post a contest</strong></li>
<li class="StepProgress-item is-done"><strong>Award an entry</strong> Got more entries that you love? Buy more entries anytime! Just hover on your favorite entry and click the Buy button
</li>
<li class="StepProgress-item current"><strong>Post a contest</strong></li>
<li class="StepProgress-item"><strong>Handover</strong></li>
<li class="StepProgress-item"><strong>Provide feedback</strong></li>
</ul>
</div>

Positioning left/right toggle/trigger and corresponding menu of a dropdown menu

I'm trying to position left and right variations of a dropdown menu.
My problem is with the toggle(dropdown__toggle) I try to position right, but it doesn't work; I want the toggle to be above the menu triangle;
I use a position:relative for it, if I try position:absolute it's creating a mess.
I want the toggle and menu to not have a fixed width because I need to use it in multiple situations.
.dropdown--right {
position: relative; }
.dropdown__toggle {
display:inline-block;
text-align:right;
position:relative;
right:0;
cursor: pointer; }
.dropdown__menu {
background-color: #E3E3E3;
background-clip: padding-box;
border: 1px solid #BDBDBD;
border-radius: 0.1875rem;
color: #0b0b0b;
list-style: none;
margin: 4px 0 0 0;
min-width: 10rem;
opacity: 1;
padding: 0;
right:0;
position: absolute;
pointer-events: none;
text-align: left;
top: 100%;
z-index: 99; }
.dropdown__menu__item {
display: block;
padding: 0.5rem 0.5rem;
width: 100%;
white-space: nowrap; }
.dropdown__menu:after {
border-style: solid;
bottom: 100%;
content: "";
height: 0;
position: absolute;
width: 0; }
.dropdown__menu:after {
border-style: solid;
bottom: 100%;
content: "";
height: 0;
position: absolute;
width: 0; }
.c-dropdown--right-triangle .c-dropdown__menu:before {
border-style: solid;
bottom: 100%;
content: "";
height: 0;
position: absolute;
width: 0;
right: 16px;
border-width: 0 10px 10px 10px;
border-color: #BDBDBD transparent; }
.dropdown__menu::after {
border-style: solid;
bottom: 100%;
content: "";
height: 0;
position: absolute;
width: 0;
right: 18px;
border-width: 0 8px 8px 8px;
border-color: #E3E3E3 transparent; }
<div>
<div class="dropdown--right" data-dropdown>
<a class="dropdown__toggle" >Toggle</a>
<ul class="dropdown__menu" data-dropdown-menu>
<li class="dropdown__menu__item"><a>Cameras</a></li>
<li class="dropdown__menu__item"><a>Cameras</a></li>
<li class="dropdown__menu__item"><a>Cameras</a></li>
</ul>
</div>
</div>
I added some styling and a class so you can use dropdown--left or dropdown--right to choose the display of your dropdown:
/* COMMON STYLE */
.dropdown__toggle {
display: inline-block;
position: relative;
cursor: pointer;
}
.dropdown__menu {
background-color: #E3E3E3;
background-clip: padding-box;
border: 1px solid #BDBDBD;
border-radius: 0.1875rem;
color: #0b0b0b;
list-style: none;
margin: 4px 0 0 0;
min-width: 10rem;
opacity: 1;
padding: 0 0.5rem;
position: absolute;
pointer-events: none;
top: 100%;
z-index: 99;
}
.dropdown__menu__item {
display: block;
padding: 0.5rem 0;
width: 100%;
white-space: nowrap;
}
.dropdown__menu::after {
border-style: solid;
bottom: 100%;
content: "";
height: 0;
position: absolute;
width: 0;
border-width: 0 8px 8px 8px;
border-color: #E3E3E3 transparent;
}
/* LEFT STYLE */
.dropdown--left {
position: relative;
text-align: left;
}
.dropdown--left .dropdown__menu {
left: 0;
text-align: right;
}
.dropdown--left .dropdown__menu::after {
left: 18px;
}
/* RIGHT STYLE */
.dropdown--right {
position: relative;
text-align: right;
}
.dropdown--right .dropdown__menu {
right: 0;
text-align: left;
}
.dropdown--right .dropdown__menu::after {
right: 18px;
}
<div>
<div class="dropdown--left" data-dropdown>
<a class="dropdown__toggle">Toggle</a>
<ul class="dropdown__menu" data-dropdown-menu>
<li class="dropdown__menu__item"><a>Cameras</a></li>
<li class="dropdown__menu__item"><a>Cameras</a></li>
<li class="dropdown__menu__item"><a>Cameras</a></li>
</ul>
</div>
</div>
<br><br>
<div>
<div class="dropdown--right" data-dropdown>
<a class="dropdown__toggle">Toggle</a>
<ul class="dropdown__menu" data-dropdown-menu>
<li class="dropdown__menu__item"><a>Cameras</a></li>
<li class="dropdown__menu__item"><a>Cameras</a></li>
<li class="dropdown__menu__item"><a>Cameras</a></li>
</ul>
</div>
</div>
Hope it helps.
If you want the class dropdown--right to also align the text in dropdown__toggle to the right, I think all you need is to include text-align.
.dropdown--right {
position: relative;
text-align: right; <-- Added CSS
}
Since you're going to be using this dropdown menu in multiple situations/components, I think it's as simple as adding position: absolute; and right: 0; to the .dropdown--right element, because you're going to be using it in other html elements anyway. And then for the left version of this component it'll be as easy as replacing the right: 0; with left: 0;
<div class="dropdown__containerexample">
<div class="dropdown--right" data-dropdown>
<a class="dropdown__toggle" >Toggle</a>
<ul class="dropdown__menu" data-dropdown-menu>
<li class="dropdown__menu__item"><a>Cameras</a></li>
<li class="dropdown__menu__item"><a>Cameras</a></li>
<li class="dropdown__menu__item"><a>Cameras</a></li>
</ul>
</div>
</div>
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.dropdown__containerexample {
position: relative;
width: 50%;
height: 200px;
border: 1px solid #000; }
.dropdown--right {
position: absolute;
right: 0; }
.dropdown__toggle {
cursor: pointer; }
.dropdown__menu {
background-color: #E3E3E3;
background-clip: padding-box;
border: 1px solid #BDBDBD;
border-radius: 0.1875rem;
color: #0b0b0b;
list-style: none;
margin: 4px 0 0 0;
min-width: 10rem;
opacity: 1;
padding: 0;
right:0;
position: absolute;
pointer-events: none;
text-align: left;
top: 100%;
z-index: 99; }
.dropdown__menu__item {
display: block;
padding: 0.5rem 0.5rem;
width: 100%;
white-space: nowrap; }
.dropdown__menu::after {
border-style: solid;
bottom: 100%;
content: "";
height: 0;
position: absolute;
width: 0;
right: 18px;
border-width: 0 8px 8px 8px;
border-color: #E3E3E3 transparent; }

Ionic app text is going out of view screen with chat app

I am adding chat feature in an ionic application. I have successfully added the chat functionality but issue is that whenever i type a long message it goes out of the view. I need the text to be with in the view. I am not good at CSS. Any help will be appreciated.
Here is the image
This is my .html file
<ion-header>
<ion-navbar>
<ion-title>{{teamName}}</ion-title>
</ion-navbar>
</ion-header>
<ion-content >
<div class="message-wrap">
<div *ngFor="let message of messages"
[class]="message.username == username ? 'message left' : 'message right'"
>
<img class="user-img" alt="" src="http://www.newsshare.in/wp-content/uploads/2017/04/Miniclip-8-Ball-Pool-Avatar-16.png">
<div class="msg-detail">
<div class="msg-info">
<p>
{{ message.username }}
</p>
</div>
<div class="msg-content">
<span class="triangle"></span>
<p class="line-breaker ">{{ message.message }}</p>
</div>
<!-- <div class="messageContent">{{ message.time }}</div> -->
<!-- <ion-datetime class="username" displayFormat="MMM DD, h:mm A" [(ngModel)]="message.time"></ion-datetime> -->
</div>
</div>
</div>
</ion-content>
<ion-footer>
<ion-toolbar>
<div id="footer">
<div class="elem"><ion-textarea type="text" placeholder="Enter message here....." [(ngModel)]="message"></ion-textarea></div>
<div class="elem"><button ion-button icon-only (click)="sendMessage()"><ion-icon name="send"></ion-icon> </button></div>
</div>
</ion-toolbar>
</ion-footer>
This is my .scss file
page-hotel-detail{
$userBackgroundColor: #387ef5;
$toUserBackgroundColor: #fff;
ion-content .scroll-content {
background-color: #f5f5f5;
}
.elem button {
border-radius: 0;
margin: 0;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.elem {
position: relative;
min-width: 50px;
}
div#footer div.elem:first-child {
flex-grow: 1;
}
div#footer {
display: flex;
flex-direction: row;
align-items: stretch;
}
ion-input{
padding-left: 15px;
font-size: 125%;
}
ion-toolbar {
margin: 0;
padding: 0!important;
}
.message:after {
content: '';
display: block;
clear: both;
}
.messageLeft {
float: left;
}
.messageRight {
float: right;
}
.message.special .innerMessage .messageContent{
background: white;
display: inline-block;
padding: 0 10px;
}
.message.special .innerMessage:before{
content: '';
height: 2px;
background: #eee;
display: block;
top: 50%;
position: absolute;
left: 0;
width: 100%;
z-index: -1;
}
.message.special .innerMessage{
background: transparent;
color: black;
font-size: 80%;
width: 100%;
float: none;
text-align: center;
position: relative;
}
.message-wrap {
padding: 0 10px;
.message {
position: relative;
padding: 7px 0;
.user-img {
position: absolute;
border-radius: 45px;
width: 45px;
height: 45px;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.36);
}
.msg-detail {
width: 100%;
display: inline-block;
p {
margin: 0;
}
.msg-info {
p {
font-size: .8em;
color: #888;
}
}
.msg-content {
position: relative;
margin-top: 5px;
border-radius: 5px;
padding: 8px;
border: 1px solid #ddd;
color: #fff;
width: auto;
span.triangle {
background-color: #fff;
border-radius: 2px;
height: 8px;
width: 8px;
top: 12px;
display: block;
border-style: solid;
border-color: #ddd;
border-width: 1px;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
position: absolute;
}
}
}
}
.message.left {
.msg-content {
background-color: $toUserBackgroundColor;
float: left;
}
.msg-detail {
padding-left: 60px;
}
.user-img {
left: 0;
}
.msg-content {
color: #343434;
span.triangle {
border-top-width: 0;
border-right-width: 0;
left: -5px;
}
}
}
.message.right {
.msg-detail {
padding-right: 60px;
.msg-info {
text-align: right;
}
}
.user-img {
right: 0;
}
ion-spinner {
position: absolute;
right: 10px;
top: 50px;
}
.msg-content {
background-color: $userBackgroundColor;
float: right;
span.triangle {
background-color: $userBackgroundColor;
border-bottom-width: 0;
border-left-width: 0;
right: -5px;
}
}
}
}
}
Got it fixed by adding this
width:200px;
word-wrap: break-word;
in css class

Resources