How to apply CSS to second word in a string?
Tags: css
Problem :
If I have the following string: John Smith, how could I use CSS to set font-weight: bold
on the second word in order to achieve: John Smith.
Can this be done in pure CSS?
Update: I am retrieving user's name from the server, so in my template it is #{user.profile.name}
.
Solution :
Since a js solution was suggested and pure CSS isn't presently possible: Live demo (click).
Sample markup:
<p class="bold-second-word">John Smith</p>
<p class="bold-second-word">This guy and stuff.</p>
JavaScript:
var toBold = document.getElementsByClassName('bold-second-word');
for (var i=0; i<toBold.length; ++i) {
boldSecondWord(toBold[i]);
}
function boldSecondWord(elem) {
elem.innerHTML = elem.textContent.replace(/\w+ (\w+)/, function(s, c) {
return s.replace(c, '<b>'+c+'</b>');
});
}
CSS Howto..
jQuery has functions toggleclass(), removeClass() and addClass(). These should help you along. Without seeing the whole HTML its a bit difficult to suggest a selector. If you assigned an id...
IMHO, it is not possible to do with pure CSS. The easiest solution will be using jQuery. // css .actioner{ -webkit-transform: translate(540px,0px); -moz-transform: translate(540px,0px); -o-transform: translate(540px,0px); -ms-transform: translate(540px,0px); } //...
You have to save this information in browser cookies. Whenever, a user accesses the site, check in the cookies if he prefers the darker version. To set the cookie use...
Wrap your widgets with a FlowPanel, so that the structure will look like: <g:ScrollPanel> <g:FlowPanel styleName="{style.canFitFourOnlyInaRow}"> // add your blue boxes here </g:FlowPanel> </g:ScrollPanel> and define a style named canFitFourOnlyInaRow...
The issue here is that since your submenus are nested within your main menu, any time your submenu is shown, the parent menu has to expand to make room for...
I created a quick and dirty "hack" for you on JSFiddle http://jsfiddle.net/uWUBE/ Hope it helps you out, you could edit it to be more dynamic. Here is some of the...
You can do like this by the following method, no matter how much data comes in the div. But the height will be equal for both divs. .box_container{display:table;width:100% } .img_box,...
You can use the user-select property (though pressing CTRL + A will still cause the blue selection background to appear as @WebDesignerRDj pointed out): img { -webkit-user-select: none; -moz-user-select: none;...
try use - ul li a img{ max-width:100%; } and for #head-section #head-section { width:100% } while you are putting 100% width to any selector then don't add padding/margin on...
Didn't think this would work myself, but it seems to: html, body { height: 100%; } .parent{ position:relative; background:red; width:200px; height:40px; } .child{ position:absolute; top:100%; left:30px; width:70px; height:70px; background:blue; }...
If you add this script it will work. $(document).ready(function(){ $(".works-feature").click(function(){ $("body").css("overflow","hidden"); }); $(".lightbox").click(function(){ $("body").css("overflow","auto"); }); }); ...
Try this CSS: for #container_background: #container_background{ background-image:url('main_bg.gif'); height: 430px; } for #content: #content{ background-color:transparent; } ...
@novicePrgrmr change container class like this .container { min-height: 100%;//min-height margin: 0 auto; padding: 0; position: relative; width: 960px; } ...
AFAIK that's not possible in CSS. You can either feed rules to multiple selectors: .one, .two, .three { color:red; } Or manually add a generic class to every HTML element....
If you want to set those styles just for p elements inside the main-column div, target them like this: .main-column p {} Also, make sure to use an actual heading...
In my own extension I only declared the html in the manifest, and the html is reading js and css files just fine. "browser_action" : { "default_icon" : "icon.png", "default_popup"...
It seems you cannot use :active alone here since Javascript is unable to trigger that state. Instead additonally create a class .active and put it on the element. .button.active:after {...
All you have to do is add line-height: 0; for those elements as well. Works great in webkit but small sliver left in FireFox due to the height of the...
try adding the "!important" statement to all your rules... as shown below: ::-webkit-input-placeholder { /* WebKit browsers */ color: #999 !important; } :-moz-placeholder { /* Mozilla Firefox 4 to 18...
Use the same CSS pseudo-classes with the gwt-Anchor class: .gwt-Anchor:link {color:#FF0000;} .gwt-Anchor:visited {color:#00FF00;} .gwt-Anchor:hover {color:#FF00FF;} .gwt-Anchor:active {color:#0000FF;} You can also use a.gwt-Anchor but it isn't strictly necessary....
You can add a new style tag cascade over the previous declaration. assuming the css in in the head tag $('head').append('<style>#element:hover {/ background-image: url("http://new.image/url");/ }/ <style>'); ...
You could use the q element instead of quotation marks, since browsers are supposed to add language-specific quotation marks, provided that the language is indicated in markup, e.g. with <html...
You won't be able to do this cross-browser. Some browsers allow a limited amount of customisation of select elements, but generally it's not worth the effort. If you really need...
Just remove the display:inline-block property for ul to center this : and for the items add text-align #navigation ul { list-style: none; padding: 0; width:400px; margin:auto; /*display: inline-block;*/ ---> Remove...
for young browser you may use the blend-mode: http://codepen.io/anon/pen/waGoEd html { background:url(http://lorempixel.com/300/300) rgba(0,0,0,0.5); } html:hover { background-blend-mode:darken; } Here a rgba() color is used, you can darken or colorish your...
you want to use the :active selector: .comment-box .btn:active { background-color: rgb(38, 173, 228); color: white; } Here is a refrence for other selectors: /* unvisited link */ a:link {...
HTML: <div id="header"> <h1>Alan Creedy</h1> <ul id="quickInfo"> <li class="mission">Mission Statement</li> <li>Helping People Think for Themselves</li> <li>1.919.926.0688</li> <li><a href="#contact">Email Me</a></li> </ul> <ul...
You can apply the rule only to ul like this: ul { list-style-image: none; list-style-type: none; } ...
You just need a helper to return the appropriate class: Template.YOURTEMPLATE.helpers({ headerClass: function () { var class = { 'ToDo': 'teal-header', 'Info': 'orange-header' }[this.type] return class || 'pink-header' } })...
Since you cannot use less or sass, what you can do is use a temp css class name and replace it using jQuery like following code, Html <div class="temp-class">aaaaaaaaaaaaaa</div> <div...