2

I'm creating a WordPress Twenty Fifteen child theme to move its left sidebar to right side.

My child theme sidebar's height is not equal to window's height like the original theme.

This is my sidebar CSS:

.sidebar {
float: right;
margin-right: 0px;
max-width: 413px;
position: relative !important;
width: 29.4118%;
background: #fff;
box-shadow: 0 0 1px rgba(0, 0, 0, 0.15);
}

I have tried height:100%; and height:auto; but it still not working.

How to fix this issue?

Zulhilmi Zainudin
  • 9,017
  • 12
  • 62
  • 98

4 Answers4

1

You can use css3 viewport-percentages.

For example, setting height equal to: height:100vh;, will make your div equal to 100% of the height of the view port.

You can read more about it here:

Make div 100% height of browser window

or have a look at this fiddle I put together here. fiddle

Note that CSS3 vh is not supported by older browsers, so you may be better off accomplishing this with jQuery or javascript.

Community
  • 1
  • 1
psvj
  • 8,280
  • 8
  • 30
  • 44
1

jQuery would be your best bet.

$(window).scroll(function() {
    var windowHeight = $(window).height();
    $(".sidebar").css("height", windowHeight);
});

The scroll function will resize the sidebar if the browser size changes.

James George Dunn
  • 523
  • 1
  • 6
  • 16
0

If you want it to be fixed (always there, like in the original theme) then you can set it to position: fixed with a top: 0, bottom: 0 and a proper left/right settings (or width).

If you want it to stay at the top and not stick to the viewport, then you could place it in position: absolute with a top: 0, bottom: 0 and proper left/right, etc.

Drown
  • 5,852
  • 1
  • 30
  • 49
0

I had the same problem. The solution I used, after looking at the styles used on http://materializecss.com/collections.html - the side navigation is similar to what I am attempting to make - I found that this worked for me:

height: calc(100% + 2em);

Well.. more precisely, THIS worked for me:

height: ~"calc(100% + 2em)";

^ I'm using LESS, and if it's not escaped, I'd end up with a height of 102%.

Lindsey
  • 191
  • 2
  • 3