Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centered responsive text

I have a jsfiddle here - http://jsfiddle.net/kw83kLmo/

It's justs a block of text that I need to center in the window.

The text needs a set width because I don't want it to be the full width of the container.

When the window gets smaller the text needs to stay in the center but get narrower.

In the example here it stays centered and responds until it get's to 600px then just stays that width.

I know I have set that width but I did that to center it

<div class="container-fluid ">

    <div class="hero">

        <div class="hero_heading text-center">
            <h1>This is a heading This is a heading This is a heading </h1>
        </div>

    </div>

</div>
like image 650
ttmt Avatar asked Jul 23 '26 04:07

ttmt


2 Answers

Update your h1 style like below.

.hero_heading h1 {
    border: 1px solid red;
    color: white;
    position: absolute;
    left: 0;
    right: 0;
    margin: 0 auto;
    max-width: 600px;
}

DEMO

like image 188
Suresh Ponnukalai Avatar answered Jul 25 '26 21:07

Suresh Ponnukalai


Edit on your code

.hero_heading h1{
    border: 1px solid red;
    color: white;
    //top: 0; left: 0; bottom: 0; right: 0;
    width: 600px;/*added*/
    max-width:80%;/*to leave spaces around your text on responsive*/
    margin:auto;/*changed*/
}

You no need to position your element for making it unless if you need

NOTE: Remove your position:relative; from .hero

DEMO

like image 38
Benjamin Avatar answered Jul 25 '26 21:07

Benjamin