Vertically center carousel items in responsive - html

I have a carousel with items that have variable height in responsive, and I want to center them vertically in the .carousel-inner container. And I do (using flex, top & transform, etc)... but they're centered only when they have finished the animation when becoming active, so they are aligned top at first, then go down and it seems like it jumps.
I think it's something about the Bootstrap animations for the carousel but I haven't figure it out. The page is https://zuckermanlaw.swapps.io, the carousel is in the Our Services section. I'd appreciate any help. Thanks.

Just add the height same as your carousel-inner class has to below mention class, though it stretch images a little bit but fix your issue.
section.third-section #carousel-our-services .carousel-inner .item .carousel-caption {
display: flex;
height: 365px;
}
I hope this helps you.
Enjoy :)

I played around with this and came up with this.
#media (-webkit-transform-3d), not all
.carousel-inner>.item.active, .carousel-inner>.item.next.left, .carousel-inner>.item.prev.right {
position: absolute;
left: 0;
right: 0;
top: 50%;
transform: translate(0,-50%); // IE9
transform: translate3d(0,-50%,0); // Modern Browsers
}
I replaced all declarations for that selector. It changes the animation style, but it does vertically align. Personally, I think that looks cool but you might not. I thought it was still worth showing to you. It might be a good start for you. I did this in the browser inspector, and that was the only change I made.

Related

css animation : slide a div hidden from the side to the center

I want to animate some sort of floating div.
When the div is in the status 'close' , most of it is hidden on the right of the screen, with only 20px still visible.
When I click on the visible part, the div move to the center of the screen, revealing itself.(it's what I call the status open)
My issue are:
I only know how center a div with margin:auto, which do weird stuff when I animate it
when the div is 'closed', the 'hidden' part create an overflow who add a scrolling. I don't want that
the div have a width who change a lot, depending of the case. Consequently, I cannot use a lot of hard coded value in CSS.
Any idea how to do this?
Even a partial solution would help me.
Edit : the solution (thanks to #sonic)
.open{
translateX(-50%);
left:50%;
}
.close {
translateX(-20px);
left:100%;
}
Its too open question to be able to help with 2,3 points, its hard even to say what is the objective and without code, who knows...
Centering div like that:
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
you can easly animate those properties.

Center text over image (Wordpress and Jetpack)

I have a little question about a wordpress plugin which is related to css.
I use on my blog the related posts plugin from Jetpack. It displays 3 articles with wide image and title at the bottom of my posts.
I would like to make the text center horizontally and vertically over my image. As you can see on this post (https://www.ptds.fr/velotaf-guide-de-survie-du-cycliste-urbain/) I managed to get it by playing around with css.
But I'm not happy with this solution as it will not work if the content is too small and the text is not really vertically aligned (just a padding from top).
Thanks in advance.
https://www.ptds.fr/velotaf-guide-de-survie-du-cycliste-urbain/
You'll need to remove some of what you've added, but here you go:
#jp-relatedposts .jp-relatedposts-list .jp-relatedposts-post {
position: relative;
}
#jp-relatedposts .jp-relatedposts-list h4.jp-relatedposts-post-title {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
width: 90%;
width: calc( 100% - 30px );
}
Remove these items from your current CSS and replace them with the values above: https://i.imgur.com/kEf3ev4.png
The end result will look like this: https://i.imgur.com/qzGI3sK.png
Edit: I changed the width from 100% because it could lead to the words touching the edge of the image, so I set to 90% for browsers that don't support calc, and added 15px of "safe space" for browsers that do.

Various CSS questions to customize theme

I'm really new to programming and trying to customize a theme that I am using. However I am having several issues where if I fix one thing something else breaks. I've researched solutions for about 3 days and I think it's time I reach out to some more experienced with CSS for help.
I tried setting up a JSFiddle but it's not working correctly as I can't access the HTML file directly. The website is www.preethijagadeesh.com. Would it be possible to review the html/css files and provide suggestions for the following requirements?
Center the title (I believe this is found in the 'site_header'
class which is pasted below). I am using margin to change the percentage and it looks
different on various browsers.
I would also like to 'fix' the title so that when I scroll the title
goes with me. I used 'position: fixed' but it cause all the
content in the 'index' ID (pasted below) to overlay on the title/site_header.
The text in the 'About' page appears to be more on the left with
a lot of white space on the right. No matter what I am unable to get
the content to center regardless of which class I update.
The line/border_bottom that appears under the navigation items should be
the same length as the text. I tried updating it but now every time
I hover over the items the text/options move around
overlay a
black color on the thumbnails on hover. I got it to 'kind of' work.
It's just when I hover on the thumbnails, the images and the
'background color' flicker
Widen the gap between the thumbnails.
Right now, there are two columns, it would be great to just put some
space in between them.
Please let me know if there's any other information I can provide.
Change
.header_image {
float: left;
margin-top: 80px;
max-width: 100%;
}
to
.header_image {
text-align: center
margin-top: 80px;
max-width: 100%;
}
Add these to .site_header:
.site_header{
/* old css remains here... */
position: fixed;
top: 0;
left: 0;
right: 0;
}
Move the padding properties from the a to their parent instead (the .page_link div).
and 5. I can't get the thumbnails to display on your jsfiddle so I can't really give the answer. But for 4 I think something like this will help:
put a <div class="thumbnail-overlay"></div> inside your thumbnail html.
For the css:
.thumbnail-overlay{
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 1;
/* this z-index should be higher than the thumbnails' child element. If no z-index is set for their child element leave it at 1 */
}
.thumbnail-overlay:hover{
background-color: rgba(0,0,0,0.5);
}
Hopefully this helps.
.header_image is floating, so you can't center it nicely. If you remove the float and then use text-align: center;, the image should center.
Not really sure where you are wanting the title to appear - should it be above the content or to the left of the content?
You have removed the padding from the links to resize the underline, but it's only been changed on hover. This is what is causing the "jumping" navigation links. If you add this code to .navigation a (instead of .navigation a:hover), this should work nicely:
.navigation a {
padding: 0;
margin-right: 6px;
margin-left: 7px;
}
Instead of using .thumb_image:hover, try using .thumbnail:hover .thumb_image and see if that's helps with the flickering. Also, maybe remove the background-position: 0 -30px;.
Is a plugin being used to generate and control the thumbnail images? The absolute positioning being used on the thumbnail images will make it difficult to reposition them.
You should be creating the site offline and reviewing your work before migrating the site to your host.
If your host does not allow you to migrate your site and/or denies you access to your HTML files, you need find a new web host.

Trouble with image gallery on codepen

I'm trying to do my first project in html & css but am having some trouble. I'm practicing using codepen and my gallery was going somewhat well but I'm trying to add the last line of images and it seems to be messing EVERYTHING up and I don't know why. Would anyone mind taking a look?
Here's the link
For some reason, when I try to add that chess board it all goes bad.
I'm still very new at this so I look forward to learning a lot.
Thanks.
[1]: http://codepen.io/zenturtle/pen/ezDGC
The margins are causing the issues. When you use margins to position an element you push the elements around it too.
One solution is to use: position: relative and then use the positioning properties: top, bottom, left, right
Example:
#chess {
position: relative;
left: 555px;
}
Another solution is to use position: absolute.
Place position: relative on the <div id="perimeter">
Place position: absolute on each <img>
Position each <img> where you want itwithin the <div id="perimeter">
Example:
#chess {
position: absolute;
bottom: 122px;
right: 230px;
}
That's how you'd position the chess image where you want it.
CSS Tricks has a good
article explaining the position property.

How to fit and center an unknown sized image in a div element with a relative size using only pure CSS

I am working on a CSS animated HTML block. I created a fully responsible grid, so these blocks have relative sizes. The block contains a big image to ensure to display the content on all screens correctly. The images in the blocks have 100% width to fit the content, and they also have CSS transitions and transforms.
I would like to center these images vertically, but using only pure CSS. I tried a lot of variations of display, position and vertical-align properties, but no one worked for me. I could easily achieve the proper animation with the background property, but I don't want to create a lot of css classes for all the images (not even with js or jquery).
So could you tell me how to solve this issue with pure CSS? I also created a jsfiddle to demonstrate the problem.
EDIT: I also would like to keep the ratio of the images inside the blocks.
I've created a codepen example of position centrally horizontally and vertically and if you resize it stays in the centre.
http://codepen.io/tom-maton/pen/oqsEJ
In the example I have
margin: auto;
position: absolute;
left:0;
right: 0;
top: 0;
bottom: 0;
This makes it h &v positioned centre if you just do
margin: auto 0;
position: absolute;
top: 0;
bottom: 0;
This will position just vertically
Hope this helps
I had a look around and found this link for you:
CSS Tricks - Absolute Center (Vertical & Horizontal) and Image
I hope this can be of some help to you
I have done it on your fiddle too:
Your Fiddle Link
I simply added margin-top: -100px;
EDIT
Sorry didn't realised it wasn't for a fixed size see this updated version:
Fiddle Updated
I used the following code:
position: absolute;
top: 50%;
left: 50%;
height: 100%;
width: 50%;
margin: -25% 0 0 -25%;
I found it here:
6 Methods For Vertical Centering With CSS
You need to define the height: 100%; as well.
demo
if you define the images with css then it could be as ratio as you wish by setting background-size: cover; but to the image it's not possible.
You can't do what you want both retaining the image ratio and your container DIV smaller than image size, you can even set the height:100% to fit image inside the DIV or set DIV to a bigger size (or use smaller image to fit in the DIV) and use line-height:100%
Here are demo for first solution:
Demo changing the ratio
And demo for second solution:
Demo not changing the ratio
(I also set the text-align:center to make sure it is centered even when you don't use width:100%)
Hope it helps you.
The most dynamic solution (in my opinion) is using translateY.
This will move the element from its current position:
see: CSS3 2D transforms
img {
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-o-transform: translateY(-50%);
transform: translateY(-50%);
}