开发者

html + css dynamic width with overflows

I don't know how to accomplish the following in html, I would prefer if the solution would be strictly html + css, javascript/jquery is being used on the site, but I don't prefer my layout to be dependant on javascript.

Section A is a list of indeterminate width, it gets populated from data from a database so it could be from 9em-15em width. Section B has text that overflows as well. I want A to take up the required width to display its content and then I want Section B to take up the rest of the width.

I开发者_运维百科s this possible, if so how? Do you know of any good books that can give me a good foundation for html+css

---------------------------------------------
|          |^|                             |^|
|          | |                             | |
|          | |                             | |
|          | |                             | |
|    A     | |             B               | |
|          | |                             | |
|          | |                             | |
|          | |                             | |
|          | |                             | |
|          | |                             | |
|          |v|                             |v|
----------------------------------------------

This is what I currently have, but if Section B overflows then it forces "A" list to shrink by making the divs to go to two lines which is unacceptable.

<div id="SectionA" style="float:left">
 <div>Just TEst data</div>
 <div>Just data</div>
 ...
 <div>Just data</div>
</div>
<div id="SectionB" style="float:left">
  <!-- A bunch of content here -->
</div>


Look at it another way:

<div id="SectionB">
 <div id="SectionA">
  <div>Just TEst data</div>
  <div>Just data</div>
  ...
  <div>Just data</div>
 </div>
 <!-- A bunch of content here -->
</div>

div#SectionA {max-width:15em; float:left;}

div#SectionB {width:100%;}

this should work perfectly


    <div id="SectionA" style="float:left;width:auto;max-width:NUMBERpx">
 <div>Just TEst data</div>
 <div>Just data</div>
 ...
 <div>Just data</div>
</div>
<div id="SectionB" style="float:left;width:auto;max-width:NUMBERpx">
  <!-- A bunch of content here -->
</div>

Maybe this can work


<style>
#sectiona{
float:left;
overflow:auto}
#sectiona>div{
white-space:no-wrap}

</style>

<div id="sectiona" style="float:left">
 <div>Just TEst data</div>
 <div>Just data</div>
 ...
 <div>Just data</div>
</div>
<div id="sectionb" style="float:left">
  <!-- A bunch of content here -->
</div>

I think that should work.

Your schematic shows the columns to have equal height though. That is hard to achieve using css only


Correct me if I'm wrong, but your scheme seems to require independent scrollbars for each section, akin to frames of previous HTML generation. If so, you will need parent container div for both section with fixed height, and set height of both section to 100%.

<style>
#frameset {
  background-color: lightBlue;
  position: absolute; /* this is my way of emulating frameset */
  bottom: 0; /* you can specify height instead if you're */
  top: 0;   /* not using absolute positioning */
  left: 0; right: 0;
}
#menu, width {
  width: auto;
  height: 100%;
}
#menu {
  background-color: bisque;
  max-width: 15em;
  float: left;
  overflow-y: scroll; /* feel free to change to auto, but remember:
   scrollbar is appended from inside. If you use script to change its
  content, sentences that previously just fit in one line may suddenly need
  a line break in the middle when the scrollbar appears */
}
#content {
  overflow-y: auto;
}
</style>

<div id="frameset">
  <div id="menu">aaaaaaaaaaa</div>
  <div id="content">b</div>
</div>


I'll give this one a shot:

<!DOCTYPE html>
<head>
    <title>Testing Columns</title>
    <style type="text/css">
    #a { float: left; }
    #b { overflow: hidden; }
    </style>
</head>
<body>
<div id="a">
    <ul>
        <li>This is</li>
        <li>Some variable width</li>
        <li>content</li>
        <li>for testing</li>
        <li>stuff</li>
    </ul>
</div>
<div id="b">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent mauris erat, porta et pulvinar vel, iaculis sed arcu. Vestibulum non eros quis eros congue scelerisque in sed tortor. Vivamus scelerisque, lorem auctor faucibus tempor, magna diam porttitor leo, vel tempor elit sapien accumsan mauris. Sed interdum est at elit cursus euismod. Donec et erat est, non molestie urna. Nam sollicitudin turpis in nunc viverra tempus. Mauris gravida viverra massa vitae ornare. Integer interdum aliquam viverra. Vivamus ut libero elit, at semper ligula. Sed iaculis risus ut ligula molestie tincidunt. Ut ac felis libero, aliquam mattis tellus. Proin non massa a odio bibendum laoreet in eu ligula. Aliquam ac elit a nisl laoreet commodo. Integer ullamcorper tempor mauris in adipiscing. Suspendisse ultrices enim vel orci adipiscing tincidunt. Praesent justo dui, ullamcorper ut venenatis posuere, molestie in arcu. Sed libero justo, facilisis sit amet luctus sit amet, cursus vel leo.</p>
    <p>Curabitur quis felis sit amet enim congue euismod vel a nibh. Sed auctor justo in nulla ullamcorper malesuada. Duis eu purus nec quam ornare congue vitae vel dui. Cras faucibus suscipit tincidunt. Nunc rutrum pretium diam ac venenatis. Proin non dui ligula, quis eleifend massa. Phasellus condimentum fringilla velit. Sed aliquet sodales tortor, ut pharetra mauris imperdiet vel. Etiam tempor augue non felis fermentum varius. Praesent facilisis condimentum commodo. Ut mollis tristique eros, non dapibus enim sollicitudin quis. In hac habitasse platea dictumst. Maecenas enim nibh, sollicitudin sit amet adipiscing vitae, aliquet pretium dui. Vivamus lacus quam, fermentum eget adipiscing et, malesuada eget urna.</p>
</div>
</body>
</html>

Pretty easy. #a floats around without an assigned witdh, because its content has width. #b does not encroach on #a's space due to overflow: hidden. This solution will not work in IE less than 7.


I would use some CSS to

.a {

float: left;

}

b will write around a.

Don't control for width at all, and it will automagically set itself to the right widths for the info you bring back from your db.

Control for height so that you can make sure that b doesnt sneak down below a.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜