Solved

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

Posted on 2016-09-12
2
34 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 21

Accepted Solution

by:
Kim Walker earned 500 total points
Comment Utility
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
Comment Utility
That solution was brilliant! You rock!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now