PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 16, 2022

[FIXED] How do I vertically align text in a colorbox?

 November 16, 2022     css, javascript, jquery, php, vertical-alignment     No comments   

Issue

How do I vertically align text that is inside of the cboxTitle-div (e.g. close-Box(text))? I use colorbox for making modal popups.

The div-structure is this:

<div id="cBoxContent">
    <div id="cBoxTitle"></div>
</div>

CSS code:

#cboxContent{overflow:hidden; background: #121219;
}
#cboxTitle{position:absolute; top:0; left:0; text-align:left; width:100%; color:#999; height: 38px;}

Solution

You can vertically center text by setting its line-height property to the height of the element it's sitting in.

#cboxTitle{
    position:absolute; 
    top:0; 
    left:0; 
    text-align:left; width:100%; 
    color:#999; 
    height: 38px;
    line-height: 38px;
}

This trick will only work if you know the height of your div, of course. There are other methods, but they're more complex.

Another method that isn't linked is to set the div containing your text to position: relative;, then setting top to 50% minus the one half the height of the element. This is best done in Javascript.



Answered By - Elliot Bonneville
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,204,163

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing