0

Is it possible to hide the string Last Name inside a th by using CSS?

It is important that table's background color, font size etc will not be affected.

<html lang="en">

<head>
  <title></title>
  <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.css" rel="stylesheet" />
  <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
  <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</head>

<body>
  <br>
  <table>
    <tr>
      <th>#</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Username</th>
    </tr>
    <tr>
      <td>1</td>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
  </table>
</body>

</html>

2
  • 2
    possible duplicate of Hide text using css Commented May 22, 2015 at 10:05
  • why dont you just give the tag an id then change the attributes via the css using this ID ? i.e : visibility: hidden; Commented May 22, 2015 at 10:32

8 Answers 8

2
<style> 
 .hideMe {display:none;} 
</style>

add this class on "th" and "td" like

<th class="hideMe">Last Name</th>
<td class="hideMe">Otto</td>

Hope this will help you.

Sign up to request clarification or add additional context in comments.

Comments

2

You can realize that by giving the element an ID or a class and adding styles like

display: none;

for this ID/ this class in your css file.

1 Comment

This would cause the offending <th> element to disappear punching a hole in the layout given the current DOM. It would also make the column narrower, so he'd need to put the text into another child inside the th which would allow the bg colour of the th to show through.
0

You can try this:

.hidden-text {
  text-indent: -9999px;
}

3 Comments

The OP can definitely try but are you certain that this will help? Sure, we are not here to spoon-feed but answers without an explanation raise quite a few flags.
Yeah, I should have mentioned at least that the class needs to be added to the th (although it seems pretty obvious to me).
@Simone Better tell OP the same in your answer as that will help the others as well when they get a similar problem
0

You can hide by using CSS pseudo selector.

th:nth-child(3) { 
  display: none;
}

Comments

0

Using nth element you can do it.

th:nth-child(3) {
    display:none;
}
<html lang="en">

<head>
  <title></title>
  <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.css" rel="stylesheet" />
  <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
  <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</head>




<body>
  <br>
  <table>
    <tr>
      <th>#</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Username</th>
    </tr>
    <tr>
      <td>1</td>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
  </table>
</body>

</html>

Refer this link.

Comments

0

You could make the text the same colour as the background although this would still mean the text was there and selectable, it would preserve all other aspects of the layout. Or you could put the text in a span and make that visibility hidden.

1 Comment

if he does it the first way he could just set pointer-events:none; to the text when its the same colour ...
0

Also you can use visibility property.

th:nth-child(3) {
    visibility:hidden;
}

Comments

0

You can change the color of your text if don't want to affect table (use rgba properties).

.lastName{
   color:rgba(0,0,0,0); /*Set opacity to 0*/
 }

If you use display property, you will hide all <th></th> (and not just the text).

Good luck,

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.