No, margin auto will not change the size of the paragraph element. It simply attempts to automatically determine the appropriate margin size on the auto-sized sides of the element. Basically, if you want the paragraph to be smaller than the div that contains it you can set a static width of the paragraph(s) as a specific width or a percentage of the parent element's inner width. Another option if you do not want to do any static sizing of the paragraph(s) would be to set padding on the parent element or set static margins on the paragraph(s).
div.paragraph-container {
padding: 20px; /* or padding: 20px 20px 20px 20px; sets all the padding individually (top, right, bottom, left) */
}
This would make all the paragraphs center inside the div and be 40px smaller assuming the paragraphs don't have margins.
div.paragraph-container p {
margin: 10px 20px; /* sets the margin on the paragraph(s) to 10px on top and bottom and 20px on left and right which does the same as the first example assuming that the div does not have padding. */
}
If you want the border to be exactly the width of the text then:
div.paragraph-container p {
border-bottom: 1px dotted black;
padding: 0px 0px 5px 0px;
margin: 10px 20px;
}
div.paragraph-container {
padding: 0px;
}
Assuming the text fills the paragraph element then this will work. If you have 2 words in the paragraph then it won't be only as wide as the text. The only way to pull that off would be with an inline element like a span or an element that has been set to display: inline;
, but inline elements will get jumbled up side-by-side unless you put a block element between them.