How do I change text direction - html

I am making a word counter but the text is not in the left. How can I make it to the left?
let area = document.getElementById('area');
let char = document.getElementById('char');
let word = document.getElementById('word');
area.addEventListener('input', function() {
// count characters
let content = this.value;
char.textContent = content.length;
// remove empty spaces from start and end
content.trim();
console.log(content);
let wordList = content.split(/\s/);
// Remove spaces from between words
let words = wordList.filter(function(element) {
return element != "";
});
// count words
word.textContent = words.length;
});
* {
margin: 0;
padding: 0;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.container {
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.container h1 {
font-size: 25px;
}
.container h3 {
font-size: 20px;
}
.heading {
border: 2px dashed green;
padding: 5px;
font-weight: 700;
text-align: center;
width: 400px;
}
#area {
height: 200px;
width: 400px;
resize: none;
font-size: 15px;
font-weight: 700;
padding: 5px;
margin-top: 15px;
color: green;
outline: none;
border: 2px dashed green;
}
#area:focus {
border: 2px dashed blue;
outline: none;
}
.result {
color: green;
font-size: 20px;
width: 401px;
text-align: center;
font-weight: 200;
padding: 5px;
border: 2px dashed green;
margin-top: 10px;
}
#word,
#char {
font-size: 25px;
text-decoration: none;
}
<div class="container">
<div class="heading">
<h1 style="color:green">Word counter</h1>
<h2>Delete everything first!</h2>
<h3><b>Word and Character count<b></h3>
</div>
<textarea id="area"
placeholder="Enter your Text Here">
</textarea>
<p class="result">
<span id="word">0</span> Words and
<span id="char">0</span> Characters
</p>
I tried changing the center to left but it gave weird results like the boxes being to the left of the page, the text being to the left but not centered. So again, how can I make it so that the text inside the middle box is on the left and not in a weird spot

If you mean in your textarea, it is because you have spaces between your textarea tags
Try this : <textarea id="area" placeholder="Enter your Text Here"></textarea>
That's why your placeholder wouldn't show too.

You can use dir="rtl" on text area
<textarea dir="rtl"></textarea>
<element dir="ltr|rtl|auto">
ltr - Left-to-right text direction
rtl - Right-to-left text

Related

how to get the same line through different <p> Tags

am trying to use this css property "text-decoration: line-through;" on two different Tags and without breaking the line
.pricereview {
display: flex;
justify-content: space-between;
align-items: flex-start;
width: 100%;
}
.price {
display: flex;
align-items: end;
text-decoration: line-through;
}
.prixunit {
color: lightgrey;
font-size: 20px;
line-height: 20px;
}
.tnd {
color: lightgrey;
font-size: 13px;
line-height: 26px;
padding-left: 5px;
}
<div class="pricereview">
<div class="price">
<p class="prixunit">560</p>
<p class="tnd">TND</p>
</div>
</div>
This is the result that I want:
Screenshot here
I'd suggest using <span> tags and wrapping them in another element. Use a pseudo-element on the wrapper to make your "linebreak" span multiple elements of different font sizes and line heights without breaking.
.price {
position: relative;
display: inline-block;
}
.price::after {
content: '';
position: absolute;
top: 45%;
left: 0;
width: 100%;
border-bottom: solid 1px #000;
}
.prixunit {
font-size: 20px;
line-height: 20px;
}
.tnd {
font-size: 13px;
line-height: 26px;
padding-left: 5px;
}
<p class="price">
<span class="prixunit">560</span>
<span class="tnd">TND</span>
</p>
You cant do that with a p tag, cause its a block-level element
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p
And it seems that in your case you want to make a line that is not cutting exactly in the middle of the word. If its your case, text-decoration: line-through dont will help you.

Wrap the Content inside the Input Value

Is there any way to wrap the content with the input field, in my case is taking a size, but I would like for example if it is the value "123" for the input to be wrapped around the text, and when we type more words it grows in size, without having a fixed size like this in the screenshot.
Screenshot of the Input Text Field 1
My Component structure JSX:
<Container {...props}>
<Input placeholder="New Skill" />
<AddIcon color="#0056FC" />
</Container>
Here is CSS, using Styled Components:
const Container = styled.section`
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 7px 10px;
gap: 10px;
background: transparent;
border-radius: 4px;
border: 1px solid ${props => props.theme.border};
`
const Input = styled.input`
font-family: 'Manrope';
font-style: normal;
font-weight: 500;
font-size: 14px;
line-height: 21px;
color: #455560;
border: 0;
background: transparent;
display: flex;
&::placeholder{
color: #0056FC;
}
`
You've already got the right answer, I just wanted to show the contenteditable strategy to achieve the same result:
.content {
display: flex;
}
#field {
min-width: 3rem; /*3 chars min length*/
border: 3px solid gray;
cursor: text;
padding: 5px;
}
<div class="content">
<h1 contentEditable="true" id="field"></h1>
</div>
I think now that must work.
span {
padding: 5px;
}
div {
display: flex;
width: max-content;
}
<div>
<span>Input Field :</span>
<input type="text" oninput="this.size = this.value.length + 1" size="1">
</div>

Have a textarea with the placeholder in the middle but when I have more rows, the rows grow upwards until reaching the margin

I have a textarea, I have the placeholder in the middle but when I start writing more that one row, the text cuts down beacause of the padding. If I remove the padding, the placeholder is not centered.
How can I achived both things?
<div class="container">
<textarea
value={body}
onChange={e => setBody(e.target.value)}
placeholder="Escribe un mensaje"
onKeyPress={async event => {
if (event.key === "Enter") {
onSave(mutate);
}
}}
required
/>
</div>
.container {
display: flex;
flex-direction: row;
width: 100%;
height: 60px;
margin-bottom: 0px;
border-top: 1px solid grey;
}
textarea {
margin: 0px;
font-weight: normal;
font-size: 12px;
line-height: 16px;
font-family: ${props => props.theme.fonts.openSans};
border-radius: 7px;
padding: 16px;
padding-top: 20px;
box-shadow: none;
resize: none;
overflow-x: hidden;
overflow-y: scroll;
scrollbar-width: none;
box-sizing: content-box;
border: none;
border-right: 1px solid grey;
&::placeholder {
font-style: italic;
font-weight: light;
}
::-webkit-scrollbar {
width: 0px;
background: transparent;
}
::-webkit-scrollbar-thumb {
background: #ff0000;
}
}
If you only need to center the placeholder, you don't need padding, simply add this:
textarea::placeholder {text-align: center;}
However, there are some issues with placeholder, it will work different on different browsers. You can learn more here.

Form text cursor wrong-sized when no text is entered

I made a form and its input text.
HTML
<form action="/search" method="get" id="searchForm"><input type="text" id="searchText" name="q" value="{SearchQuery}" /></form>
CSS
#searchText {
text-align: center;
position: relative;
top: -2px;
padding-top: 5px;
width: 496px;
font: 2em "Myriad", Helvetica, sans-serif;
line-height: 1;
color: #222222;
border: 1px solid gray;
border-radius: 2em;
}
#searchForm {
}
And it works perfectly but looks like this:
Notice how the cursor is moved down and not centered vertically.
Then, when any text is entered, it corrects itself to the right size/ vertical position and becomes
(and even stays correct when text is deleted).
How can I make it also initialise correctly?
I've tried setting the
#searchForm { }
to vertical-align: center;
line-height: normal; or inherit
font-size: 1;
but to no effect.
Quick fix suggestion :
padding: 2px 0;
would solve your problem
#searchText {
text-align: center;
position: relative;
top: -2px;
padding: 2px 0; /* altered */
width: 496px;
font: 2em "Myriad", Helvetica, sans-serif;
line-height: -2em;
color: #222222;
border: 1px solid gray;
border-radius: 2em;
}
demo
why its happening
padding-top: 5px; is pushing down the cursor by 5px...since your are not balancing this padding from bottom cursor is forced to push down!
Apply equal padding on top and bottom like below. Also remove the top:-2px.
#searchText {
text-align: center;
position: relative;
padding-top: 5px;
padding-bottom: 5px;
width: 496px;
font: 2em "Myriad", Helvetica, sans-serif;
line-height: 1;
color: #222222;
border: 1px solid gray;
border-radius: 2em;
}
DEMO

My </p> tag is affecting the position of my div. Why is this?

I have this div wedged between two bars(other divs), though when I add text into the equation, the div gets repositioned down. It works as intended without the p element and its children. Here's a fiddle to demonstrate the issue: http://jsfiddle.net/57uSQ/
this is the HTML that is causing the problem:
<p>
<span class="name">DOLCE & GABBANA</span>
</br>
<span class="title">THE ONE</span>
</p>
And the correlating CSS:
.videoDesc {
display: inline-block;
border: 1px solid #000000;
border-right: 0px;
height: 200px;
width: 500px;
}
.videoDesc p {
display: inline-block;
margin: 0;
padding: 0;
}
.videoDesc .name {
display: inline-block;
padding: 0px;
}
.videoDesc .title {
display: inline-block;
padding: 0px;
}
.title {
font-family: Lekton;
font-size: 1.25em;
}
.name {
font-family: Oswald;
font-weight: lighter;
font-size: 2.5em;
letter-spacing: 10px;
padding-left: 5px;
}
You need to add vertical-align:top to .videoDesc:
.videoDesc {
display: inline-block;
border: 1px solid #000000;
border-right: 0px;
height: 200px;
width: 500px;
vertical-align:top;
}
jsFiddle example
The default vertical alignment is baseline, which is causing the behavior you see.