?
Solved

resizing a div with css so the width resizes with the content

Posted on 2016-09-12
2
Medium Priority
?
76 Views
Last Modified: 2016-09-13
Hi Experts,

I have these two examples

Example 1
https://jsfiddle.net/qfkhx9n1/

Example 1 looks like this:

example 1

Example 2
https://jsfiddle.net/ewyxnj4c/

Example 2 looks like this:

example 2
They are the same example except that in example 2 the content in the div with this id id="sub-left" and this id id="sub-right" is longer.

Is it possible to revise Example 2 so that the divs  id="sub-left" and id="sub-right" stay centered as they are now but if the inside the divs content is longer, the content just stays on the same line but the widths of the divs grows with the content.
So instead of wrapping to another line like example 2 is currently doing, the content will be on the same line?

Anyone know the syntax to do that?
0
Comment
Question by:maqskywalker
2 Comments
 
LVL 22

Accepted Solution

by:
Kim Walker earned 2000 total points
ID: 41795466
You will have to add another wrapper for each of your subtitles which are 50% width and floated left and right. Then you would float the actual subtitle divs the opposite direction within them and make those subtitle divs auto width.
<div id="wrapper">
	<div id="header">
		<span class="MainTitle">Welcome To the Sanitarium Everyone</span>
	</div>
	<div id="sub-main">
		<div id="sub-left-wrapper">
			<div id="sub-left">
				<span class="SubTitle">This is a much longer subtitle 1</span>
			</div>
		</div>
		<div id="sub-right-wrapper">
			<div id="sub-right">
				<span class="SubTitle">This is a much longer subtitle 2</span>
			</div>
		</div>
	</div>
</div>

Open in new window

#header {
	text-align: center;
}

#wrapper {
	border: 1px solid #ab29d8;
	margin: 0 auto;
	width: 100%;
}

#sub-main {
	border: 1px solid #08aa15;
	margin: 0 auto;
	width: 100%;
	overflow: hidden;
}

#sub-left-wrapper {
	width: 50%;
	float: left;
}

#sub-left {
	border: 1px solid #ff0000;
	text-align: center;
	float: right;
	width: auto;
}

#sub-right-wrapper {
	width: 50%;
	float: right;
}

#sub-right {
	border: 1px solid #0000ff;
	text-align: center;
	float: left;
	width: auto;
}

.MainTitle {
	color: #000000;
	font-family: Arial;
	font-weight: bold;
	font-size: 32px;
	text-align: center;
}

.SubTitle {
	color: #000000;
	font-family: Arial;
	font-size: 18px;
	font-weight: bold;
	text-align: center;
}

Open in new window

0
 
LVL 1

Author Closing Comment

by:maqskywalker
ID: 41796672
That solution was brilliant! You rock!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
Suggested Courses
Course of the Month17 days, 5 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question