I would like to apply bold formatting to figure 1, figure2, ...until figure 111.
I can only change the HTML and CSS and need to do this without using JavaScript or jQuery. Is there any way besides adding <strong> in HTML?
There is ::first letter in CSS, but no ::first word. Can I use ~like %figure in CSS?
<p>Figure 3 All incidences of ...</p>
<div id="imgcontainer" style="height: auto;">
<p><img src="Images/misc/newsletters/msIssue7_monoAnti4_850x550.png" style="margin-bottom: 10px;" /></p>
<p>Figure 4 ...</p>
</div>
<div id="imgcontainer" style="height: auto;">
<p><img src="Images/misc/newsletters/msIssue7_monoAnti5_350x370.png" style="float: left; width: 450px; margin: 8px 20px 8px 0px;" /></p>
<p>Figure 5 Sequence information obtained from MS/MS analysis of capillary electrophoresis ...</p>
</div>
<p><img src="Images/misc/newsletters/msIssue7_monoAnti6_850x350.png" style="width: 850px; height: 200px; margin: 8px 8px 8px 0px;" /></p>
<p>Figure 6 Separation of ...</p>
Given that you have the ability to change the markup and CSS of your page and that you don't want to add extra elements (like <strong> etc), you could try to make use of CSS counters. Counters have very good browser support.
Using Counters, you can auto number the figures, add the text "Figure X" before the content and also style it without doing any additional changes to your markup. The big advantage of this is that you don't have to manually number them and don't even have to worry about any future changes to the order. CSS would automatically take care of it. You can also add any extra styling that you need.
Below is a sample snippet:
body {
counter-reset: figure; /* Initializes the counter to 0 */
}
p {
counter-increment: figure; /* Increment the counter everytime p tag is encountered in DOM */
}
p:before {
content: "Figure " counter(figure)" "; /* Set Figure + Counter value as content */
font-weight: bold;
color: red;
}
<p>Lorem Ipsum...</p> <!-- Counter = 1, Before Content = Figure 1 -->
<p>Lorem Ipsum...</p> <!-- Counter = 2, Before Content = Figure 2 -->
<p>Lorem Ipsum...</p> <!-- Counter = 3, Before Content = Figure 3 -->
<p>Lorem Ipsum...</p> <!-- Counter = 4, Before Content = Figure 4 -->
<p>Lorem Ipsum...</p> <!-- Counter = 5, Before Content = Figure 5 -->
If you don't want to number all <p> tags and want to number only specific <p> tags then you can give them an unique class like in the below snippet. (Note: Even though you add an extra class, the bold text is restricted to just the "Figure X" text and doesn't apply to the entire content of that <p>).
body {
counter-reset: figure;
}
p.count {
counter-increment: figure;
}
p.count:before {
content: "Figure " counter(figure)" ";
font-weight: bold;
color: red;
}
<p class='count'>Lorem Ipsum...</p>
<p>Lorem Ipsum...</p>
<p class='count'>Lorem Ipsum...</p>
<p class='count'>Lorem Ipsum...</p>
<p>Lorem Ipsum...</p>
If like the snippet provided in your question, the "Figure x" text is applicable only for the second paragraph within the div class='imgcontainer', you can still do this without adding any extra class like in the following snippet:
body {
counter-reset: figure;
}
.imgcontainer > p + p {
counter-increment: figure;
}
.imgcontainer > p + p:before {
content: "Figure " counter(figure);
padding-right: 1ch; /* More padding-right means more space between Figure x and text */
font-weight: bold;
color: red;
}
<div class='imgcontainer'>
<p>
<img src='http://placehold.it/100/100'>
</p>
<p>Some Description</p>
</div>
<div class='imgcontainer'>
<p>
<img src='http://placehold.it/100/100'>
</p>
<p>Some Description</p>
</div>
<div class='imgcontainer'>
<p>
<img src='http://placehold.it/100/100'>
</p>
<p>Some Description</p>
</div>
<div class='imgcontainer'>
<p>
<img src='http://placehold.it/100/100'>
</p>
<p>Some Description</p>
</div>
Note: 1ch means width of the "0" character in the element's font. The ch unit has lower browser support and I have used it only for example. You can use px or em or any such unit instead of ch.
though you want to change the figure1 and so on to be bold using css, as you know css only deals with decoration, while javascript deals with user action, now this can only be achived by javascript to first find out the figure word, and then adding css class to it, css has no build in Attribute to find out automaticaly and change the decoration of html inner element
you can put desired property in a class and then add the elements to that class.
Also you are using id="imgcontainer".
id's are unique in css (should be at least) when you want to give same properties to more than one element use classes instead of id's
Try putting all the figures in a div with class abc.
Now put these bold property in the that class.
here is the property for bold you need to add in your div.
font-weight: bold;
Related
So I am currently trying to edit the "line-height" of my Wordpress paragraphs. The problem is that I have multiple p tags on my page, and I'm only interested in changing the paragraphs that are located inside a div named "entry-content", which is actually the article of the page.
Here is the basic code of the php page I have:
<div class="entry-content">
<p style="text-align: center;">Paragraph 1</p>
<p style="text-align: center;">Paragraph 2</p>
<p>Paragraph 3</p>
</div>
So my question is if there's a way to do something like that in css (so it only affects the paragraphs that are inside the div entry-content:
.entry-content {
p, li {
line-height: 30px;
}
}
Thanks for your help
Your CSS selector needs to be:
div.entry-content p {
line-height: 30px;
}
This will style all <p> elements that are descendants of a <div> element with the class name "entry-content".
I'm having a challenge and i'm hours away from handing in a project and totally frustrated.
In the past i've done a simple paragraph collapse, by splitting the paragraph into 2 pieces and inserting a toggle in between.
<p id="paragraph1">some text goes here </p>
<p id="toggleMe">more...</p>
<p id="paragraph2">more hidden text shows up here</p>
in the css:
#paraphgraph2{
display: none;
#togglMe:hover #paragraph2{
display: block;
}
but apparently i'm doing something wrong, because its not affecting the browser.
This is what you have:
#paraphgraph2{
display: none;
#togglMe:hover #paragraph2{
display: block;
}
<p id="paragraph1">some text goes here </p>
<p id="toggleMe">more...</p>
<p id="paragraph2">more hidden text shows up here</p>
Try the following instead:
#paragraph2{ /* Wrong id selector */
display: none;
}/* Add closing bracket */
#toggleMe:hover #paragraph2{ /* Wrong id selector */
display: block;
}
<p id="paragraph1">some text goes here </p>
<div id="toggleMe">
more...
<p id="paragraph2">more hidden text shows up here</p>
</div>
#toggleMe:hover #paragraph2{ Suggest #paragraph2 to be inside #toggleMe.
I am trying to change the background colour of PARAGRAPH 4 only. I want to leave Paragraph 2 alone (because it is after a H4). I have tried the not selector but can't seem to get the logic working right. Not wanting to use JavaScript, PHP or jQuery. Only pure CSS please.
.widget-wrap > .widget-title {
background-color: yellow;
}
.widget-title + .textwidget {
background-color: red;
}
<div class="widget-wrap">
<h4 class="widget-title">Paragraph 1 in the div.</h4>
<p class="textwidget">Paragraph 2 in the div.</p>
<p>Paragraph 3 in the div.</p>
</div>
<div class="widget-wrap">
<p class="textwidget">PARAGRAPH 4 INSIDE 2ND DIV.</p>
<p>PARAGRAPH 5 INSIDE 2ND DIV.</p>
</div>
If the first child of .widget-wrap will only either be an h4.widget-title, or a p.textwidget (i.e. when the h4 is not present), simply use :first-child:
.widget-wrap > .widget-title {
background-color: yellow;
}
.widget-wrap > .textwidget:first-child {
background-color: red;
}
<div class="widget-wrap">
<h4 class="widget-title">Paragraph 1 in the div.</h4>
<p class="textwidget">Paragraph 2 in the div.</p>
<p>Paragraph 3 in the div.</p>
</div>
<div class="widget-wrap">
<p class="textwidget">PARAGRAPH 4 INSIDE 2ND DIV.</p>
<p>PARAGRAPH 5 INSIDE 2ND DIV.</p>
</div>
If there any other elements may appear before the first p.textwidget absent an h4.widget-title, that will complicate things slightly. You would use :not() with a sibling selector in that case, but if there can be a variable number of elements, you won't be able to do this reliably.
check this out
.widget-wrap:nth-child(2) .textwidget {
background-color: green;
color: white;
}
Why you being not using different class name or id for the paragraph 4. that will be more simple and crystal clear. I would rather suggest you to use.
In current code as class names are same for parent div and P hence the color is changing for all not only for h4. sl please kindly use these.
Html
<div class="widget-wrap">
<p class="textwidget redcolor">PARAGRAPH 4 INSIDE 2ND DIV.</p>
<p>PARAGRAPH 5 INSIDE 2ND DIV.</p>
</div>
CSS:
.widget-wrap .redcolor {
background-color: Red !important; /*use important if not works*/
}
so now all elements having class redcolor inside class widget wrap will be having background color red. you can use id or any other class name.
that will be more easier and best approach for than using the any other javascript etc.
It will add more css lines but that will not cause any harm to it.
Say that my base stylesheet defines that when I have something like:
<h2>My heading</h2>
...
<h3>My other heading</h3>
the first heading will use font-size: 1.5em and the other one 1.3 em. What I'm trying to achieve is that when those heading have classes like this:
<h2 class="larger">My heading</h2>
...
<h3 class="larger">My other heading</h3>
both headings should be 20% larger than what they would have been without the classes. Is it possible to somehow achieve this using a single CSS rule, i.e.:
.larger {
/* what to put in here? */
}
or will I need to create rules for h1.larger, h2.larger, h3.larger etc. separately and duplicate the styling rules?
I dont believe this can be done in a single rule, at the simplest level, you could surely use:
h2.larger{
font-size:1.8em;
}
h3.larger{
font-size:1.56em;
}
Where the font size is 1.2x the original in both cases- although this is hard coded.
It doesn't work that way…
But you could add a children to each h and it will make what you want:
(explanation at the bottom)
HTML:
<h2>My heading</h2>
<h3>My other heading</h3>
<br>
<br>
<h2 class="larger">My heading</h2>
<h3 class="larger">My other heading</h3>
<br>
<br>
<h2><span class="larger">My heading</span></h2>
<h3><span class="larger">My other heading</span></h3>
CSS:
h2 {
font-size: 1.5em;
}
h3 {
font-size: 1.3em;
}
.larger {
font-size: 130%;
}
Case 1: the size is applied as normal to the h's
Case 2: the size is applied to both h's disregarding their font-size initial definition.
Case 3: adding a child (in this case a span) will obbey the font-size of the parent as intended
Fiddle here: http://jsfiddle.net/z3ztr/
I'm wrapping text around an image using markup something like this:
CSS:
#imgAuthor {
float:left;
margin: 0 15px 15px 0;
}
HTML:
<h2>Author Information</h2>
<p>
<img id="imgAuthor" src="..." alt="..." />
<b>Bob Smith</b>
</p>
<p>
Here is some bio information about the author...
</p>
This actually looks okay except that, if the text is shorter than the height of the image, my page footer is also wrapped around the image.
I want my footer to appear below the image. If I add <p style="clear:both"> </p> to clear the float, then I have too much space above my footer.
How can I clear the float and force any subsequent markup below my image without adding any more whitespace?
Add overflow: hidden to the CSS for the paragraph that contains the floating image. That will make the paragraph grow to fully contain the floated image. For example:
<h2>Author Information</h2>
<p class="inner">
<img id="imgAuthor" src="http://placekitten.com/200/200">
<b>Bob Smith</b>
</p>
<p>
Here is some bio information about the author...
</p>
And:
#imgAuthor {
float:left;
margin: 0 15px 15px 0;
}
p.inner {
overflow: hidden;
}
And a live version: http://jsfiddle.net/ambiguous/S2yZG/
Alternatively, you could stick a <div style="clear: both;"></div> right at the bottom of the paragraph but you should only use this in cases where you need the overflow to be something other than hidden. For example:
<h2>Author Information</h2>
<p>
<img id="imgAuthor" src="http://placekitten.com/250/200">
<b>Bob Smith</b>
<div class="cBoth"></div>
</p>
<p>
Here is some bio information about the author...
</p>
And:
#imgAuthor {
float:left;
margin: 0 15px 15px 0;
}
.cBoth {
clear: both;
height: 1px;
}
And a live version of this approach: http://jsfiddle.net/ambiguous/3yGxA/
Why does overflow:hidden work? From the CSS3 specification:
The border box of a table, a block-level replaced element, or an element in the normal flow that is a flow root (such as an element with ‘overflow’ other than ‘visible’) must not overlap any floats in the same flow as the element itself. If necessary, implementations should clear the said element by placing it below any preceding floats [...]
Your <p style="overflow: hidden;"> satisfies the third condition so its bounding box is extended below the bottom of the floating image so that there is no overlap.
You were on the right path to try <p style="clear:both"> </p> but all you need to do is change the height and margins.
<div style="clear:both; height:1px; margin:0;"></div>
alternatively you can just add clear: both to the footer style and forget this markup.