CSS - Set text-align of inline-element - css

I have navigation points with text in it (longer and shorter). The text should be centered, but the text itself is aligned left; complicated to explain. Please have a look at my picture:
The upper three are my is-state but the lower three the should-be-state.
With display: inline my elements have the correct size (even with word breaks). So I gave the parent text-align: center to center the text-container horizontally. But: the text within the container should have text-align: left. But with display: inline this is not possible.
BTW: display: inline-block is not a solution because it strechs the container with longer text to 100% width even if the broken text does not fit.
See here: http://jsfiddle.net/z5jo64bj/
Is there a way without JavaScript to solve this?

Related

Vertical alignment of a DIV inside another DIV

I'm trying for some days to vertically align the .sl_container.
I have tried vertical-align: middle, but that doesn't work.
If i specify a height and width for the .slideshow, then using top: 50%; and transform: translateY(-50%);, that works. See here.
The problem is that if i remove the height and width for the slider to take up the available space and adapt, then the this will make the inner div appear moved upwards. See here.
display: table-cell; was not an option as it would have the arrows at the sides of the full width of the parent div instead of on the image.
I've tried flex before, and it gets vertically aligned, but if the parent DIV width is bigger than the child DIV, for some reason it goes to
As I said, I’ve tried multiple ways and there is not a single one that gets it done well without breaking the arrow positions.
What I’ve done until now: JSFiddle
The before mentioned settings are commented out in the CSS section.
Any insight to this would be helpful as to a way or how to get it aligned without breaking the whole slide and arrows.
FYI: There is a bleeding effect from the DIV's or images expanding like 1-2px to the bottom, reason why I have each DIV coloured to see if I can fix it. I'm sure it something silly and if you know what it is, please say so. It’s not important so I don’t really care much. xD
Add this to your slideshow element, using flexbox. Flex Needs prefixing for IE11 (caniuse)
.slideshow {
display: flex;
align-items: center;
}
Edit: I enabled the commented height and width styles in your jsFiddle, but this method will vertically align slideshow child regardless of width and height.
Try using flexbox, it's the most elegant solution for vertical alignment
E.g.
<div class='parentDiv'>
<div class='childDiv'>
</div>
</div>
.parentDiv {
display: flex;
align-items: center;
justify-content: center;
}
Take a look -> here

why isn't my p tag centering within my two content divs

I have a paragraph in the two divs with classes of .content1 and .content2 and I cant get them to center within the divs. Does one know why this is?
Demo
Code:
.content1 p, .content2 p {
text-align: center;
background-color: rgba(0,0,0,.02);
max-width: 280.34px;
}
as you can see text is aligned into your div.
look at 2 images with align left and align center
I see now I misread the question all those months ago. To center each paragrapah itself within its parent div, when it's wider than the max-width of the paragraph, you just need to add the margin property to the rule included in your question, setting margin-left & margin-right to auto, like so:
.content1>p,.content2>p{
background-color:rgba(0,0,0,.02);
margin:0 auto;
text-align:center;
max-width:280.34px;
}
Your text is centred in those paragraphs. However, as the text in those paragrpahs is just the same string being repeated multiple times, at some sizes you'll end up with the text on every line of the paragraphs being identical, making the paragraphs appear to be justified rather than centred. In those cases, though, you can just about see the centring on the last line which doesn't end with a comma.
To avoid any problems like this in the future, try using "lorem ipsum" as placeholder text instead.

vertical text height in css

How to fix the height of the vertical text? It is not working properly with line-height or height property
Here is my demo
http://jsfiddle.net/BsZ8f/1/
I tried my hand on the code but couldn't figure out. My solution would be to use just css2 to create vertical text, for this you just need to give the .title a fixed width say 10px just enough to hold one character, this way the text will automatically get aligned vertically and give height: auto; overflow: auto; to make sure the height adjusts.

Centering a dynamically sized div inside another div that is centered on the page

All I want to do is center some divs on the page. The outer one is a fixed size and is centered horizontally via margin: 0 auto. Inside that div I have a couple images side by side inside another div that wraps to their size. I want to center that div both vertically and horizontally inside the outer div.
It seems like a simple enough thing to want to do, no?
Update:
Let me bit a bit clearer as to what exactly the problem is. I'd love to use the display: table-cell trick to enable vertical-align: middle but the problem is that when I do this, the div shrinks down to the size of its content, thus not offering any space for centering at all, and that div is just stuck up in the top left corner of the parent. I need my display: table-cell block to fill up the available space of the containing div so it has room to center its contents.
Update 2: Solved!
Turns out the problem was that I didn't have the display: table-cell block contained in a div that was set to display: table. I'm not entirely sure how display: table differs from display: block, but it's apparently a necessary step. It appears to be working now!
This might help:
http://www.vanseodesign.com/css/vertical-centering/

Keep text on left and middle of the div, not center

I want to be able to keep a text on the left, but in the middle of a div.
<div id=sel>text goes here</div>
and my CSS for the same
sel{
text-align:left;
vertical-align:middle;
}
The characters and lines of the text may vary. I am more focussed on the text with a single line that sits on the top. I do not want to use position:absolute/relative.
Appreciate all help.
Thanks
Jean
Firstly, a side note: vertical-align only works with table cells. As a result, this problem is trivial with table cells. See Understanding vertical-align, or "How (Not) To Vertically Center Content".
Otherwise you will need to put that content inside another block and then vertically center that block within the outer block. See Vertical Centering in CSS.
If you are dealing with a single line only, the easiest way is probably to set the line-height equal to the height of the div, for example:
#sel {
text-align: left;
height: 4em;
line-height: 4em;
}
For other scenarios, have a look at this page

Resources