Ways to conceal a particular text within a <li></li> tag with CSS techniques?

I am working on a rentals theme where the search engine lists cities. However, I want to add a prefix like "Detroit-cheap-rentals" for better SEO, even though the city name and slug must be the same.

Currently, the search engine displays "Detroit Cheap Rentals" when added in this format.

To enhance SEO, I would like to remove the "Cheap rentals" part using CSS while keeping the slug as detroit-cheap-rentals.

How can I achieve this using CSS?

In the image provided, I am looking to delete the "Kiralık Villa" part with CSS. Please check the picture here for reference

Answer №1

For hiding a place labeled "Kiralık Villa," use the code li[data-value="Kiralık Villa"]

If you want to hide the place using "save," apply visibility: hidden;. Otherwise, use display:none

Click here to understand the contrast 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 partially hide text in your comment:

Set width, 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>

Answer №2

Utilizing only pure CSS, achieving this effect may not be feasible. While CSS offers selectors like first-line and first-letter, it usually requires modifying the HTML structure to make it work. Here's an example of how you can do it:

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

You can then use the following CSS:

.hidden {
  display:none;
}

Alternatively, there are numerous other solutions available that have been previously suggested. Another approach could involve employing JavaScript. Here is a resource to get started:

Answer №3

To conceal a specific list item, you can assign it a class and then hide it using the display:none; property.

Here is an example of how this can be done in HTML:

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

This CSS snippet demonstrates how to style the hidden class:

.hidden {
    display: none;
}

Answer №4

Illustration of HTML:

<ul>New York <br>Luxury Apartments</ul>

Demonstration of CSS:

ul {
    width: 100%;
    margin-top: 10px;
}

Answer №5

It seems like you are looking to display only the content within the data-value attribute in the visible text for each <li> item?

One way to achieve this is by hiding the existing text and showing the content of the data-value attribute instead.

li{
visibility:hidden;
display:block;
max-width: 100px; /* Adjust based on dropdown box width */
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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Difficulty executing for loop due to multiple buttons, resulting in malfunctioning buttons in JavaScript code

Currently encountering an issue while trying to implement modal windows on my first website. Everything works fine without the for loop, but I wanted to have multiple buttons and windows, so I decided to use a for loop to handle each button. Strangely, the ...

Page returning causing tabs to refresh improperly

Today I want to discuss two different pages: VelocityMicro.com/Cruz.php and VelocityMicro.com/PC.php, which I am currently viewing in Firefox. The issue I am experiencing is with Cruz.php. When you click on a tab like "R100 Series" and then select an acce ...

A guide to smoothly transition box-shadow with jQuery's addClass() function

UPDATED I have a div with the class .shadow-circle-lg: <div class="shadow-circle-lg"></div> To add a different border styling to the div, I am using another class called .circle-highlight: .circle-highlight{ box-shadow: 0 0 0 1px rgba(0,0, ...

Poll # Warning: The variable "poll" has not been defined. Please check the code in H:xampphtdocsuserpollvote_form.php on

This is an HTML form for displaying a poll question. I am encountering errors with the variables 'poll' and 'question', as I am new to PHP. Can someone please assist me in resolving this issue? <html> <head></head&g ...

What is the best way to add an Apple iPhone-like effect to a menu list?

I've been working on creating a menu similar to the Apple menu using the greensock api Here is my progress so far: JSFIDDLE Update This is what I am aiming for: Fiddle Any idea why there is flickering when hovering over it? <div class="de ...

JavaScript label value vanishing after postback

When using a datepicker in JavaScript, I encountered an issue where the label resets to the default value after a postback to the server, instead of retaining the user's selected values. Despite my attempts to rearrange the code, the label consistent ...

Customize the color when clicking on a mat-slide-toggle

Whenever I click on the element, a shadow appears in the color that corresponds to the element, which is currently yellow https://i.sstatic.net/21BR4.png I would like to change that shadow to be green instead, but I am unsure of how to do so. Here is my ...

Caught in a dilemma between flex-end and space-between, with margin thrown into the mix

When working with a flexbox and using justify-content:space-between, the first and last items are aligned to the edges of the flex container, with space distributed between them. But how can I align the first item to the right while keeping all other items ...

Tips for displaying an image that is embedded within a CSS file

I discovered an interesting background image embedded in a CSS file. Is there a way for me to actually view it? "iVBOR..." to "5CYII=" and saved it in a file named image.png - unfortunately, this method did not yield the desired outcome.</p> ...

Enhance an existing HTML table

Currently, I am dealing with an HTML table retrieved from a web server in C# that needs to be displayed on my aspx webform. The challenge I am facing is how to dynamically add a prerequisite based on the course ID to the last column of the table. I want to ...

Update the appearance by utilizing ngModelChange

Is it possible to style an element using ngModelChange? I attempted the following method, but it was unsuccessful <input class="input" [(ngModel)]="counter" (ngModelChange)="$event > 2 ? [style.border-color]='#ff4d4d' : [style.border-color ...

How can PHP be used to showcase multiple results from a MySql query while handling errors?

I am looking for information on a specific category of items. In this case, I have 2 wines from Chile. The code below seems to be functioning correctly, but the foreach loop is causing the first output to overlap with the second one. As someone new to for ...

Can I programmatically retrieve a comprehensive list of all global HTML attributes available?

Exploring the extensive list of global HTML attributes can be overwhelming, especially when considering how it continues to evolve with browser updates. Can JavaScript be leveraged to dynamically generate a complete list of these attributes without the ne ...

JQuery causes Bootstrap carousel to malfunction after dynamically adding attribute to img tag

If you're thinking of sending me to this resource: Bootstrap Carousel not working after adding items dynamically with jQuery, know that the situation described there is different from mine. My issue involves fetching paths for 3 images from a JavaScr ...

Removing an object from a THREE.js scene while eliminating the Ray effect: Tips and tricks

function collisionDetection(bullet, b){ for(var i = collidableMeshList.length-1 ; i>=0; i--){ var collideMesh = collidableMeshList[i]; var v = collideMesh.geometry.vertices[0]; var c = collide ...

Footer mysteriously appears on top of the container

Trying my hand at practicing HTML by creating a small webpage, but struggling with why the Footer is aligning itself under the Header instead of the container I set up. It seems like a small detail that I might have missed, but I've hit a wall and ca ...

To access a form element in JavaScript function, utilize the dynamic form name approach

Currently, I am facing an issue with a JavaScript alert function where I am trying to view the HTML form URL before it is submitted. Following advice from a post on StackOverflow about retrieving form submit content before submit, I attempted to implement ...

Asynchronously updating a Django model instance in real-time

On my website, there is a button that allows users to view notifications as a drop-down without navigating away from the current page. I am interested in updating the unread field of every notification for a user from True to False when this button is clic ...

Jquery Post() Function Failing to Submit Data

The issue is with the post values not being passed to the action page correctly. The action page is only returning a static reply, which is just a "Thank you" message without including the $_POST part. Below are the code snippets provided for reference: ...

``Sorry, the link redirection feature is currently experiencing technical

First and foremost, take a look at this example View here Based on the example provided, I would like to create a similar page using the Telrik Text Editor, with a list of links and their corresponding paragraphs. Here is the HTML I am using in the Telr ...