- AuthorPosts
- February 15, 2021 at 11:29 am #33783JoeGuest
Hey forum,
I have enabled the sidebar to appear on the homepage through using custom CSS, but cannot determine how to “crop” it so it does not extend past the length of the page, on other pages such as: https://www.example.com/report-model/ and https://www.example.com/must-follows/
As you can see, the page is short, but the sidebar is the full-length. I would like it to add some custom CSS so that the sidebar cuts itself off when the rest of the page ends. If this is not possible, would I be able to add css that removes certain aspects of the sidebar from certain pages?
Thank you to everyone who contributes to the forum!
Joe
February 15, 2021 at 11:55 am #33827Jesse OwensKeymasterHi Joe-
Thanks for reaching out, and for choosing the Grid One WordPress Theme from BoldGrid.
This is possible, but it will take a little extra trickery with JavaScript in addition to CSS, because CSS doesn’t have a method to measure another element’s height.
First, enter this Custom CSS in your Customize > Advanced > Custom JS & CSS:
aside.sidebar { overflow-y: hidden; }
That will do the job of hiding any content beyond the sidebar’s max-height. Now we need to use JavaScript to set that max-height value according to the length of your page’s or post’s content. Enter this into the Custom Theme JS
jQuery(document).ready(function($) { $('aside.sidebar').css({ 'max-height' : $('div.entry-content').outerHeight() + 'px' }); });
This code does a couple of things. It waits for your whole page to load using the (document).ready trigger. Then, it sets the max-height of your sidebar to the same height as your entry-content.
Coupled together, this code should accomplish what you’re after.
Another possibility you can consider is to use the Widget Logic plugin to only show certain sidebar widgets on certain pages, or simply reduce the number of recent posts and recent tweets you’re showing now.
February 15, 2021 at 12:07 pm #33832JoeGuestHey Jesse,
Thanks for the response. I have pasted in the code like you have suggested, but it does not seem to have changed the site at all. I have cleared the cache as well, but maybe it takes a bit to update?
I am receiving an orange “!” error on the last line of the JS code, “Unexpected Token }”
Could this be the error?
If this isn’t going to work, I can just opt for that plugin you suggested to change the sidebar on different pages. Let me know if that is my best solution.
Thanks again,
Joe
February 15, 2021 at 12:09 pm #33835Jesse OwensKeymasterHi Joe-
It looks like there may be a small typo in the code you pasted into your Custom JS. Double-check your first line, and make sure that it’s not “commented out” with a double-slash. Right now, it looks like this when I take a look:
// jQuery(document).ready(function($) { $('aside.sidebar').css({ 'max-height' : $('div.entry-content').outerHeight() + 'px' }); });
Remove that double-slash at the beginning of the first line, and it should work.
February 15, 2021 at 3:14 pm #33841JoeGuestAwesome, it works great now!
I appreciate it.
Now, I just have to figure out why this embedded video is displaying differently across different browsers. https://www.gmedd.com/blog/finding-value-in-gamestop-before-all-the-retail-mania-rod-alzmann/
How it looks on Chrome & Safari https://imgur.com/cHxawZ6
I used some code to ensure the video loads in at the maximum resolution that can fit in the section, relative to the user’s display. For some reason, this works great on mobile, chrome, but does not load well on MacOS Safari. Instead, it displays only a slice of the top of the top of the video.
I’ve tried to make a seperate forum thread for this one, but I’m getting an Access Denied message, protecting from online attacks.
Thanks,
JoeFebruary 15, 2021 at 3:26 pm #33855Jesse OwensKeymasterHi Joe-
Thanks for the screenshot, that’s very helpful. I’ll see if I can tweak our security system so that issue creating a new topic doesn’t occur again.
I was able to replicate that issue with the video using Safari 13.1 on MacOS Catalina, but it looked fine on Safari 14 for MacOS Big Sur, so it’s definitely a weird issue with Safari specifically.
I wasn’t able to figure out exactly how you have that video embedded, are you using a special plugin to embed that? The issue seems to be related to the way Safari is interpreting the height of the video iframe. I had some luck with this CSS:
.video-responsive iframe { min-height: 480px; }
However, I’m not sure how that will play out across other devices. If you’re using a special plugin for that video, we might want to check with their authors to see if it’s a known issue.
February 15, 2021 at 6:41 pm #33878JoeGuestThanks for the further testing as well, seems like for now I will have to write it off as a bug, and maybe tinker with it in the future. I should upgrade to MacOS Big Sur so it doesn’t bother me, haha.
One thing – Is there any way to have the sidebar code you wrote disabled on the homepage? It seems like sometimes it is cut short without any reason, as seen here: imgur.com/T97p1G3.png Other times, it isn’t. Odd.
Thanks again for all the help you have provided, truly appreciate it.
Joe
February 15, 2021 at 6:56 pm #33880Jesse OwensKeymasterHi Joe-
Good catch! I should have tested on the blogroll, where it was cutting off after your first post. Update that code to this:
jQuery(document).ready(function($) { if ( ! $('body').hasClass('home')) { $('aside.sidebar').css({ 'max-height' : $('div.entry-content').outerHeight() + 'px' }); } });
This basically says, “If we’re on the homepage, keep it at 100% height, otherwise cut it off at the content.”
February 16, 2021 at 1:52 pm #33882JoeGuestAwesome, great work! I can be very proud of how my website looks now.
Only issue left with my site is the header & the background of it adapting to other browser sizes. I used this code here:
@media (min-width:1130px){ .site-header { position: fixed; top: 0; width: 100%; height: 15%; z-index: 200; background: #2d2d2d; } } @media (max-width:1129px){ .site-header { position: absolute; top: 0; width: 100%; height: 40%; z-index: 200; background: #2d2d2d; } } .mobileHide { display: none;}
As a side effect, the “start” of each page is covered up by my header. You can see this as the first blog post title is not visible, and the sidebar starts with a blank space html (to combat this). In my experience, it was either this, or there was a big empty space between the header and the site.
I am using the code “background: #2d2d2d;” to ensure the header does not collide with any information on the site. Unfortunately, it doesn’t always line up perfectly, and I’m curious if there’s a way to fix that. Using Safari 13.1, the stock ticker has a background to display on, but on Safari 14 for MacOS Big Sur, it is halfway off as you begin to scroll down the site.
Is there a more uniform way to accomplish this? I spent several hours tinkering the other day, but to no avail.
February 16, 2021 at 2:25 pm #33922Jesse OwensKeymasterHi Joe-
First off, congrats on all the work you’ve done so far, designing a sidebar and sticky header from scratch isn’t a small feat!
With the breakpoints you have set up at >= 1130 and <1129, it looks like your header plus stock ticker widget is about 140 pixels and 200 pixels, respectively. So, you can add a line to each of your media queries to compensate for it, like so:
@media (min-width:1130px){ .site-header { position: fixed; top: 0; width: 100%; height: 15%; z-index: 200; background: #2d2d2d; } main > row { margin-top: 140px; } } @media (max-width:1129px){ .site-header { position: absolute; top: 0; width: 100%; height: 40%; z-index: 200; background: #2d2d2d; } main > row { margin-top: 200px; } }
I wasn’t able to replicate the issues you described with the background of the stock ticker, but as near as I can tell its background is transparent, which causes some issues with the CSS I listed above. Try adding this outside of your media queries:
#custom_html_5 { background: #2d2d2d; }
February 26, 2021 at 10:30 am #34332JoeGuestHey Jesse, back again for one question regarding the header.
On both desktop and mobile, when I view a blog page, or any page for that matter, the header with the ticker widget and 2d2d2d background covers up whatever is on the first 100-200 pixels or so on the page. To counter this, I’ve moved all of my content down a bit and it is mostly okay.
As a result though, the blog post pages make the title of the post invisible. It is possible to add an empty space before the start of any blog posts to fix this?
Here is a screenshot of what I am talking about: imgur.com/a/v7RRfUc
Thanks again,
Joe
February 26, 2021 at 10:40 am #34360Joseph WKeymasterHi Joe!
I took a look at the mobile display for your website and it looks like the reason the blog post titles are sliding under the header area is caused by the absolute positioning assignment on that area created by the following CSS rule:
@media (max-width: 1129px) .site-header { position: absolute; top: 0; width: 100%; height: 35%; z-index: 200; background: #2d2d2d; }
You could try using position: relative; instead of position: absolute; in that rule. Changing to a relative position should cause the blog post titles to display below the ticker widget in your header instead of causing them to slide under the entire header area.
Please let us know if you have any other questions for us!
- AuthorPosts
- The topic ‘How to cut off sidebar at the bottom of the content’ is closed to new replies.