Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2016-09-12
2
Medium Priority
?
70 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

610 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