Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome not showing :after pseudo selector

Really bugging me, but why isn't Chrome showing the :after pseudo selector?? I haven't noticed this before. It's quite simple CSS too. It shows in all other browsers as well!

Firefox

Firefox

Chrome

Chrome

I did notice on the Bootstrap site though, their forms are showing the :after selector in the DOM. Weird...

Bootstrap form

Please look at this code snippet that I made. It's doing it here too if you inspect the DOM in your browser. -

.form-horizontal .form-group {
  margin-bottom: 10px;
}
.form-horizontal .form-group:before {
  display: table;
  content: " ";
}
.form-horizontal .form-group:after {
  clear: both;
}
<div class="form-horizontal">
  <div class="form-group">
    <label>First Name *</label>
    <input id="txtCustodianFName" type="text" class="form-control" placeholder="First Name" />
  </div>

  <div class="form-group">
    <label>Last Name *</label>
    <input id="txtCustodianLName" type="text" class="form-control" placeholder="Last Name">
  </div>
</div>
like image 748
jaminroe Avatar asked Aug 18 '15 17:08

jaminroe


People also ask

How do I inspect pseudo elements in Chrome?

Pseudo classes on elements can be triggered to investigate how an element may react if it were to be hovered over for example. You can right click on a node in the Elements panel and select Force element state. Alternatively, the Toggle element state icon can be clicked on in the Styles sub-pane.

What is :: before in inspect?

::before. ::before is a generated content element that represents a styleable abstract first child of the respective element. The content inserted using ::before is inserted before other content inside the element and is displayed inline by default. The value of the content is specified using the content property.

What is pseudo-element selector?

A CSS pseudo-element is a keyword added to a selector that lets you style a specific part of the selected element(s). For example, ::first-line can be used to change the font of the first line of a paragraph. /* The first line of every <p> element.


1 Answers

The content property is required for :before and :after pseudo selectors. If it is not included, it will have no effect on the element. If you are using the selectors to preform a clearfix, or some other case where you don't actually want any content, you can simply leave the content property blank with content:''; Like you have already done for the :before selector. Your CSS should look like this:

.form-horizontal .form-group:after {
  content: '';
  clear: both;
}

Learning To Use The :before And :after Pseudo-Elements In CSS

JSFiddle

like image 141
APAD1 Avatar answered Sep 27 '22 20:09

APAD1