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
Related
I have this design here:
You can see the material icon is a bit too close to the description. I thought I could create some padding between both by doing something like this:
.location-secondary-info span:first-child {
padding-right: 5px;
}
That has been ineffectual.
This is the component code:
renderLocation() {
const filteredLocations = this.props.locations.filter(location => {
return !location.name.match(/[A-Z0-9]+$/);
});
return filteredLocations.map(location => {
if (location.airport_code) {
return (
<div key={location.id}>
<div className="location">
<h1>
{location.name} ({location.airport_code})
</h1>
<div className="location-secondary-info">
<span>
<i className="material-icons">airplanemode_active</i>
{location.description}
</span>
</div>
</div>
</div>
);
} else {
return (
<div key={location.id}>
<div className="location">
<h1>{location.name}</h1>
<div className="location-secondary-info">
<span>
<i className="material-icons">location_city</i>
{location.description}
</span>
</div>
</div>
</div>
);
}
});
}
You should select the i element inside the span, so:
.location-secondary-info span i {
padding-right: 5px;
}
With span:first-child you were selecting the first span element inside .location-secondary.
I am trying to set the width of some data from a database, so that all data is the same lenght.
I am using (for a test), the following CSS:
style='width: 200px; border: 1px solid black;'
This is within a bold tag, again just for testing.
The result is not what I want.
The bottom text uses the following css:
.pwidth {
width: 200px;
border: 1px solid black;
}
I want the data after PID: to look like the demo ex show.
What am I missing?
<body>
<section>
<div class="jumbotron">
<h1 class="text-center">Index Of Records</h1>
<h2 class="text-center">Add New Record <a href='insert_record.php'>(x)</a><h2>
</div>
<div class="container">
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<div><strong>PID:</strong>";
echo "<b style='width: 200px; border: 1px solid black;'>". $row["pid"]. "</span></b>";
}
} else {
echo "No records to view.";
}
$con->close();
?>
<p class="pwidth">demo ex show<p>
</div><!-- container end -->
</section>
Try This One
<section>
<div class="jumbotron">
<h1 class="text-center">Index Of Records</h1>
<h2 class="text-center">Add New Record <a href='insert_record.php'>(x)</a>
<h2>
</div>
<div class="container">
<?php
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
echo "<div><strong>PID:</strong>";
echo "<p style='width: 200px; border: 1px solid black;'>" . $row["pid"] . "</span></p>";
}
} else {
echo "No records to view.";
}
$con->close();
?>
<p class="pwidth">demo ex show</p>
</div>
<!-- container end -->
</section>
What kind of an element is your "pwidth"? You may use an HTML-Block-Element to set a width.
So maybe <p>, <div> or something else.
a <b> tag is not block or inline-block element so it can't have width/padding/margin values.
You can add trigger those bold tags with Class in CSS and make them display: block;
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>
<article class="tweet-inner">
<div class="text-wrapper">
<div class="tweet">
<div class="text">
<p>Coming down! Time for Croation BBQ </p>
</div>
<p class="last">
<span class="pull-right">
<small> Hello this is first text </small>
<small> Hello this is second text </small>
</span>
</p>
</div>
</div>
</article>
I have the following repeating html structure.
As of now, I want to provide alternate rows with different background. The element which I want to color is class=text
I do the following in my css -
.tweet-inner .tweet .text-wrapper .text:nth-child(even) {
background-color: #FF0000;
}
This does not work, I also tried -
.text:nth-child(even) {
background-color: #FF0000;
}
This is what works -
article.text:nth-child(even) {
background-color: #FF0000;
}
But I want the .text to be alternately colored, not the entire article.
This also does not work.
The fiddle is http://jsfiddle.net/LKqvz/. Please let me know.
It should be:
article:nth-child(even) .text{
...
}
Because you have multiple article elements with a single .text DIV (your attempts select the nth .text child from article)
Try this
article:nth-child(even) .text {
background-color: red;
}
Js Fiddle
try this:
article:nth-child(even) .tweet .text {
background-color: #FF0000;
}
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>