0

I'm working on a data platform that has widget specific to the platform I'm using a widget called map that displays a map and the title linked to the map in the database. the map includes a div title:

<map>
<div class="title">Title</div>
other divs ..
</map>

When I code i don't have access to the div title because it's included in the widget. I want to change the text of the title using css.

I looked at these examples: How can I replace text with CSS?

And did:

  1. First option

    .title{ visibility:hidden }

    .title:after{

    content:"NewTitle" ;
    visibility:visible;
    

    }

But then "Title" is just hidden but still takes space so my "NewTitle" is not centered

  1. Second option

    .title{ text-indent: -9999px; line-height:0; }

    .title:before{

    text-indent:0;
    content:'Welcome Back!';
    display:block;
    line-height: initial;
    

    }

But then my NewTitle is not well displayed.

How can I do to just switch "Title" to "New title" in CSS or eventually in Javascript.

Thank you for your help

Edit: the beginning of the displayed page

enter image description here

Flexibilités etc... is the title

I dont have access to what is written below ods-map in the html code as the ods-map is a widget. I can only change the css.

Community
  • 1
  • 1
morg
  • 1,173
  • 4
  • 18
  • 36

3 Answers3

1

JavaScript solution is the standard to do this:

$('.title').html("new title here"); // jquery
document.getElementsByClassName("title")[0].innerHTML = "new title here" // pure JS

fiddle:

https://jsfiddle.net/qpq45Luc/1/

messerbill
  • 5,499
  • 1
  • 27
  • 38
0

Although your question is not tagged with , your initial way of getting the text replaced was on the right track. You just need to explicitly set the display:block; on the pseudo-element. Then position the pseudo-element absolutely and with same padding on both the div and the pseudo-element to keep similar appearance.

Something like this:

div.title { 
    visibility: hidden; position: relative;
    padding: 4px; 
}

div.title::after {
    content: 'Replaced text';
    visibility: visible;
    display: block; position: absolute;
    padding: 4px; top: 0px;
}
<map>
    <div class="title">Title</div>
</map>

However, note that this is still a hack. Javascript is better way of doing this as, the text will be in your control.

Abhitalks
  • 27,721
  • 5
  • 58
  • 81
  • When i do that the text is not displayed but the space it used to take is still there so my new title is not at the right place. – morg Jul 31 '15 at 14:02
0

It's kind of hacky, but going off of your first attempt just add margin-left: -272px (depending on your title). https://jsfiddle.net/jmser6yd/2/

.title
{
  visibility: hidden;
}
.title:after
{  
  content: "New Title";
  visibility: visible;
  margin-left: -272px;
}

I still like a javascript / jQuery solution better, as @messerbill suggested

deebs
  • 1,390
  • 10
  • 23
  • When i do that the text is not displayed but the space it used to take is still there so my new title is not at the right place. – morg Jul 31 '15 at 14:02
  • With the full title,
    and subtitle (or whatever that is) try margin-left: -272px. This is a hack, but it sounds like you need to hack your way through those widgets.
    – deebs Jul 31 '15 at 14:20
  • Yes i pasted the answer because the same thing appears than with abhitalks suggestion! where should i put !important – morg Jul 31 '15 at 14:22
  • if needed, like this: "margin-left: -272px !important;". After I read what your title was, it sounds like the "!important" may not be necessary, but the different margin. – deebs Jul 31 '15 at 14:53