I know there are a lot of these questions already answered but non that fit my requirements. I have a table of unknown height and width and I need to, if the table is too high so that one needs to scroll through it, that the table headers stay fixed and follow the scroll. All solutions I've seen require a fixed height of the table. I would also want the scroll to be invisible while still functional. Can this be accomplished or do I need the fixed height?
My CSS so far allows me to scroll both vertically and horizontally (I only want the vertical scroll) but with fixed height and visible scroll bar:
table.sol-compare-table {
box-sizing: border-box;
overflow: hidden;
display: table;
width: 100%;
}
table.sol-compare-table thead, table.sol-compare-table tbody {
float: left;
width: 100%;
}
table.sol-compare-table tbody {
overflow: auto;
height: 150px;
/*overflow-x: hidden;*/
}
table.sol-compare-table tr {
width: 100%;
display: table;
text-align: left;
}
Here is my HTML:
<table class="table sol-compare-table">
<thead>
<tr>
<th>
<div>
<a class="sol-pdf-generator hover-gray-icon sol-share-icon" target="_blank" ng-href="#">
<i class="fa fa-file-pdf-o"></i>
Ladda ner som PDF
</a>
<a class="sol-share-facebook hover-gray-icon sol-share-icon" onclick="#">
<img src="#" alt="facebook">
</a>
<a class="sol-share-twitter hover-gray-icon sol-share-icon" onclick="#">
<img src="#" alt="twitter"><!--<i class="fa fa-twitter"></i>-->
</a>
<a class="sol-share-mail hover-gray-icon sol-share-icon" onclick="#">
<i class="glyphicon glyphicon-envelope"></i>
</a>
</div>
<h2 class="sol-compare-heading">Allmän Information<h2>
</th>
<th ng-repeat="unit in units" class="sol-compare-heading">
<div>
<a href="#/unitDetail/{{unit.Id}}">
<img class="detail-main-image" ng-if="getImageOfUnit(unit).Value.Id" ng-src="#"></img>
</a>
</div>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="#">
<td>Name</td>
<td ng-repeat="unit in units">
<span ng-if="unitAttr.Value != null">
<span print-attribute="#"></span>
</span>
<span ng-repeat="#" ng-if="unitAttr.Values">
#
</span>
<span ng-if="# == null && unitAttr.Values == null">
-
</span>
</td>
</tr>
</tbody>
</table>
EDIT
I tried with using position:fixed at the table header and that almost accomplish what I'm after, only that it should be fixed at the top of the page at all times (when scrolling down it should follow the scroll but the same position in the browser window). This JSfiddle is the easiest way to show where I'm at atm I guess; http://jsfiddle.net/rwqkokgy/5/
For vertical scrollbar You have to use overflow-y:scroll; overflow-x:hidden;
You can use overflow-y:auto; and vertical scrollbar will be show/hide depend of table content.
There is one example, but with two tables. First one is header and second for table content. Maybe You can achieve on this way.
jsfiddle example
In this example is one button, too. For simulating with and without scrollbar, depending of table content.
That button and js function called chVl You can remove. First function called checkW is used if You resize Your browser.
I hope so this will help You.
Edit :
If You want vertical scrollbar all time, then do next (in provided jsfiddle example) :
Remove onload and onresize from body
Remove complete javascript
In #container (css) for overflow-y replace from auto to scroll
About height in #container, You can change it by Your needs.
And, of course, remove that button, like i wrote above. His purpose is just for simulation, nothing else.
I'm now using an Angular directive called "sticky" which makes it so that the "sticky" element (which I set to be the table header) sticks to the top of the screen when scrolling.
For more information about this directive, please follow this link: http://angularscript.com/angularjs-directive-create-fixed-elements-scroll-angular-sticky/
It was very easy to implement and required almost no coding at all.
Related
I'm trying to implement a virtual scroll in my image gallery. My problem is that the implementation doesn't work correctly. First, the elements are displayed in vertical position, when in fact they should respect the horizontal breakpoints and only then respect the vertical scroll. Second, with the scroll elements appear with huge spacing.
Does anyone know how I can solve this problem? thanks
DEMO
HTML
<div [ngSwitch]="viewMode" style="height:100%; width:100%">
<div id="tab2" *ngSwitchCase="'tab2'" style="height:100%; width:100%">
<div
style="margin-left: 16px; margin-right: 16px;height:100%; width:100%"
class="first"
>
<ng-container
*ngIf="
arrayDeNomesCategorias.length == 0 ||
arrayDeNomesCategorias == undefined
"
>
<ul
class="mdc-image-list my-image-list"
style="height:100%; width:100%"
>
<cdk-virtual-scroll-viewport
itemSize="50"
style="height:100%; width:100%"
>
<ng-container *cdkVirtualFor="let i of images; let j = index">
<li class="mdc-image-list__item">
<div class="mdc-image-list__image-aspect-container">
<img
src="https://material-components-web.appspot.com/images/photos/3x2/{{
i + 1
}}.jpg"
class="mdc-image-list__image"
/>
</div>
</li>
</ng-container>
</cdk-virtual-scroll-viewport>
</ul>
</ng-container>
</div>
</div>
</div>
Problem
Correct, but without the implemented scroll :(
I updated your example here.
Your problem was mainly css and there seem to have been (at least) 2 problems:
Your are giving .mdc-image-list__item class min-height: 400px and max-height: 400px. That basically means that all your .mdc-image-list__item containers will have 400px height (so height: auto is kind of useless). Removing this will remove the white space between your images.
If you want to have scroll as well as elements on the same page you should use a flex container with flex-wrap: wrap.
In order to do this I used the following snippet (for your case):
:host ::ng-deep .cdk-virtual-scroll-content-wrapper {
display: flex;
flex-wrap: wrap;
}
You can read more about host and ng-deep here. But please be aware that according to this article (and not only) is recommended to avoid using it in recent version of angular. For the sake of simplicity I used it on your example but you might want to avoid it in production.
(extra) : As a small improve I also removed the duplicated margin: 10px; height: auto; max-height: 400px; properties from .mdc-image-list__item media queries (and only leaved the initial one with no media query). It will be applied anyway since there isn't anything to overwrite it and just changing just the with on the media queries should be enough.
I want to add an image (img src="~/img/logo2.jpg) next to below image in a different column.
<header class="header overlay"
id="core_view_Header_0"
style="display: block;">
<!-- visible bar -->
<div class="col-md-12">
<table style="width: 100%">
<table style="display: <inline-block>;">
<table style="float: left;">
<tr>
<td>
<a class="logo" href="#" target="" tabindex="12">
<img src="~/img/logo1.png">
</a>
</td>
To fix this problem, you could put the image in its own paragraph with nothing to its left or right (except maybe another image):
The other option is to tell the web browser to push the graphic all the way to the left or right and make the text fill in NEXT to it, as the cat graphic to the right is doing here.
This is the code you need to align an image to the right:
**<img src="http://www.example.com/graphic.jpg" style="float: right;** margin-left: 5px; margin-bottom: 5px;"**>**
(The parts without ** are optional.)
What's all that gobbledygook mean? Let's break it down.
<img ... > is the placeholder for an image.
src="..." tells the web browser where the image's data is stored or uploaded (its location, its URL).
style="..." style tells the web browser to expect a special set of codes called CSS (never mind what that is) which explain how you want the image to be displayed: its size, its layout, whether it has a border, and so on. Styles can also be added to set text colors, sizes and fonts. If HTML is the main chassis of the car, styles tells the web browser about the car's paint job and whether it comes equipped with bluetooth or cup holders.
float: right; means push the image as far to the right as it will go. If there's already something there (the sidebar, another floated image), then this image will squeeze in just to the left of that. This is how you tile images side by side. You can also float: left; to make images behave just like the letters of this paragraph: they'll start at the left-hand margin, then tile from left to right across the column until they run out of room, then they flow onto the next line.
margin-left and margin-bottom are optional. They add a little bit of an empty border (px means "pixels") to the left and under the image so things aren't mashed right up against it. If you have floated an image to the left, you should probably include a margin-right to add padding there.
VERY IMPORTANT: TO TURN OFF "FLOAT", use the following command:
<p style="clear: both;">
Why would you want to do that? Well, if an image is floated all the way to the right or left, whatever you write after that will attempt to fill in around it. For example, the text above filled in around that cat picture.
If you don't want the following paragraph to fill in next to the floated object, then you need to use the clear command to draw an invisible horizontal line across the page that says "everything after this has to start on a new paragraph, below the floated image(s)."
Add another img tag within the same <td></td>.
Try adding some external CSS styles to your rather than inline-CSS (Looks better and clear). Also make sure to give style for your image size.
If you would like your imges to be vertical aligned, try: display:flex and flex-flow:column
See snippet below:
header {
display: block;
}
table {
width: 100%;
display: inline-block;
float: left;
}
td {
display: flex;
flex-flow: column;
}
<header class="header overlay" id="core_view_Header_0">
<!-- visible bar -->
<div class="col-md-12">
<table>
<tr>
<td>
<a class="logo" href="#" target="" tabindex="12">
<img src="~/img/logo1.png">
</a>
<a class="second-img" href="#" target="" tabindex="12">
<img src="~/img/logo2.png">
</a>
</td>
</tr>
</table>
</div>
</header>
I'm trying to make a movie manager to get me back working with rails again. I'm reading the movies from a database, and trying to present their covers in a responsive grid.
I'm new to using Twitter Bootstrap, and having some weird issues with weird spacing. All my images are the same height and width, so that shouldn't be an issue.
To see the issue, go here: http://jsfiddle.net/32AcT/ (Due to the responsive grid, you may have to make the view window bigger, so they're not all in a single column.) I'm simply doing:
<ul class="thumbnails">
<li>
<a href="#">
<div class="caption">2 Fast 2 Furious</div>
<img alt="2 Fast 2 Furious" class="thumbnail" height="111" src="http://cf2.imgobject.com/t/p/w500/4rDV8TgaILHRfX1IRgpysjkD9A0.jpg" width="74" />
</a>
</li>
...
</ul>
Here is an example of what it looks like (weird spacing highlighted with pink box):
I understand why the widths are off, due to the caption lengths being longer than the image's width (although I'd like to fix that somehow too). Why is this happening, and is there any good method to prevent it?
try this one i think it will solve your prblem
http://jsfiddle.net/32AcT/1/
.thumbnails > li { width:100px; }
.thumbnails .caption{ overflow :hidden; text-overflow:ellipsis; white-space:nowrap; }
.thumbnails img{ height:111px; width:74px}
main issue with bootstrap-combined.min.css line no 23 height:auto;
img {
max-width: 100%;
width: auto 9;
height: auto;
vertical-align: middle;
border: 0;
-ms-interpolation-mode: bicubic;
}
If I get the problem right, the caption is causing it. What would you say to a solution like this: http://jsfiddle.net/32AcT/4/
The difference from your solution is that the Caption is inside the thumbnail (seen in code 1) div and thus is limited in the width (seen in code 2). It could be that you have to play a round with the height of the div but I guess that would be the "best" solution for this.
Code 1:
<li class="span4">
<div class="thumbnail">
<img src="http://cf2.imgobject.com/t/p/w500/1ZjDmPKMUtout8hR77qmK1llgls.jpg">
<div class="caption">
<h3>Along Came a Spider</h3>
<p>Action Action</p>
</div>
</div>
</li>
Code 2:
.thumbnail{
height:650px!important;
}
Why doesn't this work (i.e. div content is not centred - vertically)?:
<div style="display: table;">
<div style="vertical-align: middle; display:table-cell; height: 100px; font-size: 11px;">
<a target="_self" runat="server" href="~/daily.aspx">
<img src="images.png" /></a>
content in div<br />
</div>
</div>
Googling everywhere in understanding how I can vertically align a div and it's content has failed.
Anybody any ideas in the best css styling for content in a div.
UPDATE
Need to explain that I need the text vertically aligned to the image not just the div. The text is bottom to the image. Might have to use floats.
If you only need the text aligned in the middle of the text, this will do:
<div>
<div>
<a target="_self" runat="server" href="~/daily.aspx">
<img src="images.png" style="vertical-align: middle;"/></a>
content in div<br />
</div>
</div>
and here's an example http://jsfiddle.net/Tetaxa/tVQc6/
If you are displaying an element as a table, why not use a table?
As far as I know though, it is not possible to center content unless you know it's height. IF you know the height you can use something like this:
.container {
position: relative;
}
.vertical {
position: absolute:
top: 50%;
height: 200px;
margin-top: -100px; // This is half the height
}
why dont You try using <table>? or do u want to do it with <div> itself?
I know this is an old question,
but did anyone try display:table/table-cell/table-row instead? That should be fine.
(ofcourse not working on older IE etc.)
Types from W3Schoools:http://www.w3schools.com/cssref/pr_class_display.asp
These types can be set to any html element, and it should render as a part of a table (or a table itself).
This meaning you should be able to use divs to render data as if it was in a table.
I have not tested this though and the last time I used this was years ago.
able The element is displayed as a table
table-caption The element is displayed as a table caption
table-cell The element is displayed as a table cell
table-column The element is displayed as a table column
table-column-group The element is displayed as a table column group (like )
table-footer-group The element is displayed as a table footer row group
table-header-group The element is displayed as a table header row group
table-row The element is displayed as a table row
table-row-group The element is displayed as a table row group
I have two elements (a button and an anchor tag) both with a dynamical text inside that grow to the length of their content.
I cannot know which one of them will be the longest at compile time, nor can I know what the maximum/minimum width will be.
The shorter one should always adapt to the longest one.
<span id="buttonsColumn">
<button type="submit" name="powerSearchSubmitButton" id="powerSearchSubmitButton">
<span><em><%=ViewData.Model.T9nProvider.TranslateById("CommonWeb.Search")%></em></span>
</button>
<a class="linkButton" href="something">
<span><em><%=ViewData.Model.T9nProvider.TranslateById("CommonWeb.Advanced")%></em></span>
</a>
</span>
The wrapping span can be changed to anything desired.
Any ideas?
You could try something like this:
#buttonsColumn {
display: block;
float: left;
background-color: #F88;
}
#buttonsColumn button,
#buttonsColumn a {
display: block;
}
#buttonsColumn button {
width: 100%;
background-color: #8F8;
}
#buttonsColumn a {
width: 100%;
background-color: #88F;
}
As I see it, you could do it two ways:
Figure out the length on the ASP side and set a variable with the length of the larger, then use that in a size property on each.
Write a javascript function to figure out which of the two is larger and set the length of both to that.
Might I suggest you give up and use tables?
They are still part of the specification after all, and what you're doing could be construed as tabular data. All you'd need to add would be a style="width:50%" to each table data tag and a style="width:100%" tag to the button.
<table>
<tr>
<td style="width:50%">
<button type="submit" style="width:100%" name="powerSearchSubmitButton" id="powerSearchSubmitButton">
<span><em><%=ViewData.Model.T9nProvider.TranslateById("CommonWeb.Search")%></em></span>
</button>
</td>
<td style="width:50%">
<a class="linkButton" href="something">
<span><em><%=ViewData.Model.T9nProvider.TranslateById("CommonWeb.Advanced")%></em></span>
</a>
</td>
</tr>
</table>
You can probably get rid of those spans within the button and anchor tags, they don't seem to serve a purpose unless your CSS is doing something with the span children of the container.