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 looks like a label for the text. What I get instead is that the paragraphs inherit the width of the div father node which is wider.     #container {   width: 30%;   background-color: grey; }  #container p {   background-color: green; } &lt;div id="container"&gt;   &lt;p&gt;Sample Text 1&lt;/p&gt;   &lt;p&gt;Sample Text 2&lt;/p&gt;   &lt;p&gt;Sample Text 3&lt;/p&gt; &lt;/div&gt;
7820
I have a layout similar to:  &lt;div&gt;     &lt;table&gt;     &lt;/table&gt; &lt;/div&gt;   I would like for the div to only expand to as wide as my table becomes.
10108
There is nothing worse than coming across a website with paragraphs that span the width of your screen resolution. They are usually so hard to read, I don't even bother.  A lot of web designers use generic grid and column systems, but I don't feel these have been optimised for readability, they are more of design guide on general aesthetics.  I guess it comes down to words per line. Are the rules that apply to print media the same for screen media?  Are there any type of guidelines to help me size the width of paragraphs on the screen?  I want to take into consideration:   Major web font faces (i.e. Arial, Verdana, Georgia, Times) A range font sizes (i.e. 8px-24px) Space between columns
8914
I wish to be able to have a table (using tabular) that fills the page horizontally with each column using a fraction of that space, for now assume that they are equally sized.  I wish to be able to use enumerations inside of the tabular, so I am using parabox's to achieve this.  Currently I have got:  \begin{tabular}{ | p{0.25\linewidth} |                    p{0.25\linewidth} |                    p{0.25\linewidth} |                    p{0.25\linewidth} | }  %content here after   except this uses all the space from the first margain to the end of the page. Which looks awful. I really want to avoid hard coding in any dimensions because I will want to play around with margins and orientation later.   If I could get it so that I can use a proportion of the text width for each column that would be great.
19582
If I set a CSS value on a specific element using:  $('#element').css('background-color', '#ccc');   I want to be able to unset that element-specific value and use the cascaded value, along the lines of:  $('#element').css('background-color', null);   But that syntax doesn't seem to work – is this possible using another syntax?  Edit: The value isn't inherited from the parent element – the original values comes from an element-level selector. Sorry for any confusion!
31813
Although elements like &lt;div&gt;s normally grow to fit their contents, using the float property can cause a startling problem for CSS newbies: If floated elements have non-floated parent elements, the parent will collapse. For example:   &lt;div&gt;   &lt;div style="float: left;"&gt;Div 1&lt;/div&gt;   &lt;div style="float: left;"&gt;Div 2&lt;/div&gt; &lt;/div&gt;    The parent div in this example will not expand to contain its floated children - it will appear to have height: 0. How do you solve this problem? I would like to create an exhaustive list of solutions here. If you're aware of cross-browser compatibility issues, please point them out. Solution 1 Float the parent.   &lt;div style="float: left;"&gt;   &lt;div style="float: left;"&gt;Div 1&lt;/div&gt;   &lt;div style="float: left;"&gt;Div 2&lt;/div&gt; &lt;/div&gt;    Pros: Semantic code. Cons: You may not always want the parent floated. Even if you do, do you float the parents' parent, and so on? Must you float every ancestor element? Solution 2 Give the parent an explicit height.   &lt;div style="height: 300px;"&gt;   &lt;div style="float: left;"&gt;Div 1&lt;/div&gt;   &lt;div style="float: left;"&gt;Div 2&lt;/div&gt; &lt;/div&gt;    Pros: Semantic code. Cons: Not flexible - if the content changes or the browser is resized, the layout will break. Solution 3 Append a &quot;spacer&quot; element inside the parent element, like this:   &lt;div&gt;   &lt;div style="float: left;"&gt;Div 1&lt;/div&gt;   &lt;div style="float: left;"&gt;Div 2&lt;/div&gt;   &lt;div class="spacer" style="clear: both;"&gt;&lt;/div&gt; &lt;/div&gt;    Pros: Straightforward to code. Cons: Not semantic; the spacer div exists only as a layout hack. Solution 4 Set parent to overflow: auto.   &lt;div style="overflow: auto;"&gt;   &lt;div style="float: left;"&gt;Div 1&lt;/div&gt;   &lt;div style="float: left;"&gt;Div 2&lt;/div&gt; &lt;/div&gt;    Pros: Doesn't require extra div. Cons: Seems like a hack - that's not the overflow property's stated purpose. Comments? Other suggestions?
30295
#container {     width: 75%;     float: right; }   If I change the width to %100 it affects the entire site, i just want the homepage to be at 100% width and all other pages with sidebar 75%
15546
I've noticed this issue on a handful of other communities, but making the browser window narrow (mine is 1080x960) makes the .post-layout and #sidebar elements overlap. Maybe something to do with the grid CSS? The #mainbar element seems to be the correct width and changing the .post-layout's overflow-x to auto seems to "fix" it  From retrocomputing:    From this post, because we are meta after all:    Specs:   Google Chrome Version 78.0.3904.108 (Official Build) (64-bit) Ubuntu 18.04.3 LTS
77342
Is it possible to to change a &lt;span&gt; tag (or &lt;div&gt;) to preformat its contents like a &lt;pre&gt; tag would using only CSS?
14781
Say I have the following CSS and HTML code:    #header {   height: 150px; } &lt;div id="header"&gt;   &lt;h1&gt;Header title&lt;/h1&gt;   Header content (one or multiple lines) &lt;/div&gt;     The header section is fixed height, but the header content may change.  I would like the content of the header to be vertically aligned to the bottom of the header section, so the last line of text "sticks" to the bottom of the header section.  So if there is only one line of text, it would be like:   ----------------------------- | Header title | | | | header content (resulting in one line) -----------------------------   And if there were three lines:   ----------------------------- | Header title | | header content (which is so | much stuff that it perfectly | spans over three lines) -----------------------------   How can this be done in CSS?
14534
I created a horizontal menu using a HTML lists and CSS. Everything works as it should except when you hover over the links. You see, I created a bold hover state for the links, and now the menu links shift because of the bold size difference.  I encounter the same problem as . However, the post does not have proper solution. I've searched everywhere for a solution and can't find one. Surely I can't be the only one trying to do this.  Does anyone have any ideas?  P.S: I don't know the width of the text in menu items so I cannot just set the width of the li items.    .nav { margin: 0; padding: 0; } .nav li {      list-style: none;      display: inline;      border-left: #ffffff 1px solid;  } .nav li a:link, .nav li a:visited {      text-decoration: none;      color: #000;      margin-left: 8px;      margin-right: 5px;  } .nav li a:hover{      text-decoration: none;      font-weight: bold;  } .nav li.first { border: none; } &lt;ul class="nav"&gt;     &lt;li class="first"&gt;&lt;a href="#"&gt;item 0&lt;/a&gt;&lt;/li&gt;     &lt;li&gt;&lt;a href="#"&gt;item 1&lt;/a&gt;&lt;/li&gt;     &lt;li&gt;&lt;a href="#"&gt;item 2&lt;/a&gt;&lt;/li&gt;     &lt;li&gt;&lt;a href="#"&gt;item 3&lt;/a&gt;&lt;/li&gt;     &lt;li&gt;&lt;a href="#"&gt;item 4&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;
61850
I'm trying to horizontally center a &lt;div&gt; block element on a page and have it set to a minimum width. What is the simplest way to do this? I want the &lt;div&gt; element to be inline with rest of my page. I'll try to draw an example:  page text page text page text page text page text page text page text page text                -------                | div |                ------- page text page text page text page text page text page text page text page text
58280
I'm trying to center a fixed size control within a form.  Out of interest, is there a non-idiotic way of doing this? What I really want is something analogous to the text-align css property.  At the moment, I'm setting the padding property of the surrounding form to a suitable size and setting the Dock property of the control to fill.
51982
I need a CSS selector that can find the 2nd div of 2 that has the same class. I've looked at nth-child() but it's not what I want since I can't see a way to further clarify what class I want. These 2 divs will be siblings in the document if that helps.  My HTML looks something like this:  &lt;div class="foo"&gt;...&lt;/div&gt; &lt;div class="bar"&gt;...&lt;/div&gt; &lt;div class="baz"&gt;...&lt;/div&gt; &lt;div class="bar"&gt;...&lt;/div&gt;   And I want the 2nd div.bar (or the last div.bar would work too).
39831
The \multirow text is covered by the background color. Does someone know why and can fix it?    \begin{table}[h]     \caption{caption}      \label{tab}      \centering     \begin{tabular}{cccccc}         \toprule         &amp; &amp; A &amp; B &amp; C &amp; D \\         \midrule         \rowcolor{gray!10}             \multirow{2}{*}{Rosso}  &amp; Pruning &amp; - &amp; - &amp; 6-C-Pr &amp; - \\         \rowcolor{gray!10}                                 &amp; Stalks &amp; - &amp; - &amp; 6-C-S &amp; - \\             \multirow{2}{*}{Verde}  &amp; Pruning &amp; - &amp; - &amp; 6-M-Pr &amp; - \\                                 &amp; Stalks &amp; - &amp; - &amp; 6-M-S &amp; - \\         \rowcolor{gray!10}             \multirow{2}{*}{Blu}    &amp; Pruning &amp; 4-Pa-Pr &amp; 5-Pa-Pr &amp; 6-Pa-Pr &amp; 7-Pa-Pr \\         \rowcolor{gray!10}                                 &amp; Stalks &amp; 4-Pa-S &amp; 5-Pa-S &amp; 6-Pa-S &amp; 7-Pa-S \\             \multirow{2}{*}{Bianco}         &amp; Pruning &amp; - &amp; - &amp; 6-W-Pr &amp; - \\                                 &amp; Stalks &amp; - &amp; - &amp; 6-W-Pr &amp; - \\             \bottomrule         \end{tabular} \end {table}
105714
I want to create a custom listings environment and want to set its width as something like 90% of textwidth, centred.  Per an  for algorithms, the first thing I tried was to embed the listing in a minipage environment. However, . I found a way to still make standard environment work, but it requires to use the escape command every time before ending the environment.  The second thing I tried was this latter command, but as far as I can see, it doesn't offer a feature to set the width of the listing or centre it.  \documentclass{article} \usepackage{listings} \usepackage{lipsum}   \lstnewenvironment{queryl} %% APPROACH 1  {\lstset{frame=shadowbox,escapechar=`}}  {}  \newenvironment{query} %% APPROACH 2  {\begin{minipage}{4cm}\centering\begin{queryl}}  {\end{queryl}\end{minipage}}   \begin{document} %% APPROACH 1 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. \begin{queryl} begin { do nothing } end ; \end{queryl} Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.  %% APPROACH 2 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.  \begin{query} begin { do nothing } end ;`%&lt;- needs escape-to-LaTeX character to work \end{query}  Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. \end{document}     One can note that for the first environment, the frame extends beyond the width of the text. Also, puzzlingly the minipage environment doesn't seem to want to centre and swallows space (though I guess I could perhaps at least get that to work with tinkering).  In any case, does anyone have any ideas on how to set a width for a custom listings environment and centre it without requiring use of the escape character each time to end the environment?
24664
I'm looking for a way to change the CSS rules for pseudo-class selectors (such as :link, :hover, etc.) from JavaScript.  So an analogue of the CSS code: a:hover { color: red } in JS.  I couldn't find the answer anywhere else; if anyone knows that this is something browsers do not support, that would be a helpful result as well.
72669
I try to adapt this solution  to my needs.  But I have a width problem 1\tabcolsep is too short, but anything longer is too long, should be 2\tabcolsep.    \documentclass[10pt]{article} \usepackage[T1]{fontenc}  \usepackage{array} \usepackage{tabularx} \usepackage{ragged2e}  \newcolumntype{C}[1]{&gt;{\Centering}p{#1}} \usepackage{tikz}  \newcommand\Tdiag[4]{%     \multicolumn{1}{|p{#2}|}{\hskip-\tabcolsep     \begin{tikzpicture}[%                 baseline={(0,-.25\baselineskip)},                 every node/.style={outer sep=0pt,inner sep=#1}]     \node[minimum width={#2+1\tabcolsep-\pgflinewidth},         minimum height=2\baselineskip-\pgflinewidth+\extrarowheight,         use as bounding box] (box) {};     \draw[line cap=round] (box.north west) -- (box.south east);     \node[anchor=south west,text width=.75*#2,align=left] at (box.south west) {#3};     \node[anchor=north east,text width=.75*#2,align=right] at (box.north east) {#4}; \end{tikzpicture}\hskip-\tabcolsep}}  \begin{document}  \begin{tabular}{|C{1.2cm}*{3}{|c}|}\hline \Tdiag{.2em}{1.2cm}{\^Age}{Sexe}&amp; Féminin &amp; Masculin &amp; Totaux  \\\hline 15 ans&amp;&amp;1&amp;\\\hline 16 ans &amp; 16 &amp; &amp;  \\\hline 17 ans &amp; 3 &amp; &amp;  \\\hline Totaux &amp; &amp; &amp; 36  \\\hline \end{tabular}   \end{document}