JavaScript How to left-align centered text only if hits a line break? left align center text,left align center html,left align

How can I condition my text to become left-aligned if hits the end of its contained space and has to switch to the next line? Is there something inherent within CSS that can detect it, or does it have to be a JavaScript solution?

Here's the fiddle so you can see how it should behave: https://jsfiddle.net/fj4ddmey/2/

.text.container {
  margin: 0 auto;
  text-align: center;
  width: 350px;
  border: 1px solid black;
}
.text.container.two {
  text-align: left;
}
<div class="text container">
  <p>This is how short sentences should look</p>
</div>
<div class="text container">
  <p>This text should be left aligned because it hits a line break</p>
</div>
<div class="text container two">
  <p>This is how it should look, but it needs to be a fluid solution</p>
</div>
Answer:1

Use flexbox like that

.container {
  display: flex;
  justify-content: center;
}
<div class="container">
  <p>This is how it should look, but it needs to be a fluid solution</p>
</div>
Answer:2

You can set the <p> as inline block, so that text-align:center on the container will center the <p> tag first, rather than the text. And inline-block has the shrink-to-fit feature, means the width is determined by the content, and never goes beyond the container, with text-align:left, text inside will be left aligned when it wraps.

.container {
  width: 350px;
  margin: 0 auto;
  text-align: center;
  outline: 1px solid black;
}
.container p {
  display: inline-block;
  text-align: left;
  outline: 1px dotted red;
}
<div class="container">
  <p>This is how short sentences should look</p>
</div>
<div class="container">
  <p>This text should be left aligned because it hits a line break</p>
</div>
Answer:3

I am using the following regex in conjunction with abide Foundation for validating a password: <form id="setPassword" action="{{ url('changePasswordWithoutToken') }}" method="POST" class="account ...

I am using the following regex in conjunction with abide Foundation for validating a password: <form id="setPassword" action="{{ url('changePasswordWithoutToken') }}" method="POST" class="account ...

  1. regex password validation python
  2. regex password validation javascript
  3. regex password validation c#
  4. regex password validation java
  5. regex password validation codewars
  6. regex password validation no spaces
  7. regex password validation swift
  8. regex password validation 8 characters
  9. regex password validation php
  10. regex password validation python codewars
  11. regex password validation jquery
  12. regex password validation example
  13. regex password validation ruby
  14. regex password validation angular
  15. regex password validation
  16. regex password validation javascript code wars
  17. regex password validation pattern
  18. regex password validation mvc
  19. regex password validation powershell
  20. regex password validation oracle

In my Google Chrome Extension I have: function submitScreenshot() { chrome.tabs.captureVisibleTab( null, function(img) { var xhr = new XMLHttpRequest(), formData = new FormData(); ...

In my Google Chrome Extension I have: function submitScreenshot() { chrome.tabs.captureVisibleTab( null, function(img) { var xhr = new XMLHttpRequest(), formData = new FormData(); ...

I have a problem with connection to a database with mongoose on localhost. In my server.js file I have: var express = require('express'); var app = express(); //...

I have a problem with connection to a database with mongoose on localhost. In my server.js file I have: var express = require('express'); var app = express(); //...

  1. node js mongodb
  2. node js mongodb tutorial
  3. node js mongodb example
  4. node.js mongodb example application
  5. node js mongodb connection
  6. node js mongodb find by id
  7. node js mongodb find example
  8. node js mongodb driver
  9. node js mongodb update by id
  10. node js mongodb find
  11. node js mongodb example github
  12. node js mongodb crud
  13. node js mongodb user authentication
  14. node.js mongodb find toarray
  15. node js mongodb aggregate query
  16. node js mongodb authentication
  17. node js mongodb connection pool
  18. node js mongodb rest api
  19. node js mongodb insert
  20. node.js mongodb search engine

This is my Html5 code.. Problem is that "Text is not fully read by the voice. It stops in half way."What I need to do for that? Am using the script inside the html <!DOCTYPE html> <html ...

This is my Html5 code.. Problem is that "Text is not fully read by the voice. It stops in half way."What I need to do for that? Am using the script inside the html <!DOCTYPE html> <html ...

  1. html5 javascript text to speech
  2. html5 javascript text
  3. html5 javascript copy text to clipboard
  4. html5 javascript input text
  5. html5 javascript write text file
  6. html5 javascript create text file
  7. html5 javascript change button text
  8. html5 script typeu003d text/javascript srcu003d
  9. javascript html5 canvas draw text
  10. html5 typeu003d text/javascript
  11. html5 script typeu003d text/javascript
  12. html5 javascript draw text
  13. html5 typeu003d text/javascript 不要