Anyone know of a css hack to change the link text in here:
<div id = "foo"> Long Text for Regular site </div>
to this shorter version.
<div id = "foo"> Shorter Text </div>
I was able to add text before or after the link, using pseudoselectors but no luck modifying the link text itself.
I'm using a squarespace template, so I'm not able to use javascript to do this or generate better html.
You can accomplish something similar to what you're trying to do with with CSS3 text-overflow property:
HTML
<p>The quick brown fox jumped over the lazy dogs.</p>
CSS
P {
font-size:12pt;
line-height:12pt;
}
.truncate {
display:inline-block;
max-width: 100px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
line-height:11pt;
}
JSFiddle
http://jsfiddle.net/LcS7a/
Try:
#foo a{
text-indent: -9999px;
visibility: hidden;
word-spacing:-999px;
letter-spacing: -999px;
}
#foo a:after{
content: "New Text";
visibility: visible;
word-spacing:normal;
letter-spacing: normal;
}
Demo: http://jsfiddle.net/8DK9g/
** Edit **
Just read you can't alter the HTML that is being generated, leaving this here for anyone that may find it useful
** /Edit **
Using Duver Jaramillo's example, I've moved the shortened text onto the a tag using a data- attribute.
See http://jsfiddle.net/3n1gm4/KrwWL/
HTML
<div id = "foo">
Long Text for Regular site
</div>
And the CSS
#foo a{
text-indent: -9999px;
visibility: hidden;
word-spacing:-999px;
letter-spacing: -999px;
}
#foo a:after{
content: attr(data-short-text);
visibility: visible;
word-spacing:normal;
letter-spacing: normal;
}
Related
I have a CSS-only tooltip that uses a special element attribute to provide the content:
<li class="privTooltip" data-tooltip="My tooltip text">
Which is then handled in CSS:
<style>
[data-tooltip]:after {
content: attr(data-tooltip);
...styling...
}
</style>
But this only supports raw text. If I try to provide any HTML tags, like data-tooltip="<b>Granted through role paths</b>...more stuff", they aren't interpreted:
Text decoration, maybe a simple HTML table, etc.. would make these a lot nicer. I know I can write a DOM-based tooltip that does just about anything, but I'd like to know if it's possible with this lighter-weight pseudo-element CSS-only method.
This solution doesn't use your exact method, but it is CSS-only, which it sounds like is the important part for your use-case. You could try something like this, which allows you to style the tooltip's content with CSS.
EDIT: here's a live version of this in CodePen
HTML
<div class="tooltip">
<!-- put the content you want to hover over here -->
<img style="width: 40px; padding: 16px;" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Infobox_info_icon.svg/1200px-Infobox_info_icon.svg.png">
<span class="tooltiptext">
<!-- put the tooltip here -->
<strong>Title 1:</strong> Lorem ipsum.<br><br>
<strong>Title 2:</strong> Lorem ipsum.<br><br>
<strong>Title 3:</strong> Lorem ipsum.<br><br>
<strong>Title 4:</strong> Lorem ipsum.
</span>
</div>
CSS
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 200px;
background-color: #fff;
color: #000;
text-align: left;
border-radius: 4px;
border: 1px solid #d0d0d0;
padding: 8px;
/* Position the tooltip */
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
Let's say I have a p and I want to remove/hide the first two letters. Is there any way I can do that with only CSS (no JS)?
Example:
.remove-letters {
/* STYLES-HERE */
}
<p class="remove-letters">yrHello There!</p>
Actually, there is a way to do this in pure css! It uses the ch font-dependent unit.
.remove-letters {
font-family: monospace;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display:block;
text-indent: -2ch;
font-size: 2em;
}
<html>
<body>
<p class="remove-letters">yrHello There!</p>
</body>
</html>
Unfortunately this works only with monospace fonts and not in older browsers.
Without Javascript you cant achieve this very well. It would be a very hacky solution. With JS would be working like a charm.
let str = "yrHello There!"
console.log(str.substring(2))
I think I found a way to do it...
Example:
.remove-letters {
font-size: 0px;
}
.remove-letters:after {
font-size: 10px;
content: "Hello There!";
}
<p class="remove-letters">yrHello There!</p>
I am looking for a basic information icon like this:
After some more searching, I myself have found the entity. The code for it is â, and it looks like this: â
There's đ (U+1F6C8, CIRCLED INFORMATION SOURCE). As an HTML entity: đ.
There are plenty of tools, many online, that let you search for, and get more information about, Unicode characters. My personal favourite is this one.
this may help you ,
using html and css we can achieve this results
<!DOCTYPE html>
<html>
<style>
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
/* Position the tooltip */
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
</style>
<body style="text-align:center;">
<div class="tooltip">đ
<span class="tooltiptext">Tooltip text</span>
</div>
</body>
</html>
UNICODE U+02139
HEX CODE âš
HTML CODE âš
CSS CODE \2139
// css example
span {
content: "\2139";
}
HTML Example
<span>âš</span>
Source
These days I use emoji for "info" âšī¸ or "documentation" đ or "source" đ
Previously, I would put the â inside superscript â because it reflects that it is a footnote to the text.
<sup>â</sup>
Also, consider the â° symbol over the đ as it respects the baseline.
Use the unicode: â into the HTML.
HTML Code: âš
CSS Code: \2139
Use tailwind CSS (https://tailwindcss.com/) then the code below will create a nice info button.
<div class="flex items-center justify-center italic
text-stone-500 cursor-default w-5 h-5
rounded-full border border-gray-500 bg-green-100">
i
</div>
Is it possible to search for text using your browser's Ctrl+F function across three span tags if the middle tag is set to hidden? For example:
<span class="visibleText">Trying</span>
<span class="hiddenText">to search</span>
<span class="visibleText">text.</span>
If .hiddenText is set to display:none, the web browser will show "Trying text." If you search using Ctrl+F in a web browser, however, you will stop matching the string after "Trying ". You can highlight the whole phrase "Trying text" and press Ctrl+F, which will pop the phrase into your search box, but clicking the find-next-match button will yield no results.
Is there any way of making that whole phrase searchable? For an example, check out: http://jsfiddle.net/surrealmind/qo2ens33/.
This works
http://jsfiddle.net/qo2ens33/2/
HTML
<span class="visibleText">Trying</span>
<div class="hiddenText"><span>to search</span></div>
<span class="visibleText">text</span>
CSS
.hiddenText{
width:0px;
height:0px;
overflow:hidden;
display:inline-block;
}
This works too
http://jsfiddle.net/ctwheels/qo2ens33/5/
HTML
<span class="visibleText">Trying</span>
<span class="hiddenText">to search</span>
<span class="visibleText">text</span>
CSS
.hiddenText {
position:absolute;
opacity:0;
width:0px;
}
Not sure if this is what you're looking for
Ok, I think this is what you're looking for... You can't (as far as I know) search for two separate spans together, so what I've done is I've added the visible spans together
http://jsfiddle.net/ctwheels/qo2ens33/6/
Using this code:
JS
var numberOfElements = $(".visibleText").length;
for (var i = 1; i < numberOfElements; i++) {
$(".visibleText:eq(0)").append(" " + $(".visibleText:eq(1)").text());
$(".visibleText:eq(1)").remove();
}
With this you can find "Trying to search text." but not "Trying text.":
.hiddenText{
position: absolute;
top: -10000cm;
left: -10000cm;
}
Demo
This isn't exactly what you want but it does accomplish "hidden text". I think the positioning could be tweaked to fit your purpose.
.parent {
height: 2em;
width: 400px;
background: white;
position: relative;
}
.hiddenText {
width: 100%;
overflow: visible;
display: inline-block;
position: absolute;
color: transparent;
bottom: 0;
left: 0;
cursor: default;
}
.hiddenText::selection {
background: rgba(0,0,0,0);
}
http://jsfiddle.net/nbzv9thL/
I tried something with div tag as follows,
<style type="text/css">
#hello{
visibility: visible;
cursor: pointer;
position: absolute;
}
#list{
visibility: hidden;
cursor: pointer;
position: absolute;
top: 30px;
z-index: 1;
background-color: aqua;
}
#second{
position: absolute;
}
</style>
<div id="hello" onclick="{if(list.style.visibility=='hidden'){list.style.visibility='visible';}else{list.style.visibility='hidden'};}">Hello user</div><br/>
<div id="second">Welcome to smartdata</div>
<div id="list">
Home <br/>
SignOut <br/>
</div>
It is working fine but the problem is list is not displaying on the first click. Any thing wrong with my code.??
Your code doesn't work as you expect it to due to the way element.style works.
Check this MDN link on element.style: https://developer.mozilla.org/en/DOM/element.style
Since the style property has the same (and highest) priority in the
CSS cascade as an inline style declaration via the style attribute, it
is useful for setting style on one specific element.
However, it is not useful for learning about the element's style in
general, since it represents only the CSS declarations set in the
element's inline style attribute, not those that come from style
rules elsewhere, such as style rules in the section, or
external style sheets.
So when you first run your code and even if your element.style.hidden is declared in the external CSS sheet, the style declaration remains empty and you need to perform additional checks.
if (!list.style.visibility || list.style.visibility === 'hidden') {...}
You can take a look at the fiddle to see it work: http://jsfiddle.net/Kk6TJ/1/
Also:
It's best to use triple equal === to perform strict comparison without converting variable type.
You don't need curly braces in your event handlers. If you were hoping that they would create scope - they don't! Only functions in JavaScript have scope.
list.style.visibility=='hidden' is a false statement on first click
try this
{if(list.style.visibility=='hidden' || list.style.visibility='')
<style type="text/css">
#hello{
visibility: visible;
cursor: pointer;
position: absolute;
}
#list{
visibility: hidden;
cursor: pointer;
position: absolute;
top: 30px;
z-index: 1;
background-color: aqua;
}
#second{
position: absolute;
}
</style>
<div id="hello" onclick="{if(list.style.visibility=='hidden' || list.style.visibility==''){list.style.visibility='visible';}else{list.style.visibility='hidden'};}">Hello user</div><br/>
<div id="second">Welcome to smartdata</div>
<div id="list">
Home <br/>
SignOut <br/>
</div>â
This is because your if..else are not in order. Re-ordering of decision statement corrected the behavior, Now first click is showing the menu items.
Also, If you run your script and watch it in firebug console you'll see your javascript code is throwing warning on first click.
I've updated your code -
<style type="text/css">
#hello{
visibility: visible;
cursor: pointer;
position: absolute;
}
#list{
visibility: hidden;
cursor: pointer;
position: absolute;
top: 30px;
z-index: 1;
background-color: aqua;
}
#second{
position: absolute;
}
</style>
<script type="text/javascript">
function Clickme()
{
var list = document.getElementById('list');
if(list.style.visibility=='visible')
{
list.style.visibility='hidden';
}
else
{
list.style.visibility='visible'
}
}
</script>
<div id="hello" onclick="Clickme();">Hello user</div><br/>
<div id="second">Welcome to smartdata</div>
<div id="list">
Home <br/>
SignOut <br/>
</div>
Styles defined in style tags and css files are not in the element.style.property property, they are available if the element has its style set inline <element style="property:value;"> or explicitly element.style.property = value;
To get styles for an element defined in style tags/sheets use window.getComputedStyle(element, null).getPropertyValue(property);`
So you can either inline the styles on list, use getComputedStyle getPropertyValue or use the fact that list.style.visibility is going to be empty on the first click.
Go for something like this -
if(list.style.visibility=="visible")
{
list.style.visibility="hidden";
}
else
{
list.style.visibility="visible"
}