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>`
Related
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.
I'm not able to change the height of the div when showing the error messages after submitting the form so that there is no overflow. I can set the height property to 1100px so that there is no overflow anymore but it looks quite ugly having so much white space.
I created a JSFiddle because it is a lot of code and since most of the code is relevant for the problem it is quite difficult to reduce it.
<div class="contact-form-wrap">
<div class="contact-form-wrap-left">
<div class="col full-width"><ul class="error-message"></ul></div>
</div>
<div class="contact-form-wrap-right ">
</div>
</div>
I tried to set the height to auto with a min-height of 760px. The div still does not grow. I changed the display property of contact-form-wrap-left to display: inline-block but since float is used this seems not to work.
https://jsfiddle.net/ArisMartinAccola/ud8x5e9o/
I hope someone can help me.
Change place of divs like this
<div class="col full-width"><ul class="error-message"></ul></div>
<form action="config.php" method="post" class="contact-form">
After that set col full-width with position relative and contact-form to relative as well. Of course, use create ID's for both of those
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.
So let's say have the following content structure:
<div class="wrapper">
<div class="contentOne" style="width:50px"></div>
<div class="contentTwo"></div>
<div class="contentThree"></div>
<div class="contentFour"></div>
</div>
What I want to achieve on page load, is for the width of the 1st div (contentOne) to be picked up and increment the width of the other 3 divs by 50px. In the end I want the following:
<div class="wrapper">
<div class="contentOne" style="width:50px"></div>
<div class="contentTwo" style="width:100px"></div>
<div class="contentThree" style="width:150px"></div>
<div class="contentFour" style="width:200px"></div>
</div>
First prize would be for this to be possibly using CSS3 Calc. If not JS will be a close 1st princess.
Thanks
Right now, CSS has no preceding-sibling selector (although there is a "following sibling" selector, for some reason), so a pure CSS solution isn't yet possible. jQuery would be something like this:
$('div:not(:first)').each(function()
{
$(this).width($(this).prev().width() + 50);
});
Use Jquery to this . The code would be something like this. Please make the changes appropriate this is just a demo code.
var widthOfFirstChild=$('.wrapper').eq(1).width();
$('.width div').each(
function(){
$(this).attr('style':widthOfFirstChild+50);
widthOfFirstChild=+50
});
The scenario:-
A published HTML page has position:absolute DIVs and all DIV heights are set to specific px values. The page is editable via an online CMS such as Surreal or Cushy. The editor enters more content that the DIV was designed to take. The result is that the extra content overflows the DIV and the page design is trashed.
Is there any way that when an editor does this that the DIV height expands AND all other DIVs on the page move down? Bare in mind that the DIV heights cannot be set to 100% but have fixed px values.
I am assuming the solution maybe jQuery or JavaScript - any ideas?
<body>
<div id="two" style="position:absolute;left:163px;top:0px;width:738px;height:269px;z-index:5;padding:0;">
<img src="images/two.jpg" id="two" alt="two" border="0" title="two" style="width:738px;height:269px;">
</div>
<div id="three" style="position:absolute;left:0px;top:350px;width:900px;height:294px;z-index:6;" class="editable">
<!-- div content -->
<!-- this is where the user/editor will add content -->
</div>
<div id="four" style="position:absolute;left:0px;top:0px;width:900px;height:323px;z-index:7;padding:0;">
<div id="five" style="position:absolute;left:0px;top:0px;width:162px;height:269px;z-index:0;padding:0;">
<img src="logo.gif" id="logo" alt="Logo" border="0" title="Logo" style="width:162px;height:269px;">
</div>
I don't see exactly the scenario, but have you considered the scroll within your fixed size divs ?
Give a class to those divs, such as
<div class="bescrollable"></div>
and then in your css :
.bescrollable {overflow:auto;}
scrollbars will be added when overflows occur
You can set height of the div according to the content like this:
.container {
position: absolute;
width: 400px;
height: 400px;
}
.content {
width: 100%;
height: 100%;
}
<div class="container">
<div class="content">...</div>
</div>
$('.container').css('height', $('.content').height());
Here a fiddle: http://jsfiddle.net/Kdktw/
As CBRRacer mentioned in the comments, if we could see the HTML, the answer would be more accurate to your situation.
I hope this helps!
This would be predicated on the height of the content within the box. Probably the best method would be to have the height of the content div set to auto and use javascript to get the height of the element.
// Using jQuery
var contentDivHeight = $('#myContentDiv').height();
var startingOffset = 250; // The height of the div original set at startup
Then you could simply add this height to each of the primary display controls that would have to be moved "down". If you assigned them all a common class they could all easily be selected (such "primaryInterface" or something).
$(document).ready(function() {
$('.primaryInterface')each(function (i) {
var newTop = this.offset().top + contentDivHeight - startingOffset;
var newLeft = this.offset().left;
this.offset({ top: newTop, left: newleft });
});
});
This code is untested, but ideally, once the page loads, it would find all of the elements with the specified class and set their top offset to be the difference between the starting height of the div and the resultant height.