How do I get an element to always occupy a specific percentage of its parent element, even when the browser is resized?
Tags: jquery,html,css,html5,jquery-ui
Problem :
Note: I know that elem {height: 90%}
exists.
What I need:
- an element to occupy x% width and y% height of its parent element, regardless of size
- the parent has margins and padding
My problem:
- it looks great at first, but when I make the browser window smaller, content starts spilling out of the bottom of the parent. This is super depressing. It looks to me like the size of the
#load
div is 90% of its parent (as requested; see stylesheet below); unfortunately this 90% doesn't take margins or padding into account. What is going on here? If the answer is just that percentages don't work "like that" when there are margins/padding, how do I specify that an element occupies x percent of its parent after deducting margins/padding? Also, note that jQueryui uses css that I would like to avoid touching, if possible.
My markup:
<div id="tabscontainer">
<div id="tabs">
<ul>
<li><a href="#create">Create</a></li>
<li><a href="#load">Load</a></li>
</ul>
<div id="create">
something or other
</div>
<div id="load">
... there is a lot of content here ...
</div>
</div>
<script>
$(document).ready(function() {$("#tabs").tabs();});
</script>
My styling:
html, body {
height: 100%;
}
#tabscontainer {
height: 95%;
}
#tabs {
height: 100%;
}
#tabs > div {
height: 90%;
overflow: auto;
}
Also, the default jQuery styling of tabs is in effect (with no changes from me).
Solution :
I think the problem is that the styles from jQuery UI are in PX while the rest are in %. You usually run into problems when you combine that. Try setting margins, paddings and borders in % (I know you don't want to mess with jQuery CSS, but you can override it with !important or similar).
CSS Howto..
I figure you want something like this: http://jsfiddle.net/v4sch/28/
It appears that your HTML syntax is incorrect for the table cell. Before you try the other idea below, confirm if this works or not... You can also try adding...
One can't remove the call class with a standard jqGrid method. So you have to do this manually: var iCol = getColumnIndexByName(grid,"ColumnName"), tr = grid[0].rows.namedItem(rowid), // grid is defined as...
The reason is because the startOver function is hiding all the images. $("#images").hide(); You need to hide the individual image tags instead of the div with $('#images img') I added...
Here's a way to do it without adding any additional markup, though you do need to add unique classes to each of the anchor links. CSS: .navbar-default .navbar-nav>.active>a:before, .navbar-nav>li>a:before {...
Place this inside of your CSS file: @font-face { font-family: 'your font name'; src: url(path/to/your/font.woff); } .anyClassToUseFont { font-family: 'your font name' } Make sure the path to the .woff...
Simple add this: div{ display: inline; } ...
This seems to be an outstanding bug in Google Chrome. You are better off parsing the strings either with javascript or server side. http://groups.google.com/a/chromium.org/group/chromium-bugs/browse_thread/thread/b54006f7a2b5fe5b http://code.google.com/p/chromium/issues/detail?id=31349 Bug Reproduced:...
Facing the same challenge, I ended up extending javax.faces.application.ResourceHandlerWrapper and javax.faces.application.ResourceWrapper to append "&v=x.y.z" to the result of ResourceWrapper#getRequestString(). I saw this kind of solution implemented by Primefaces and Openfaces....
Just of the top of my head, I think that if you're willing to use HTML5 and use the <input type="text" name="year" required> property, that you should be able to...
overflow: scroll doesnt work in Android 2.3.x, you will need to build the scrolling yourself by listening for drag events. see the iScroll library...
I have found a work around though I'm not 100% if it is the way to go but I added margin-bottom: -25% to all images and it appears to have...
.single_box a {text-decoration:none;} ...
You can't select JSON with CSS. It operates on a DOM. It looks like you aren't trying to though. You just have a text node (which you created using half...
Setting display: inline-block; on your span should fix this. As is pointed out in the comments below, span is by default an inline element, but that does not mean that...
The problem is that you have not defined a top value on #header ul. This should fix it: #header ul { ... top: 0; } JSFiddle example...
To be a true working blog, the other answers would have you dynamically create css and have a class or id for each date you wanted displayed. It would be...
The answer is not to use an <img> tag and try to set a background-image in css. Either use a <div> or <img src="pic.png"> and not an invalid mix of...
you need to use $(window).scroll() event to update the left nav bar
Just a typo : it is not atrr, but attr ;-)
You do it like this: $('#bx-next').css('z-index', '-1'); If you want more than one, you can do this: $('#bx-next').css({ 'z-index' : '-1', 'color' : 'red', 'background' : 'blue' }); You don't...
Here is a simple example, made of DIVs with some CSS and a little jQuery to check the checkbox when the button is clicked: jsFiddle demo HTML: <div id="container"> <div...
Depends how you want to display the item. You could use display: block, or display: initial if you want to display the divs initial state. More display options found here...
Based on what Thomas suggested, this is a complete solution 1- myCellList.css .cellListWidget { } .cellListEvenItem { display: inline-block; cursor: pointer; zoom: 1; } .cellListOddItem { display: inline-block; cursor: pointer;...
According to the CSS3 Text draft, you can use word-break: break-all (on the dd elements). The names are misnomers; the settings declare that any string in the content may be...
Do you mind sharing why percentages wouldn't work? Usually that's what I would recommend if you're wanting the page to scale correctly on window resizes. I guess if you really...
CSS transitions only animate from one set of styles to another; what you're looking for is CSS animations. You need to define the animation keyframes and apply it to the...
The script you are using is automatically centered by default. The trick to centering is to use: 'margin: 0 auto' for the parent element. So now you gotta figure out...
here is a visual of my result: and the code (as minimal as possible): <head> <title></title> <style> div.main { clear: both; } div.main > div.column { position: relative; width: 100px;...
Use a translateX value of -100%. Percentage transformations are based on the element's dimensions, so 100% would be equal the element's width. At this point no JavaScript would be needed....