Why is vertical-align:middle not working like text-align:center - html

Can someone please tell me why vertical-align:middle Not working like text-align:center ?
I mean, why is it so hard to make it work?
I want to know why those W3 ppl don't make a text-align:middle
I'm asking why it's so hard to make the vertical-align:middle like text-align:center.

The vertical-align attribute is for inline elements only. It will have no effect on block level elements, like a div or a paragraph.If you would like to vertically align an inline element to the middle just use this.
Refer this Link : http://phrogz.net/CSS/vertical-align/index.html

text-align:center
means put the text in the center of the width of the <p> tag for example
vertical-align:middle
means. Put the <p> in the center (middle) of the height of the the parent tag <div> for example. Which means you need to increase the height of the parent.

Vertical align aligns like by height like this:
___________________________
Some text aligned top
Some text aligned middle
Some text aligned bottom
__________________________
Help with horizontal align can be found here: http://www.w3schools.com/css/css_align.asp

Related

Center Align Span in Div

I have this problem where Im trying to center a div with several spans of alternating texts of various lengths.
I have tried everything I could find, but the problem persists. Please, can anyone look into my css for what Im doing wrong?
Heres the link to the website: www.ultimatexp.com, I need to center align the changing header: We are exclusive, We are exciting, We are effective, We are entertainer asia.
Thank you!
Use width :100%;display:block in your span styles. or either try setting the parent div's text-align property containing the spans as text-align:center
Instead of display:block us display:inline-block for span, then add text-align:center

Is there a better way to horizontally align elements, than text-align: centre?

I have a div, I need ALL the elements inside to be centred, this includes; text and some images.
.class {
text-align: centre;
}
Works, however is there a better (best practice) Way to do this? I tried fiddling with margins etc... and it worked up until I resized to browser windows, any images that moved down (next row) were automatically aligned left?
What I am asking is there a css class similar to vertical-align but for aligning elements horizontally?
text-align: center (not centre) is your best bet. There are things you can do to prevent the items from breaking to a new line, such as setting a (max-)width on images inside this div based on media queries. But as far as aligning them in the center goes, just use text-align and if you want to break to a new line, a simple br will do the trick.
You said you played with margins. If you want to space elements out on the same row, keep using the margin property, but in addition to the text-align on the parent div.
You may use margin to horizontally align
margin: 0 auto;
http://jsfiddle.net/knzg410f/
alternate way :
to align horizontally you could use paragraph tag:
<p align="center">your text here</p>
http://jsfiddle.net/3Lz59zca/

Aligning div centrally inside other div and an image centrally both vertically and horizontally

I'm trying to achieve the following: I have a central div (wrapper) exactly in the center of my page, both vertically and horizontally. Inside that div I want to have another 2 divs, one of which will contain a logo and the other some text. The logo image also has to be aligned vertically and horizontally to the center of its div. Currently this is what I have:
Here's the jsfiddle with my HTML and CSS: http://jsfiddle.net/7cQhG/
How can I center the logo div (only centered horizontally, and have a 10px margin-top) and have the logo image centered inside that div, both horizontally and vertically, just as it is now)?
Is there any reason you have to have the logo as an img?
I've taken the starting point you gave, and put together a jsFiddle fork : http://jsfiddle.net/mori57/HDmkZ/
I've taken out the img tag, and used it as a background image. "center center" should theoretically center it within its container, and as it's a transparent png, your background color still shows up as you wanted.
Let me know if this works for you, or if you have any other questions.
As a sidebar, you really don't need (and you really shouldn't) to specify your tags in your CSS. The only place that's really appropriate is if you're assigning defaults to a specific tag... otherwise, rules of specificity are already going to take over when you're using those IDs you've got in there.
Note that I wasn't clear what you wanted to do with the text below the logo, so I didn't do any styling, there.

align-middle question

What is my misunderstanding about the way that vertical-align:middle; works?
I have posted (http://jsfiddle.net/D6RwZ/) some code which I would expect to vertically align a red rectangle in a blue rectangle, but it doesn't look like that.
vertical-align:middle won't work on div (block element). You can refer here for details.
If you want to vertical align, I think the only option is using margin/padding with appropriate parameters.
Vertical-align only works on inline images and display: table-cell.
I've used this solution a few times and it works quite well but takes some work. If you're working with fixed size elements position absolute is by far the simplest. Dynamic sized elements and vertical centering can be very tricky, lots of browser quirks to deal with.
vertical-align can only be applied to elements with:
display:table-cell in order to vertically align the contents of the element.
display:inline or display:inline-block in order to vertically align the element within the text line that contains it
A cheap hack with the latter : http://jsfiddle.net/8bZQS/

HTML, Floating, Small Problem, Seems Simple

If you look at my Jsfiddle Example, the float seems to disregard the title text that is to the left of the floated element. My goal is to make the floated element not overlap the title text and to stop once it reaches the end of the div which is the title text
My questions, is this possible?
I just do not want it to overlap the element which is to the left of the floated element.
Thanks in advance for the advice, suggestions, etc.
Jsfiddle.net
Remove Position: Relative from your #advertisement_1 div, and in the HTML put it above the title div.
Below is an updated JSFiddle with it working, you may need to adjust the "top" value in your CSS for the advert box if it needs to be different to what is in the fiddle.
http://jsfiddle.net/f5j2z/