- This topic has 15 replies, 3 voices, and was last updated 4 years, 6 months ago by Tom.
-
AuthorPosts
-
October 2, 2019 at 4:48 pm #1024770An Nguyen
Hi there,
I tried to use this code to make topbar and main nav sticky but it doesn’t work. I need your support. I turned off sticky option on customize
https://generatepress.com/forums/topic/sticky-top-bar-and-main-navigation/
Thanks
October 2, 2019 at 4:56 pm #1024771DavidStaffCustomer SupportHi there,
it won’t work on your site as you’re using the merged header Element.
October 2, 2019 at 5:01 pm #1024773An NguyenHi David,
I turned it off , it’s still the same situation.
October 2, 2019 at 5:42 pm #1024796DavidStaffCustomer SupportThats because you have this CSS that is setting its position to relative:
.home .site-header { background-color: transparent; position: relative; }
You also need to set the
top
value for the site header to the height of the top bar which is 57px.October 2, 2019 at 7:15 pm #1024836An NguyenHi David,
It worked. May I ask you about issue relating to sticky? In single post, I tried to make tableofcontent sticky. I did a hook after-entry-header and put shortcode inside div-wrapper (“wrap-lwptoc”). I want it displays as a sticky object at outside container(like right sidebar) but I couldn’t. It’s sticky but not move to the left -80px. This is my css following a guide that you posted about GP-social sticky.
`.wrap-lwptoc{
display: block !important;
position: sticky !important;
position: -webkit-sticky !important;
top: 103px;
height: 0;}
.lwptoc {
top: 57px;
flex-direction: column;
left: -80px !important;
}`Thanks
October 3, 2019 at 2:23 am #1025008DavidStaffCustomer SupportSticky elements are relative to their parent container and the scroll direction which is vertical – so the Left property doesn’t apply.
If you want to move the element horizontally you will need to transform its position:
transform: translateX(-80px);
October 3, 2019 at 6:16 pm #1025762An NguyenHi David,
Thanks David, you did the trick but I have a bit confusion about using left. You can use left to move GP-social up to left side but this case is different. However, this case is similarity with GP-social. https://generatepress.com/forums/topic/social-share-buttons-only-in-post-and-fixed-in-sidebar/
As you said, relative position we use transform instead of left because of scroll direction, can I move the element both vertical and horizontal such as going left 80px and then going up 50px? I tried with translateY but it doesn’t work.
October 4, 2019 at 3:04 am #1025961DavidStaffCustomer SupportThat uses margin-left which may also work but not seeing the actual element you wanted to move transform was a safer bet.
This explains the transform property:
https://www.w3schools.com/cssref/css3_pr_transform.aspOctober 4, 2019 at 3:37 am #1025979An NguyenHi David,
I used this code from page 3 of this link
@media (min-width: 840px) { .floating-container { display: block; position: sticky !important; position: -webkit-sticky !important; top: 80px; height: 0; } #gp-social-share { top: 1em; flex-direction: column; left: -50px !important; } }
+You used “left:-50px !important”. Therefore, I used for tableofcontent but it doesn’t work. After your suggestion, I used transform: translateX(…); and it works that why this makes me confusion.
October 4, 2019 at 1:37 pm #1026535DavidStaffCustomer SupportAs this topic has gone from sticky nav/top bar, to TOC to social links i provided the transform translate method as this works in the majority of scenarios.
CSS is relative to the HTML it is applied, just because something works in one scenario doesn’t meant it can be applied everywhere.
I suggest you study some W3Schools so you’re better equipped.
October 4, 2019 at 6:06 pm #1026617An NguyenHi David,
CSS is relative to the HTML I knew that David. This is a basic level.
This topic has given a sticky on right-side bar site (after-entry-header) that you supported “JUAN JOSE GONZALEZ” as page 3. Have you read that? It is the same situation because I also put my tableofcontent on the same location. When you using hook, it has been injected the php function in HTLM template. So, I think HTML in the after-entry-header location is the same structure.
I confused because I used “left” and this attribute does not work. However, in my case, I’ve used margin-left and transform: translateX(…) and both give me the correct solution. I solved the tableofcontent problem by myself.
Anyway, thanks for your support for sticky main nav and top-bar.
October 5, 2019 at 8:33 am #1027042TomLead DeveloperLead DeveloperDid using
transform
not work for you?Sometimes using
left
will work, but it depends on a lot of factors. If it doesn’t work in this scenario, you’ll want to usetransform
instead.October 5, 2019 at 8:45 am #1027052An NguyenHi Tom,
“Transform” and “margin-left” work correctly. In contrast, when I used “left”, the tableofcontent doesn’t change its position. Finally, I tried “transform” & “margin-left” , however I have a little bit confuse on this and I’ve wondered which one is the correct option changing the position of this element.
October 5, 2019 at 4:32 pm #1027265TomLead DeveloperLead DeveloperI would personally go with the transform option.
October 7, 2019 at 1:09 pm #1028735An NguyenThanks Tom!
You alway give me a perfect solution! Thanks.
Transform attribute is absolutely perfect.
-
AuthorPosts
- You must be logged in to reply to this topic.