Multiple CSS content for markup with multiple classes - css

I am trying to add icons with CSS content value to different classes. Some markup might have multiple classes, in which case I want multiple icons after the text. Problem is, I am not sure if I can add multiple content values to the same class.
Example:
.entry-header::after {font-family: FontAwesome; font-size: 15px; /*float: right;*/}
.status-private > .entry-header::after {
content: " \f023"
}
.format-standard > .entry-header::after {
content: " \f040"
}
.format-video > .entry-header::after {
content: " \f03d"
}
In the case where a class is e.g. .status-private a logo will be displayed, but what if the markup has two classes? Such as .status-private .format-standard? How can I then display two icons?
If possible, I would avoid having to make CSS for every possible combination of these three classes.
My current markup:
<article id="post-1713" class="post-1713 post type-post status-private format-video hentry category-uncategorized post_format-post-format-video">
<header class="entry-header">
<div class="entry-date">
May 20, 2016
</div>
<div class="entry-title post-1713 post type-post status-private format-video hentry category-uncategorized post_format-post-format-video">
Private: Private: This is a video post
</div>
</header><!-- .entry-header -->
<div class="entry-content" data-did-load="true" style="display: none;">
<p>
The format of this post is video, but the video has not yet been added
</p>
</div><!-- .entry-content -->
</article>
I want to display the icons after Private: This is a video post

You cannot have multiple pseudo elements on the same element. Even if you could, as mentioned in original answer, just having ::after::after will not help you avoid duplication.
This is where I'd prefer practicality over purity. I'd just add an empty span for each status with each of the CSS classes, and target these in the CSS still with ::after etc.
Update 1: Example:
.entry-header > .icon::after {font-family: FontAwesome; font-size: 15px; /*float: right;*/}
.entry-header > .icon-status-private::after {
content: " \f023"
}
.entry-header > .icon-format-standard::after {
content: " \f040"
}
.entry-header > .icon-format-video::after {
content: " \f03d"
}
<!-- To show icons -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" />
<div class="status-private">
<div class="entry-header">
<span class="icon icon-status-private"></span>
Private
</div>
</div>
<div class="status-private">
<div class="entry-header">
<span class="icon icon-status-private"></span>
<span class="icon icon-format-standard"></span>
Private Article
</div>
</div>
<div class="status-private">
<div class="entry-header">
<span class="icon icon-status-private"></span>
<span class="icon icon-format-standard"></span>
<span class="icon icon-format-video"></span>
Private Video Article
</div>
</div>
Note: You can change the .icon in the first CSS line to [class=*'icon-'], and remove the redundant icon class from the spans.
If you are using some programming language (Serverside or JavaScript), you can use some programming checks to decide to write each span in the HTML.
Update 2: Avoiding HTML Changes
If you really have to keep the HTML as-is. You'll have to duplicate the selectors I'm afraid.
In your particular situation, it's not too bad actually. Here's the full example from your updated question HTML:
.entry-header::after {
font-family: FontAwesome;
font-size: 15px;
float: right;
}
.format-standard > .entry-header::after {
content: " \f040";
}
.status-private.format-standard > .entry-header::after {
/*Had to put 2 spaces to make the icons separate */
content: " \f023 \f040";
}
.format-video > .entry-header::after {
content: " \f03d";
}
.status-private.format-video > .entry-header::after {
/*Had to put 2 spaces to make the icons separate */
content: " \f023 \f03d";
}
/* Might not be needed now */
.status-private > .entry-header::after {
content: " \f023";
}
<!-- To show icons -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" />
<article id="post-1713" class="post-1713 post type-post status-private format-video hentry category-uncategorized post_format-post-format-video">
<header class="entry-header">
<div class="entry-date">
May 20, 2016
</div>
<div class="entry-title post-1713 post type-post status-private format-video hentry category-uncategorized post_format-post-format-video">
Private: Private: This is a video post
</div>
</header><!-- .entry-header -->
<div class="entry-content" data-did-load="true" style="display: none;">
<p>
The format of this post is video, but the video has not yet been added
</p>
</div><!-- .entry-content -->
</article>

Can Add multiple content like this too.
div::after{
font-family: FontAwesome;
}
.icon::after{
content: "\f03d";
font-size: 30px;
}
.icon.icon2::after{
content: "\f023 \f03d \f023";
font-size: 30px;
}
<head>
<link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
</head>
<div class="icon"></div>
<div class="icon icon2"></div>

Related

Hide an element based on the existance of other classes conditionally

I am getting HTML from an external source and can't change the code, so in order to get the result we need I need to conditionally hide things.
In this example, where I have a level-0 and level-1 I need to set display:none on the h2 (finance in this case).
<section class="level-0">
<h2 id="4001567002">Finance</h2>
<section class="child level-1">
<h2 id="4008036002">Fusion</h2>
<div class="opening" department_id="4001567002,4008036002" office_id="4000758002" data-office-4000758002="true" data-department-4001567002="true" data-department-4008036002="true">
<a data-mapped="true" target="_top" href="google.com">Business Systems Executive</a>
<br>
<span class="location">Sydney</span>
</div>
</section>
It could be that there is no level-1 in which case the level-0 header should be visible:
<section class="level-0">
<h2 id="4008036002">Fusion</h2>
<div class="opening" department_id="4001567002,4008036002" office_id="4000758002" data-office-4000758002="true" data-department-4001567002="true" data-department-4008036002="true">
<a data-mapped="true" target="_top" href="google.com">Business Systems Executive</a>
<br>
<span class="location">Sydney</span>
</div>
The ids are not predictable, so I cannot hide the levels based on that.
Is this possible in pure CSS or should I come up with another solution?
I was not able to do what you want with Pure CSS, and I don't think it is possible as you cannot add conditional statements within CSS.
Please find below a solution with a little bit of jquery:
var count = $(".level-0").length +1;
for (i = 1; i < count; i++) {
if ($(".level-1").parents('.container > .level-0:nth-of-type(' + i + ')').length == 1) {
$( '.level-0:nth-of-type(' + i + ')').addClass( "has-lv1" );
} else {
$( '.level-0:nth-of-type(' + i + ')').addClass( "no-lv1" );
}
}
.container {
border: solid 1px black;
padding: 20px;
background-color: lightblue;
}
.container > h2{
color: green;
}
.has-lv1 > h2 {
display: none;
}
.no-lv1 > h2 {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<h2>Example with <strong>Level 1</strong></h2>
<section class="level-0">
<h2 id="4001567002">Finance</h2>
<section class="child level-1">
<h2 id="4008036002">Fusion</h2>
<div class="opening" department_id="4001567002,4008036002" office_id="4000758002" data-office-4000758002="true" data-department-4001567002="true" data-department-4008036002="true">
<a data-mapped="true" target="_top" href="google.com">Business Systems Executive</a>
<br>
<span class="location">Sydney</span>
</div>
</section>
</section>
<hr>
<h2>Example without <strong>Level 1</strong></h2>
<section class="level-0">
<h2 id="4001567002">Finance</h2>
</section>
</div>
I hope this helps

Hover effect not working with w3-css

a:hover
{
text-decoration: none;
color: #F78888;
}
<link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet" />
<nav class="w3-sidebar w3-collapse w3-top w3-large" style="z-index:100;width:210px;font-weight:bold;" id="mynav">
<div class="w3-container" style="color: white;">
<h3 class="w3-padding-64"><b>No<br>Name</b></h3>
</div>
<div class="w3-bar-block w3-padding-8" style="color: white;">
Courses
Exercises
Rubric
Students
AnyName
Contact
Logout
</div>
</nav>
I am using w3-CSS for my web page. While I apply the hover effect for the 'a' elements it is applying. I can't overwrite the predefined hover effect of the w3-css. I want to change thee text color while hovering the mouse.
That stylesheet you're using is littered with !important declarations including this one at line 144:
.w3-button:hover{color:#000!important;background-color:#ccc!important}
If you want to use a custom color you're unfortunately going to have to declare it the same way using !important. I never advise this if I can help it but, that stylesheet is garbage, so I'm afraid you're not left many choices.
Below is a sample showing this. (I had to add a few other non-relevant styles to get the markup to display in the snipped because nav was display:none. You can ignore those.
/* For demo only */
body {
background-color: #ddd;
}
nav.w3-sidebar.w3-top {
display:block;
background-color: #ccc;
}
/* override !important declarations from W3 stylesheet */
a.w3-button:hover {
color:red !important;
background-color:#ccc !important
}
<link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet" />
<nav class="w3-sidebar w3-collapse w3-top w3-large" style="z-index:100;width:210px;font-weight:bold;" id="mynav">
<div class="w3-container" style="color: white;">
<h3 class="w3-padding-64"><b>No<br>Name</b></h3>
</div>
<div class="w3-bar-block w3-padding-8" style="color: white;">
Courses
Exercises
Rubric
Students
AnyName
Contact
Logout
</div>
</nav>
Make a new class in your stylesheet, e.g:
.myCustomHoverColor:hover {
color: #78cc45 !important;
}
and add it as a class to your <a> element.
so your <a> would look like this:
CoursesĀ“
This worked for me:
<head>
<link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet" />
<style>
.myCustomHoverColor:hover {
color: #78cc45 !important;
}
</style>
</head>
<body>
<nav class="w3-sidebar w3-collapse w3-top w3-large" style="background-color: gray; z-index:100;width:210px;font-weight:bold;" id="mynav">
<div class="w3-container" style="color: white;">
<h3 class="w3-padding-64"><b>No<br>Name</b></h3>
</div>
<div class="w3-bar-block w3-padding-8" style="color: white;">
Courses
Exercises
Rubric
Students
AnyName
Contact
Logout
</div>
</nav>
</body>
.w3-hover-white:hover{color:#000!important;background-color:#fff!important}
Courses
By removing the .w3-hover-white from the a element and gave my own userdefined style.
a:hover
{
text-decoration: none;
background-color: white;
color: #F78888;
}

wordpress bootstrap. No flowing to the right

So, after a few bootstrap tuts, decided to try mixing it up with wordpress. A whole bunch of questions there, but my main concern right now is, why isn't angies list image moving to the right? I did float:right in css, i did pull-right class, i even did margin-left:99%... it's still there. WHY?
Any other notes are appreciated as well :)
you can see the whole thing here
http://soloveich.com/
<body>
<div class="container-fluid>
<div class="row-fluid" id="heady">
<div class="span4"><div id="sign"></div></div>
<div class="span4" id="menubg">
<nav class="navbar">
<div class="navbar-inner">
<?php wp_nav_menu( array( 'theme_location' => 'main-menu' ) ); ?>
</div>
</nav>
</div>
<div class="span4" class="pull-right"><div id="angies"><img src="http://www.soloveich.com/wp-content/themes/Yellow-sign/images/angies.png"></div>
<div id="lic">
<ul id="licen">
<li>Phone# (555)555-5555</li>
<li>Lic# 7778899</li>
<li>Bond# 111223344</li>
</ul>
</div>
</div>
</div>
and the css
#heady {
background-color: #727272;
Height:370px;
}
#sign{
background-image: url(images/sign.png);
height: 334px;
width: 334px;
margin-left: 15px;
margin-top: 10px;
}
#menubg {
font-family: 'Contrail One', cursive;
font-weight: 200;
font-size: 25px;
text-decoration: none;
margin-top:130px;
}
#angies {
margin-top: 20px;
float: right;
margin-left: 99%;
}
If you want it to have your #angies to the very right of your page do the following:
#angies{
position:absolute;
margin-top:20px;
right:0px;
}
Long story short: you will force your element to break out of the flow in an absolute position at 0px from your right.
Also as I was browsing to the source of the page using developer tools in Chrome I realized that you are not embedding correctly the bootstrap javascript. See the last script tag before your ending </body> tag. You forgot to include the path to the template which is mandatory in Wordpress when you are including javascript files. That line of code should look like this:
<script src="<?php bloginfo('template_url');?>/js/bootstrap.min.js"></script>
instead of just this:
<script src="js/bootstrap.min.js"></script>

Behavior of floated object when related element is missing

<div class="pagination">
<?php if($page->hasPrevVisible()): ?>
<span class="prev">
<em>Previous Article</em>
<?php echo $page->prevVisible()->title() ?>
</span>
<?php endif ?>
<?php if($page->hasNextVisible()): ?>
<span class="next">
<em>Next Article</em>
<?php echo $page->nextVisible()->title() ?>
</span>
<?php endif ?>
</div>
This is what stands in my article view, basically. There's the main div, which won't matter for this case and two spans within. When there's no next our previous article, the option doesn't show up. Now to the CSS:
.pagination em {
font-family: Arvo;
font-size: .8em;
font-style: normal;
text-transform: uppercase;
display: block;
color: #838383;
}
.prev {
width: 49%;
display: inline-block;
}
.next {
width: 49%;
text-align: right;
float: right;
}
I've included the .pagination em because it is really important for me to keep that display:block there to drop a line. I can't make .next align with .prev without using float, it goes one line down. So maybe the issue is in the em, but I don't know for sure.
If there is a previous and a next article, it works like a charm. If there is only a previous article it also stands perfectly, however, if there's solely a next article, .next won't align properly.
For a practical example, please take a look at the bottom of this page.
Your problem is that your .pagination class is not clearing with only one floated div in it.
If you simply add overflow: auto; to the .pagination class in your CSS, it should fix the problem.
.pagination {
padding: 1.25em 0px;
font-size: 0.8em;
line-height: 1.2em;
border-bottom: 0.07143em solid rgb(55, 185, 81);
font-family: "Elena Web",Georgia;
overflow: auto;
}
Example: http://cssdesk.com/q2h4U
Hope this helps, and good luck!
float will float the element out of parent's "inner" dimension, which means its size will not be considered when calculating parent's size.
You can use display:inline-block on both sides, and use a dummy span when only one side is present:
http://jsfiddle.net/WR6cy/
<!-- when both sides present -->
<div class="pagination">
<span class="prev">
<em>Previous Article</em>
Previous Title
</span>
<span class="next">
<em>Next Article</em>
Next Title
</span>
</div>
<!-- when only prev side presents -->
<div class="pagination">
<span class="prev">
<em>Previous Article</em>
Previous Title
</span>
</div>
<!-- when only next side presents, use a dummy prev side to "push" the next -->
<div class="pagination">
<span class="prev">
</span>
<span class="next">
<em>Next Article</em>
Next Title
</span>
</div>
.prev {
width: 49%;
display: inline-block;
}
.next {
width: 49%;
text-align: right;
/* float: right;*/
display:inline-block;
}
Edit:
To achieve this with your current PHP, you can slightly modify it to:
<div class="pagination">
<span class="prev">
<?php if($page->hasPrevVisible()): ?>
<em>Previous Article</em>
<?php echo $page->prevVisible()->title() ?>
<?php endif ?>
</span>
<span class="next">
<?php if($page->hasNextVisible()): ?>
<em>Next Article</em>
<?php echo $page->nextVisible()->title() ?>
<?php endif ?>
</span>
</div>

Word Spacing Query

I have a word spacing issue which I cannot seem to resolve.
The web page is www.c5d.co.uk/captaintwo.php
The word spacing under the top images look ridiculous. Yet as far as I can see, the CSS is the same.
What am I missing ? If I put a /p tag after Wrigley it works fine but fails validation as there is no opening p tag
Relevant HTML and CSS is as follows:
.captain{word-spacing:185px;display:inline;}
.pres {display:inline; }
.ladycaptain{word-spacing:120px;display:inline; }
<img class="lewis" src="http://www.c5d.co.uk/captain.png" alt="The Captain">
<img class="socialtwo" src="http://www.c5d.co.uk/president.png" alt="President">
<p class="pres">
<br>Captain: John</p> <p class="captain">Lewis President:</p> Bill Wrigley
<img class="lewis" src="http://www.c5d.co.uk/ladycaptain.png" alt="Lady Captain">
<img class="socialtwo" src="http://www.c5d.co.uk/juniorcaptain.png" alt="Junior Captain">
<p class="pres">
<br>Lady Captain: Beryl</p> <p class="ladycaptain">Harrison Junior</p> Captain: Kieran Metcalf
Make the following changes:
.pres {
/* display: inline (remove) */
display: inline-block;
width: 270px;
text-align: center;
}
.captain {
/* display: inline (remove) */
display: inline-block;
width: 270px;
text-align: center;
}
<br> is outdated. Use the self-closing <br /> instead. The names should be wrapped in something (p, span, h3, something). There are 2 styles (one inline (inside the document) and one attached to #header) that are adding around 500px of space there. That's why there is a large gap.
Consider making it easier on yourself.. use 1 class to define each TYPE of object.
#people {
styles for container div
}
.box {
styles for the individual boxes
}
.photo {
styles for <img>
}
.title {
styles for names of people
}
Then just apply the classes to the appropriate item like so
<div id="people">
<div class="box">
<img src="path/image.jpg" class="photo" />
<h3 class="title">Position, name</h3>
</div>
<div class="box">
<img src="path/image.jpg" class="photo" />
<h3 class="title">Position, name</h3>
</div>
etc...
</div>

Resources