FlyingCat
FlyingCat

Reputation: 14250

How do align texts in the child div

I am trying to text-align to center on a div with texts. The texts inside the div needs to be aligned to the left.

In my jsfiddle

html

<div class="parent">
    <div class="texts">my text my text my text<br>my textmy text</div>    
</div>

CSS

.parent {
    text-align:center;
}

.texts{
   //not sure what to do    
}

I need to have texts div center inside the parent div but no indentations on two lines of texts. I can't really set the widths because they all needs to be responsive. How do I solve this? Thank you!

https://jsfiddle.net/bh4pu001/

Upvotes: 2

Views: 51

Answers (3)

Sandip Tajne
Sandip Tajne

Reputation: 57

Please Use Following code

.parent {
    float:left;
}

.texts{
    float:left;
   text-align:center;
}

.parent {
    float:left;
}

.texts{
    float:left;
   text-align:center;
}
<div class="parent">
    <div class="texts">my text my text my text<br>my textmy text</div>    
</div>

Upvotes: 0

Bhavin Panchani
Bhavin Panchani

Reputation: 1352

set display: inline-block;

.texts{
   text-align: left;
   display: inline-block;
}

Working fiddle

Upvotes: 0

Tamil Selvan C
Tamil Selvan C

Reputation: 20199

Use

.parent {
    text-align:center;
}

.texts{
    display: inline-block;
    text-align: left;
}
<div class="parent">
    <div class="texts">my text my text my text<br>my textmy text</div>    
</div>

Upvotes: 2

Related Questions