I have a fixed container in which I placed a list (ul) with dynamic number of items.
at the top of the container there's a title.
It seems that the presence of the title messes the list scroll. i.e. one cannot scroll to the last item on the list, since the bottom part of the list is pushed below the view port.
My HTML & CSS (skeleton) is at http://jsfiddle.net/brjwjn2L/2/ where you can notice the scroll issue.
my HTML:
<div class="menu-wrap">
<div style="height:100px">
<div>my items</div>
</div>
<div class="menu">
<div class="icon-list">
<ul>
<li class="playerBox">
<div class="topRect">
item 1
</div>
</li>
<!-- unknown number of items -->
<li class="playerBox">
<div class="topRect">
item n
</div>
</li>
</ul>
</div>
</div>
</div>
I'd appreciate any hint as for how can the list scroll bar be shown so that user could scroll all the way to the last item.
Thanks
Idan
Is changing your .menu-wrap's CSS from
position: fixed;
to
position: relative;
an option? It does fix the scrolling problem, but it might change your layout.
You could also try
position: absolute;
though it doesn't seem to display correctly.
EDIT: Since that isn't an option, change the height style of your title div to percent say 15%:
<div style="height:15%">
<div>my items</div>
</div>
and then change your menu height to fill the REST of the percentage (not 100%):
.menu {
height: 85%;
overflow-y: auto;
}
The problem is that both the title div and the menu div have the same container parent. So since the title div was taking up 100px, that 100px was removed from the menu's 100%.
Related
I have a top nav, side nav and the main content of the page. On click, the tabs on the side nav should bring the div associated with the tab to the top of the page (This is a different issue i am facing as scrollTop method from JS isn't working, but I am able to use scrollIntoView() for now to get something going)
template
<mat-card class="main-card">
<mat-card-title>Some title</mat-card-title>
<mat-card-content class="main-content">
<div class="div1">Div1 content</div>
<div class="div2">Div2 content</div>
<div class="div3">Div2 content</div>
</mat-card-content>
</mat-card>
CSS
.main-card {
overflow: auto;
height: 700px;
}
.main-content {
height: 1000px;
overflow: auto;
}
sidenav items
<div class="side-nav">
<div class="mat-list-item" (click)="handleElemScroll(div1)">
<span>Div1</span>
</div>
<div class="mat-list-item" (click)="handleElemScroll(div2)">
<span>Div2</span>
</div>
<div class="mat-list-item" (click)="handleElemScroll(div1)">
<span>Div2</span>
</div>
</div>
on the main card, I am unable to add the height prop to, even if I use !important. I've run into this issue with a few other times using angular-material. I am forcing a scroll, but mid way through the scroll, the entire page begins to scroll. Even though the height of my mat-card-content is set to be larger than the mat-card itself.
A few questions if anyone can guide me
1. Why does my entire page begins to scroll mid way?
2. Without making my side and top nav stick, how can I implement a scroll? Is my idea of using overflow, and making the inner container height larger than its parent container the correct idea here?
Thanks for any help
I have a div element that wraps items in it
<div id="#wrapper" style="overflow: scroll; max-height: 100%;">
<ul>
<!--lots of li's go here.
When an li is clicked, "#details" pop from below.
-->
</ul>
</div>
<div id="#detils" style="display:none; height:30%;">item details</div>
Since there might be lots of items, the div has:
max-height: 100%;
When an item is clicked, details section should pop from below.
Its height is 30%.
How can I make the div wrapper scrollbar height automatically adapt to the new situation in CSS only. In other words: its height should now change to 100%-70%=30%
You can add a class which has height:30; when the item is clicked.
I hope this can help you.
I need to set the position of a table container as absolute based on the <body> container rather than its nearest positioned parent container.
Fixed position is NOT what I want since it positions it based on the viewport and not the main body (this is the expected behaviour for fixed).
Here is a little more details and code showing what I want.
CSS:
#media screen and (max-width: 480px)
I need the <table> content to have an absolute position based on the <body> container
and not the <div id="SearchForm"> container which is the nearest parent with its position set
HTML:
<body>
<div class="page"> <!--position: absolute;-->
<div id="Header"> <!-- position: fixed;-->
<div class="inner">
<div class="header-secondary"> <!--position: absolute;-->
<div id="SearchForm"> <!--position: relative;-->
<form action="......">
....<!--parent search bar form-->
</form>
<table> <!--quicksearch-->
...content <!-- quicksearch results popup-->
</table>
</div>
</div>
</div>
</div>
</div>
</body>
The reason behind this is that when the page is displayed in the mobile view for devices under 480px wide,
The <header> and <div id=searchform> stay fixed at the top of the screen/viewport regardless of scrolling down.
The <table> is the quickview search box that pops up during search showing nearest results.
The problem is, that this causes the quicksearch suggestion box to stay at the top as well. The rest of the page will scroll underneath it, but the suggestion box will stay "fixed" at the top of the screen.
This is somewhat fine if there were just a few results, but when there are more and it extends beyond the bottom of the screen/viewport, there is no way to scroll the suggestion box down to see the rest of them.
I could add a scroll bar for overflow but I want to be able to scroll beyond the quicksearch container and see the content of the main body if I keep scrolling down. As of now, the main content will scroll under the quicksearch results but always remain hidden under it.
if I use position:absolute; it will remain at the top of the screen and I won't be able to scroll down to the results that are offscreen.
If I use position:fixed; then the same thing will happen since it will be positioned based on its viewport and not based on the main body
My only current working option is to have the JS load outside DOM and thus have the ability place it anyway I want it.
This though creates other positioning issues when resizing the window beyond 480px for desktop view mode as it is harder to calculate the offset based on a child container that is deep in the body and keeps resizing dynamically when the window resizes.
Setting the table to position: absolute relative to the body will be impossible as long as any of it's parents has position: fixed.
You will have to move the <table> outside of the fixed header one way or another.
I would use an extra wrapper to be able to switch which element has position: fixed at what viewport width:
<body>
<div class="page"> <!--position: absolute;-->
<div class="ExtraWrapper"> <!-- position: fixed; above 480px -->
<div id="Header"> <!-- position: fixed; below 480px -->
<div class="inner">
<div class="header-secondary"> <!--position: absolute;-->
<div id="SearchForm"> <!--position: relative;-->
<form action="......">
....<!--parent search bar form-->
</form>
</div>
</div>
</div>
</div>
<table> <!-- quicksearch. position: absolute; below 480px -->
...content <!-- quicksearch results popup-->
</table>
</div>
</div>
</body>
This is my website
Does anyone know how to put the nav bar right next to the white box where my content will go? I just want it exactly vertically aligned with the white box, but make it sit just to the left of it. Thanks
HTML
<nav>
<div class="nav-container">
<ul class="nav">
<li><span class="text">HOME</span></li>
<li><span class="text">HTML & CSS</span></li>
<li><span class="text">USABILITY</span></li>
<li><span class="text">ACCESSIBILITY</span></li>
<li><a href="page5.html"><span class="text">HOW I BUILT THIS</span>
</a>
</li>
</ul>
</div>
</nav>
CSS
nav {
margin: auto;
}
EDIT: I misunderstood the question, here is the new answer:
http://codepen.io/Vall3y/pen/gbpRoG
I have put the nav and content again under the same container, but the container is now relatively positioned, and the nav is absolutely positioned at top: 0, left: 0. You can control the distance of the nav from the content by adjusting the container width, or with the left attribute of the nav. I have applied a dashed border around the container to demonstrate what is happening, but in your site it doesn't need a border of course.
Orig:
If you could include the rest of the code I could give you a better example, but here is the layout you want:
http://codepen.io/anon/pen/EajXgq
The key here is that the nav and content are adjacent in markup (elements comes right after another. I used float left to make them on the same vertical line but there are other techniques)
The nav is floated left, so that it doesnt take any flow space and allows the content to horizontally align at the center, using a fixed width and an auto margin.
They both are contained in a container to allow margin from the logo if necessary
Also see that there is a clearfix element, for clearfix. Google it to find out what it does but basically it allows the container to stretch over the floated elements so it doesn't mess up the layout
<div class="purple-logo"></div>
<div class="container">
<div class="nav"></div>
<div class="content"></div>
<div class="clearfix"></div>
</div>
I'm helpless, tried my best understanding CSS but it's just not for me.
I would like to make a really simple MasterPage:
at the top a div of full width and height 40px (1)
at the bottom also a div of full width and height 40px (2)
in the middle:
on the left: a div of width 200 px (3)
on the right side of the left div: a div with contentPlaceHolder (4)
What I would like to get is: if i make some site that uses my master page and place a panel in the contentPlaceHolder that has width 800px, I would like my site to adjust to it - top, middle and bottom divs to have their width of 1000px (200 + 800). I also wouldn't like (and I have a huge problem with that) the (4) to move down if I resize (shrink) the browser window - I would like all the divs to be blocked.
This is my master page html:
<div>
<div class="header">
</div>
<div>
<div class="links">
</div>
<div class="content">
</div>
</div>
<div class="footer">
</div>
</div>
What kind of CSS do I have to write to make this finally work?
Not sure if you have checked into this or not, but we use the YUI-Grids CSS Framework for our layouts. It keeps us from having to spend a lot of time on CSS, which we are not great at being developers.
There is even a grid builder which will let you graphically layout a page, and then copy and paste the required HTML to make it happen :)
To prevent floated divs from being "squeezed" out of the alignment you want, you usually use either width or min-width.
For example, in this code the div containing the links and content will never be smaller than 1000 pixels. If the screen is smaller than 1000 pixels, a scrollbar is displayed.
<div style="min-width: 1000px">
<div class="links"></div>
<div class="content"></div>
</div>
You could also use width instead of min-width:
<div style="width: 1000px">
<div class="links"></div>
<div class="content"></div>
</div>
The difference between the two is simple: if you specify min-width, the div CAN grow to be larger if it needs to. If you specify width, the div will be exactly the size you specified.
Be aware that min-width is not supported by IE6.
Here's a quick stab at specific CSS/Markup for this problem.
Markup:
<!-- Header, etc. -->
<div class="contentView">
<div class="links">
</div>
<div class="content">
</div>
</div>
<!-- Footer, etc. -->
CSS:
.contentView {
/* Causes absolutely positioned children to be positioned relative to this object */
position: relative;
}
.links {
position: absolute;
top: 0;
left: 0;
width: 200px;
}
.content {
padding-left: 200px;
}
You might want your footer to be "sticky." Check here for information on that: http://ryanfait.com/resources/footer-stick-to-bottom-of-page/
How appropriate this is depends on precisely what the design calls for. This makes the links section more of a floating box on the left than a column for example.
This ends up looking like this (.content is green, .links is red):