Image in a DIV - vertical centered - css

i have a DIV with a size x and some images in it with often a larger size. And in this case i need the image vertical centered in this DIV.
Dows anyone know, how i can realize that?
Thanks for reading that!

You can place the images inside divs and place those divs into the Your div and after words to center them
You can also make a class fo those divs and in the css part position:center;

You can use vertical alignment as here http://phrogz.net/css/vertical-align/index.html

If the div contains only images and no text/one liner, you can set line-height=height and use vertical-align to center the image.
<div style="height: 10px; line-height: 10px">
<img src="" style="vertical-align: middle"/>
</div>
PS: It is important to have a space character after the <img/> to force the image to align to the space in IE6.

Related

Proportionally scaling an image on the left to the height of two lines on the right

I cannot figure out how to scale an image on the left side proportionally to the height of two lines on the right.
I tried to solve the problem with flexbox, but the aspect ratio was not preserved.
<div style="display: flex;">
<img src="https://www.gnu.org/graphics/heckert_gnu.small.png">
<div>
<h1 style="font-size: 128px;">GNU</h1>
<p style="font-size: 32px;">GNU is Not Unix</p>
</div>
</div>
https://jsfiddle.net/1gh1hr0c/
It seems to involve a circular dependency. The calculation of the width and height of the img depend on the height of the right div, and the height of the div depend on the width of the div. The flexbox would need the width of the image to determine the width of the div...
Anyway, what I'm trying to do is still quiet a simple in nature. I think there should be a solution using flexbox or something fancy.
use must st property to your flex container align-items: center;
https://jsfiddle.net/1gh1hr0c/3/

HTML: Div is not in align?

Hello i used Bootstrap and my 2 div col-md-6 and col-md-6 are not in align in height.
Use this css for the first div.
div.col-md-6 {
display: inline-block;
vertical-align:middle;
}
The simplest way to align vertical align here is to add padding from top in the first div.Your second div have buttons and must be having padding also.
Use min-height for both using class to div. It will solve your query.
eg:
<div class="col-md-6 mycol">
</div>
<div class="col-md-6 mycol">
</div>
style.css
.mycol{
min-height:100px;
}
Without the code, it's hard to find the cause, but I guess your two div are without a css height property and then adapt to their content.
The div on the right contains items that seems to have a padding on top and bottom, resulting in an item with a greatest height than the one on the left.
Your two div are aligned on the top and as it's already been mentionned you need to add the same padding on the left and right cols (I don't like the vertical align answer, as it work in this case, but could cause issues as the cols height could change).
If you dont have a scenario where you text will wrap to the next line, you can use line-height which will be same for both the sections.

Div Wrapped around image has border that exceed past image

I'm not sure if that title made sense but I'll try to explain to the best of my ability.
I want to add a div basically on top of an image, which is simple. I wrap the image around a div and then give things like top:, left:, from that.
Yet this div that the image is inside of exceeds the border of the actual image and goes all the way out to the parent div. How do I make it so that the border of the div just wraps around the actual image inside the div.
The black square is an image. But the div with the class of image, does not have a border that wraps around the image.
<div id="page">
<div class="image">
<img src="http://upload.wikimedia.org/wikipedia/commons/8/85/Black_300.jpg">
<div class="innerimage"></div>
</div>
</div>
Add display: inline-block to the .image div:
display: inline-block;
http://jsfiddle.net/wwRhB/4/

<img> in <div> won't vertical-align:middle, why?

we have CSS:
#left,#right{width:450px;height:450px;}
#left{position:absolute;left:20px;top:30px;}
#right{position:absolute;left:420px;top:30px;float:center;}
#left img, #right img{float:center; vertical-align:middle;cursor:pointer}
Image is horizotal centered, but gets top aligned (i want middle)
html looks like
<div id="media">
<div id="left"><img/></div> <div id="right"><img/></div>
</div>
Any idea what i'm doing wrong?
By the way, all this problem it's because i'm displaying images with different resolutions :S
EDIT
This didn't help... :(
#left,#right{width:450px;line-height:450px;}
#left{position:absolute;left:20px;top:30px;}
#right{position:absolute;left:420px;top:30px;float:center;}
#left img,#right img{cursor:pointer;}
you can vertical align an image in a div that has no text in it by setting line-height on the on the div. example:
<div style="height: 100px; line-height: 100px;">
<img src="http://nelson-haha.com" height="50" style="vertical-align: middle;"/>
</div>
You'll first off need to have some height declared on #left or #right to get it to align vertically. (As it is, it has no more known space to align vertically in than the space it's taking up--so it will always appear top-aligned.)
Secondly, make sure you understand vertical-align correctly. Here's a good resource: http://phrogz.net/css/vertical-align/index.html In short, vertical-align is probably not the best solution.
vertical-align on an image is how the text aligns to the image, the way the text wraps around the image. Not the way the image is displayed in the div.
Please see this on StackOverFlow

How to achieve Bottom Align floated div that sizes to it's container

How can I achieve the following layout? Specifically the positioning of Image and DIV
I've found that unless I set a specific width for the Div, it will just go on to the next line and take up the full width of the container. Additionally aligning it relative to the bottom of the image is giving me trouble. Currently they're both float:left
Edit: The two solutions so far work if the image is a constant width which I guess I could work with, but it's going in a Wordpress theme for an author's profile page and it's possible that images would have slightly variable widths. Is there a solution that would have the Div right next to the image (minus padding) regardless of how wide or narrow the image is? Basically having the div adjust its width to accommodate the image width.
Tested in IE7/8, Firefox, Chrome.
Live Demo #2
CSS:
#container{width:80%; padding:12px; margin:0 auto}
#top{position:relative;overflow:auto}
#top img{float:left; background:red; width:100px; height:180px}
#header{position:absolute; bottom:0; right:0}
#content{height:200px}
JS/jQuery:
$('#header').css('margin-left', $('#top img').width() + 10);
(you might want to change the + 10 for parseInt($('#top img').css('margin-right'), 10))
HTML:
<div id="container">
<div id="top">
<img src="" />
<div id="header">Some text here that should wrap to fit on row. Some text here that should wrap to fit on row. Some text here that should wrap to fit on row. Some text here that should wrap to fit on row. </div>
</div>
<div id="content">dfgdfg</div>
</div>
I'd put the header image and header div inside its own container and position the items within it using absolute positioning.
I've put together a quick sample here: http://jsfiddle.net/JjxYj/1/
Notice here that if you remove the width of the Div in the header, it will become the width of its content.
Update
To answer the updated part of the question, here's another solution that'll allow the image to be of any width whilst still positioning the header text at the bottom of its containing item: http://jsfiddle.net/JjxYj/5/

Resources