Linked Questions
119 questions linked to/from How can I make a div not larger than its contents?
158
votes
14
answers
448k
views
Width equal to content [duplicate]
I'm experiencing some trouble with the width property of CSS. I have some paragraphs inside a div. I'd like to make the width of the paragraphs equal to their content, so that their green background ...
11
votes
4
answers
30k
views
making a div "hug" its contained components [duplicate]
If I have HTML that looks like this:
<div class="figure">
<img src="some_image.png" />
<div><span class="caption">Fig. 1: Some caption</span></div>
</div>...
14
votes
1
answer
42k
views
How to create a div box with dynamic width based on text content? [duplicate]
I want to create a simple div that shrinks and expands according to the content contained.
https://jsfiddle.net/qa5dr0x8/
<body>
<div style="border: 1px solid red; padding: 15px; width:...
16
votes
3
answers
5k
views
CSS: Max-Width won't shrink? [duplicate]
Possible Duplicate:
Make CSS Div Width Equal To Contents
I am trying to make a chat like application but now I ran acros a little bug of some sort.
I have a div with a max-width set to 350px. But ...
5
votes
5
answers
1k
views
How to adjust div width with the siz of text inside it [duplicate]
My idea is to make each element within divs that have the .main_content class, to have a width equal to the width of the text inside it. How do I this?
As you can see, the width of each one (span, h2,...
2
votes
5
answers
3k
views
How do I make a h1 and h3 only as wide as the text [duplicate]
.main-heading {
display: block;
font-family: "Josefin-Sans", sans-serif;
font-size: 70.6px;
font-weight: bold;
text-align: center;
color: #ba9a45;
}
.subheading {
font-family: "Cardo", ...
0
votes
4
answers
6k
views
How to add border to a text only and align center [duplicate]
I am new to Html & CSS. I want a heading which contains text like "Women safty". I want to warp the heading text with border. But when I apply border to text the border covers all the ...
0
votes
7
answers
9k
views
Make border just around text, not the whole block [duplicate]
In the following snippet, the border outlines the block and not just around the text inside it:
.border {
font-size: 30px;
text-align: center;
border: red 2px solid;
}
<p class="border"&...
0
votes
2
answers
3k
views
CSS text-decoration underline, same width as text and underline [duplicate]
I have an <h1> with a text-decoration of underline, I was able to make it the same width as text via display: table-cell like so:
#login h1 {
color: #FFF;
border-bottom: 2px solid #...
0
votes
1
answer
2k
views
How to make element's width match text width with CSS [duplicate]
I have an element that takes 100% of its container's width:
How do I make it so the width of the element is as wide as the text?
I can't find the answer online because I don't know how to formulate ...
7
votes
1
answer
2k
views
Make div width same as its content width [duplicate]
I have attached a fiddle link to this question. I need the red dot to be closer to the text. For the first & last item, it works well..but if any item is multi line..it has extra whitespace at the ...
0
votes
4
answers
931
views
How to apply background colour property to only the area on which the text is located? [duplicate]
I have a div block inside which I have a paragraph whose background is black:
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-...
1
vote
2
answers
839
views
Use minimum possible width [duplicate]
I have a container that effectively, I want to compress the contents to their minimum width without scroll bars. fit-content is close, but allows the content to use more width than it actually needs. ...
-1
votes
3
answers
2k
views
How to set width of span tag to be the same as its content? [duplicate]
I NEED to use display: flex in order to style this icon and text that are within a span tag. As you can see the width is way too long, I just want the width to be just as long as the width of image ...
0
votes
3
answers
1k
views
Width of a container not automatically adjusting based on content inside [duplicate]
I have a div inside which I have content. I gave width = auto and then gave max-width but the container is taking up a constant fixed no matter what the size of the content is:
.adjustablebox {
...