2

I have a theme about rentals. The search engine is listing the cities, but when im adding a city, the name and the slug must be same. But for a better SEO, I need to add a prefix like "Detroit-cheap-rentals"

So I must write the city name and the city slug same. In this situation the search engine is looking like "Detroit Cheap Rentals"

I want to get rid of the "Cheap rentals" part with the css so the slug can still be detroit-cheap-rentals.

How can I do this with css?

In this picture, the part I want to delete with css is "Kiralık Villa" check the picture here please

özgür kuş
  • 93
  • 1
  • 9
  • So you want to hide with data-value="something" ? – Shahil M Aug 16 '18 at 12:34
  • @לבני מלכה has put up the answer – Shahil M Aug 16 '18 at 12:36
  • data value comes from the city's name, I can not slice it to parts and hide with visibility:hidden. if I write the city name from wordpress admin panel as "detroit cheap rentals" its having the same slug but only the one li element. – özgür kuş Aug 16 '18 at 12:38

5 Answers5

6

use li[data-value="Kiralık Villa"]

if you want to hide with "save" the place use visibility: hidden; if not use display:none

Learn here the difference between visibility:hidden and display:none:

li[data-value="Kiralık Villa"]{
    visibility: hidden;
}
<ul>
<li data-value="Kiralık Villa">Kiralık Villa</li>
<li data-value="other">other</li>
</ul>

To your comment hide part of text:

Set width and white-space: nowrap; overflow: hidden;

   li[data-value="Kiralık Villa"]{
    width: 83px;
    white-space: nowrap;
    overflow: hidden;
    }
<ul>
 <li data-value="Kiralık Villa">Kiralık Villa and more text</li>
 <li data-value="other">other</li>
</ul>
לבני מלכה
  • 15,925
  • 2
  • 23
  • 47
  • data value comes from the city's name, I can not slice it to parts and hide with visibility:hidden. if I write the city name from wordpress admin panel as "detroit cheap rentals" its having the same slug but only the one li element – özgür kuş Aug 16 '18 at 12:40
  • 1
    you mean you want to hide only part of text? – לבני מלכה Aug 16 '18 at 12:42
  • thats right. I know its hard. maybe js can help that but Im not familiar with the js:( – özgür kuş Aug 16 '18 at 12:44
  • that works well my friend thank you. But the menu elements are also having the css code and breaking. Im putting the css code with onyl li{ width: 83px; white-space: nowrap; overflow: hidden; } this one is not working. li[data-value="Kiralık Villa"]{ width: 83px; white-space: nowrap; overflow: hidden; } – özgür kuş Aug 16 '18 at 12:59
  • 1
    use `!important` to defention that you want them not override by other – לבני מלכה Aug 16 '18 at 13:01
  • 1
    Learn here:https://stackoverflow.com/questions/9245353/what-does-important-in-css-mean – לבני מלכה Aug 16 '18 at 13:01
  • thank you so much my friend but I just couldnt handled it.... can you see my web site villatut.com and try the changes in developer mode then advise me please? I just couldnt make it happen. – özgür kuş Aug 16 '18 at 13:06
  • 1
    I can not see any long text(you are from Turkey? I have been there last week :) ) – לבני מלכה Aug 16 '18 at 13:09
  • oh sorry I flushed the cache now. please check again. Yes, we are a rental company, we may have a barbeque next time you come here :) there you will see only Fethiye Villa Kiralama for now, I will do the rest if I can manage this one. – özgür kuş Aug 16 '18 at 13:12
  • 1
    I flight many time to Turkey... honesty I am turkish but live in other place – לבני מלכה Aug 16 '18 at 13:14
  • Anybody ever said that you are a beautiful person? thank you so much man! – özgür kuş Aug 16 '18 at 13:26
  • @לבנימלכה You should change your answer to include the content of the fiddle that was the actual working answer. As it stands now, your current answer is not correct, only the fiddle in your comment. – awe Aug 17 '18 at 03:59
  • @awe the answer and fiddle contain the same.... I just post fiddle to explain to OP because he does not get it – לבני מלכה Aug 19 '18 at 05:14
1

I don't think this is possible with pure css, css has first-line, and first-letter selectors, but it is not possible unless you are able to modify the html.. so you can add

<li>Detroit <span class="hidden">Cheap Rentals</span></li>

css

.hidden {
  display:none;
}

Or the many other solutions that were already presented.. Another idea would be using js, here a good start.. http://www.dynamicsitesolutions.com/javascript/first-word-selector/?path2=/javascript/first-word-selector/

Renzo Calla
  • 7,486
  • 2
  • 22
  • 37
0

You can add a class to the li tag and hide it with display:none;

Example HTML:

<ul>
    <li>Number 1</li>
    <li class="hidden">Number 2</li>
    <li>Number 3</li>
</ul>

Example CSS:

.hidden {
    display:none;
}
Filip Vuskovic
  • 126
  • 1
  • 15
0

As I understand, you want to show only the content of the data-value in the visible text on each <li> item?

You could do it like this, which will hide the existing text, and show the content of the data-value instead.

li{
visibility:hidden;
display:block;
max-width: 100px; /* this should be the available width you have in the dropdown box */
overflow-x:hidden;
}
li:before{
visibility:visible;
display:inline-block;
content:attr(data-value);
}
<ul>
<li data-value="Detroit">Detroit something</li>
<li data-value="Fethiye">Fethiye Kiralık Villa</li>
</ul>
awe
  • 21,938
  • 6
  • 78
  • 91
  • In my menu, it writes "Fethiye Kiralık Villa" but I want the "Kiralık Villa" part not to shown – özgür kuş Aug 16 '18 at 13:05
  • OK, but in [your image](https://i.hizliresim.com/Q28vNZ.png) of the site with debugger tools open, the items with the text "Fethiye Kiralık Villa" had data-value="Fethiye". Based on that, this solution would work. – awe Aug 17 '18 at 04:21
0

Example of HTML:

<li>Detroit <br>Cheap Rentals</li>

Example of CSS:

li {
    height: 20px;
    overflow: hidden;
}