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

Friday, November 18, 2022

[FIXED] How to vertical-align an alternate text within a floated image?

 November 18, 2022     css, html, text-alignment, vertical-alignment     No comments   

Issue

Having tried some of the solutions relating to vertical align, I don't seem to be able to solve this. Not sure if anyone can help me on this. All I want is to position the alternate text in the middle of an empty image.

This is the html code:

<div class="viewport">
 <a href="#">
  <img src="http://yahoo.com/" alt="no image" />
 </a>
 <div>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
 </div>
</div>

And this is the css code:

.viewport {
 background: #bbb;
 width: 350px;
 height: 300px;
 padding: 5px;
}

.viewport img {
 float: left;
 margin: 5px;
 width: 100px;
 height: 100px;
 background: #000;
 text-align: center;
}

.viewport div {
 margin-left: 20px;
}

Thanks for taking your time to read.


Solution

edit 2017: Flexbox FTW (probably with a both as a flex item (its container having default vertical/second axis align-items: stretch) and a flex container (vertical alignment is then achieved with flex-direction:column and justify-content: whatisneeded)

I believe @alt has the height of its content, far less than 100px.

By fixing a line-height equal to height, vetical-align will do what you intend it to do.
Here is a fiddle: http://jsfiddle.net/PhilippeVay/Xevph/



Answered By - FelipeAls
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • 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

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 © PHPFixing