bootstrap .row inside a .row-fluid container - javascript

I want to have the ability to place a fixed span div ( span1..span12) inside a .row-fluid container.
<div class="row-fluid">
<div class="span5 red">
<div class="row">
<div class="span3 gray">
I need this to span exactly 300px, not 31% of its parent
</div>
</div>
</div>
<div class="span5 blue">
</div>
here is the working jsbin ( sadly you need to enlarge the output pane )--> http://jsbin.com/uwecuv/1/edit
The idea is that the css selector (.row-fluid span3) would take precedence in this case.
Do you guys have any ideas how I can make the 'div.span3.gray' span 300px?
The reason is that in the real scenarion it will be an absolutely positioned div, and I don't want it to inherit the parent's size ( which btw will be just a div with an input box ).
Thanks!

Bootstrap grid system is designed so that span3 means that element has width=3/12 of the container width (row or row-fluid). So if you need div with fixed width=300px(not 3/12 of container width) you need to use your own css class with width=300px. Or you can use fixed layout without responsive css.

Related

Child element changing parent element height (css)

I'm trying to make the div not expand over user visibility, but when I dock multiple items in this div, it expands off screen.
Here is an example.
I know, it sounds long, but I was trying to reproduce the entire layout to find the problem.
<body>
<div class="container">
<div class="head"></div>
<div class="main">
<div class="painel"></div>
<div class="dash">
<div class="head-dash"></div>
<div class="content-dash">
<div class="email-list">
<div class="head-content"></div>
<div class="content">
<div class="item"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
https://jsfiddle.net/ricardosc12/rb2kjtfh/12/
change the variable quant -> 50 and you will see the problem
Probably its height setting to 100% ignores its adjacent element, but how can I make it take up the remaining space without expanding later.
As you can see in the example, the email-list class has expanded over content, pushing all the main ones down.
I'm looking for a solution to this using flex, but can you suggest other possibilities.
I looked around but it didn't work.
Make a div fill the height of the remaining screen space
It's not the perfect answer but will solve your problem.
change your height of content-dash to this
.content-dash{
height: calc(100vh - 140px) ;
padding: 25px;
background: #EEEEEE;
}
We will make the content-dash's height to 100vh and subtract the height of head-dash and head from it.

Limit the fixed sub div's height on scrolling towards parent div's height

At the moment the div(.name) that I would like to be in position:fixed is perambulating all over my page and divs everywhere. I don't want to put a background and z-index to all divs in the page, just not to see the fixed one, which should be limited only at its row - the header one; at some places I have a space between two rows so even if I put z-index and position: relative(playing with max-height as well, without any success), I see the fixed div between the rows. So what can I do so the fixed one to be scrolled only inside of its row - header and to disappear when the header disappear from the viewport. Thank you guys in advance!
.name {
margin - top: 5 %;
position: fixed;
}
<div class="row header">
<div class="col-xl cover">
<div class="row justify-content-md-center">
<div class="col col-lg-2"></div>
<div class="col-md-auto name" id="nameScroll">
Something here
</div>
<div class="col col-lg-2"></div>
</div>
</div>
</div>
correct me if I am wrong, but, your problem is that you want to scroll a div within a row, you may try, overflow: auto, over the parent div.
link of position property for some guidance as how it works -
https://www.w3schools.com/cssref/pr_class_position.asp

Resize container dynamically when font size changes

I am displaying every word in a sentence in separate div using inline-block with max-width of 120px. When I try to increase the font size on parent div my inline-block of div get overlaps due to large font size.
Is there any way to programmatically calculate the max-width required for inline-block of div to be used after increasing the font size?
Here is sample code snippet:
jQuery('.btnIncFont').click(function(){
jQuery('.parentDiv').css('font-size',parseInt(jQuery('.parentDiv').css('font-size'))+2);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="btnIncFont">+</button>
<div class="parentDiv">
<div style="display:inline-block;max-width:120px">This is a test1</div>
<div style="display:inline-block;max-width:120px">This is a test2</div>
<div style="display:inline-block;max-width:120px">This is a test3</div>
<div style="display:inline-block;max-width:120px">This is a test4</div>
</div>
Keep pressing the + button and at certain stage you will find that the div is overlapping each other. I want to fix this with calculation for my max-width to attain the exact ratio according to initial size 120px after incrementing font-size.
When you increase the font-size make sure you are also increasing the line-height.
I don't think you want to go down the road of programmatically setting the width of each div, let the CSS do it for you. I'm assuming you aren't already doing that, if so, try setting it to auto. Lastly, I may suit you better.
Sorry for the vague answer but if you post the code I'll give you a more specific one.
Your CSS:
.v {
word-wrap:break-word;
display:inline;
font-size:140px;
border:2px solid blue;
max-width:120px;
}
and HTML:
<div>
<div class="v">This</div>
<div class="v">is</div>
<div class="v">a</div>
<div class="v">test</div>
</div>
Added the break-word css option. Here is the full fiddle: http://jsfiddle.net/eugensunic/76KJ8/74/
I think I have got a solution. Never thought that it would be as much simple as using just a span inside child div to get the element width after increasing font-size. Then replacing max-width on child div with span width value. It will gives you the exact ratio based on your initial max-width value of 120px after incrementing font-size and at the same time also take care to wraps the div in case it exceeds the width of parentDiv.
Here is code snippet:
jQuery('.btnIncFont').click(function() {
jQuery('.parentDiv').css('font-size', parseInt(jQuery('.parentDiv').css('font-size')) + 2);
var spanWidth = parseInt(jQuery('.parentDiv div span').css('width'));
jQuery('.parentDiv div').css('max-width', ((spanWidth < 120)?120:spanWidth) + 'px');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="btnIncFont">+</button>
<div class="parentDiv">
<div style="display:inline-block;max-width:120px"><span>This is a test1</span>
</div>
<div style="display:inline-block;max-width:120px"><span>This is a test2</span>
</div>
<div style="display:inline-block;max-width:120px"><span>This is a test3</span>
</div>
<div style="display:inline-block;max-width:120px"><span>This is a test4</span>
</div>
</div>
use width auto....
`<div>
<div style="display:inline-block;width:auto">This</div>
<div style="display:inline-block;width:auto">is</div>
<div style="display:inline-block;width:auto">a</div>
<div style="display:inline-block;width:auto">test</div>
</div>`

What is the purpose of the <div id="Circle"> on this website?

On this website http://science-inc.com/ (on the index.html),
what is the purpose of div#Circle?
<div id="left-section">
<h1>Science</h1>
<canvas width="1278" height="614"></canvas>
<div id="Circle"></div>
</div>
It is an empty element. It has :before and :after pseudo elements, but they don’t seem to be doing anything.
It just a blank <div> that's making no effect on the view of page because it has height 0 (because it has no content), width same as it's parent element and no other staying.so there is no mean of it.

Position elements in a top->down left->right manner

I have a main container <div> which holds 4 or 5 other sub <div>s. The container has a fixed height and a fixed width. What is the best way to position the sub divs so that they are arranged in a top->down then left->right manner?
I've tried floating the sub divs but that just gives me a left->right then top->down order.
Basically I want this
[ sub div 1][sub div 3][sub div 4]
[ sub div 2][ ][sub div 5]
When I mark up the code like this:
<div id="container">
<div class="subdiv">sub div 1...</div>
<div class="subdiv">sub div 2...</div>
<div class="subdiv">sub div 3...</div>
<div class="subdiv">sub div 4...</div>
<div class="subdiv">sub div 5...</div>
</div>
Notice that the sub divs can have variable heights but fixed widths.
Thank you,
To my knowledge, there's no way to do it.
There is some CSS3 that works only on some browsers to support multi-column layout (-moz-column-width, etc...) but I don't know whether it would work with DIVs in the content. And I'm fairly certain it it's not supported in IE7
The way I'd do it would be to break up the content into 3 columns containers
<div id="container">
<div class='column'>
<div class="subdiv">sub div 1...</div>
<div class="subdiv">sub div 2...</div>
</div>
<div class='column'>
<div class="subdiv">sub div 3...</div>
<div class="subdiv">sub div 4...</div>
</div>
<div class='column'>
<div class="subdiv">sub div 5...</div>
</div>
</div>
Use this CSS on the DIVs:
display: inline-block
The only way to do this natively is to use CSS3 columns (as Damp mentioned) but there are some articles on how to achieve a similar effect with JavaScript as seen in this question. That case is actually more complicated than yours.
I'm thinking the best way to do it with JS would be to first split it evenly into column containers as Damp suggested with a best guess. This should help for those with JS disabled. Then us JS to measure heights of the subdivs and move them if the initial guess was off. Assuming you're using a server side language to generate the page, you should be able to split the columns evenly. You can probably even make a good estimation on the split by checking the length of content (assuming its text) as a heuristic for the likely height of the subdiv.

Categories