user3026860
user3026860

Reputation: 35

How do I center this element?

My HTML:

<div class="container">
    <div class="card login">
        <p id="Title">Plex</p>
            <div class="label">
        </div>
        Random text
    </div>

    <div class="card welcome">
        <div class="label">
            <p id="Title">Hi!</p>
        </div>
        Lorem ipsum
    </div>

    <div class="card extra">
        <div class="label">
            <p id="Title">Extra</p>
        </div>
        Lorem ipsum
    </div>
</div>

MY CSS:

.container{
    display: flex;
    width: 100%;
    /*align-content: center;*/
}
.card {
    flex: 1 1 auto;
    border: 1px solid #f3f3f3;
    background-color: #f3f3f3;
    margin-left: 50px;
    margin-right: 50px;
    margin-top: 25px;
    height: 450px;
}
.label{
    background-color: #434342;
    width:auto;
    height: 70px;

}
.card:not(:first-child){
    margin-left: 20px;
}

#Title {
    float: left;
    font-family: Thinfont-Thin;
    font-size: 42px;
    color: #d2731d;
    text-align: center;
}

A JSFiddle: http://jsfiddle.net/cvYGW/

How do I make the PLEX HI EXTRA all align perfectly in the middle of their cards and how do I move them up or down?

Upvotes: 0

Views: 103

Answers (8)

Lijo
Lijo

Reputation: 6778

jquery animation


src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
    </script>
    <script> 
    $(document).ready(function(){
      $('#Title').click(function(){
        $('#Title').animate({
          bottom: '-=20'
        }, 1000);
      });
    }); 

updated fiddle

Upvotes: 0

enguerranws
enguerranws

Reputation: 8233

You have to reset margin to 0 for #title and put a line-height that equals to the height of the parent.

#title { /* change this selector to .title */      
  line-height: 70px;
  margin: 0;
  font-family: Thinfont-Thin;
  font-size: 42px;
  color: #d2731d;
  text-align: center;
}

See: http://jsfiddle.net/cvYGW/9/

By the way, remember that your code is not valid HTML, as you use the same ID three times (#title). You should use class in this case. And you don't need any float property.

Upvotes: 2

Priya jain
Priya jain

Reputation: 703

update css:

#Title {
float: left;
font-family: Thinfont-Thin;
font-size: 20px;
color: #d2731d;
text-align: center;
width: 100%;

}

Upvotes: 0

SubjectCurio
SubjectCurio

Reputation: 4872

You shouldn't have multiple instances of an ID, so firstly change #Title to a class

You can't use float:left; & text-align:center;, remove the margin from your title p, match the line height

.title {
  margin:0px;
  line-height:70px;
  font-family: Thinfont-Thin;
  font-size: 42px;
  color: #d2731d;
  text-align: center;
}

http://jsfiddle.net/cvYGW/6/

Upvotes: 1

Harsha Venkataramu
Harsha Venkataramu

Reputation: 2904

Check out http://jsfiddle.net/skyrbe/cvYGW/8/

You were using same id for multiple p tags . Never do that.

.Title {
    float: left;
    font-family: Thinfont-Thin;
    font-size: 42px;
    color: #d2731d;
    text-align: center;
    width:100%;
    margin:0px auto;
    line-height:42px;
}

Upvotes: 0

SivaRajini
SivaRajini

Reputation: 7375

Please refer below updated fiddle

http://jsfiddle.net/cvYGW/10/

give some width for parent div and align the child elements in center of parent by using margin css property.

margin: 0 auto;

Thanks,

Siva

Upvotes: 0

rrugbys
rrugbys

Reputation: 282

I have update the js fiddle you just have to add

 #Title {
     line-height:70px;
     width:100%;
     margin:0;
 }

Check on fiddle

Upvotes: 0

timo
timo

Reputation: 2169

#Title {
font-family: Thinfont-Thin;
font-size: 42px;
color: #d2731d;
text-align: center;
margin:0 auto;
}

Upvotes: 0

Related Questions