Reputation: 1338
How to display the following code in line with a heading and one list per column?
I tried it with the following code and with a style-attribute display:inline-block;
at the header tag but none of them worked for me.
Thanks for your help.
<!doctype html>
<html lang="en">
<body style="display: inline-block">
<div>
<h2>Members</h2>
<ul>
<li>person_1</li>
<li>person_2</li>
<li>person_3</li>
</ul>
</div>
<div>
<h2>1st shift</h2>
<ul>
<li>person_1</li>
<li>person_2</li>
<li>person_3</li>
<li>person_4</li>
</ul>
</div>
<br style="clear:both">
</body>
</html>
Upvotes: 3
Views: 280
Reputation: 3429
try this one:
.text{
float: left;
padding: 10px;
}
.text ul{
margin: 0;
padding-left: 20px;
}
Upvotes: -1
Reputation: 5169
Or floats would suffice for such a task. Although it would be wise to add a div
wrapping them both to which you can apply a clear. The clear is necessary due to the fact using floats with remove the elements from the document flow. A clear will negate this problem and restore page flow.
Please find a rough dirty example below (minus the clear).
.list{
float: left;
padding: 10px;
border: 1px solid red;
margin: 0 20px 0 0;
}
.list ul{
margin: 0;
padding-left: 20px;
}
<!doctype html>
<html lang="en">
<body style="display: inline-block">
<div class="list">
<h2>Members</h2>
<ul>
<li>person_1</li>
<li>person_2</li>
<li>person_3</li>
</ul>
</div>
<div class="list">
<h2>1st shift</h2>
<ul>
<li>person_1</li>
<li>person_2</li>
<li>person_3</li>
<li>person_4</li>
</ul>
</div>
<br style="clear:both">
</body>
</html>
Upvotes: 3
Reputation: 37701
Your divs actually need to be displayed using inline-block (and width of at most 50% of the container, so they both can fit), see here:
div {width: 40%; display: inline-block; vertical-align: top}
<!doctype html>
<html lang="en">
<body>
<div>
<h2>Members</h2>
<ul>
<li>person_1</li>
<li>person_2</li>
<li>person_3</li>
</ul>
</div>
<div>
<h2>1st shift</h2>
<ul>
<li>person_1</li>
<li>person_2</li>
<li>person_3</li>
<li>person_4</li>
</ul>
</div>
<br style="clear:both">
</body>
</html>
Upvotes: 2