Hide a word within a class with just CSS - html

A WordPresss site, where I'm attempting to hide the word 'SKU' as seen below in the html code.
Here is the html
<div class="card-body card-body">
<h3>Phase 1 Phonics Planning Week 1 Example TEST FREE</h3>
<p><small><strong>SKU:</strong> </small></p>
<p>
</p></div>
I want to use a just CSS to hide the SKU word, my effort thus far, but I'm unable to see how to target just SKU, I presume I need to use the element some how?:
CSS
.card .card-body {
display: none;
}

Unless im misunderstanding your question, you can just use:
.card-body p small strong {display:none}
If this isn't what you require please elaborate.

There are a couple of ways. One is to use
.card-body small {
display: none;
}
But, it would probably be better to create a new class just for hidden things, like this
.hide-sku {
display: none;
}
and in the html
<span class='hide-sku'>SKU:</span>
(also, you have the class card-body duplicated -- not sure if that's your intention)

If you can control classes in your html code - the easiest way is to add some helper class:
.hidden {
display: none;
}
<div class="card-body">
<h3>
Phase 1 Phonics Planning Week 1 Example TEST FREE
</h3>
<p class="hidden">
<small>
<strong>SKU:</strong>
</small>
</p>
<p>Some other content</p>
</div>
If you can't control classes and change html code - you can use :nth-of-type or :nth-child pseudoclasses:
.card-body p:nth-of-type(1) {
display: none;
}
<div class="card-body">
<h3>
Phase 1 Phonics Planning Week 1 Example TEST FREE
</h3>
<p>
<small>
<strong>SKU:</strong>
</small>
</p>
<p>Some other content</p>
</div>

Related

Using SASS / BEM / Grandparent / parent / child / selector / :hover

I'm having a challenge and i'm hours away from handing in a project and totally frustrated.
In the past i've done a simple paragraph collapse, by splitting the paragraph into 2 pieces and inserting a toggle in between.
<p id="paragraph1">some text goes here </p>
<p id="toggleMe">more...</p>
<p id="paragraph2">more hidden text shows up here</p>
in the css:
#paraphgraph2{
display: none;
#togglMe:hover #paragraph2{
display: block;
}
but apparently i'm doing something wrong, because its not affecting the browser.
This is what you have:
#paraphgraph2{
display: none;
#togglMe:hover #paragraph2{
display: block;
}
<p id="paragraph1">some text goes here </p>
<p id="toggleMe">more...</p>
<p id="paragraph2">more hidden text shows up here</p>
Try the following instead:
#paragraph2{ /* Wrong id selector */
display: none;
}/* Add closing bracket */
#toggleMe:hover #paragraph2{ /* Wrong id selector */
display: block;
}
<p id="paragraph1">some text goes here </p>
<div id="toggleMe">
more...
<p id="paragraph2">more hidden text shows up here</p>
</div>
#toggleMe:hover #paragraph2{ Suggest #paragraph2 to be inside #toggleMe.

Text not wrapping, instead opts to go under

My Problem
So I am trying to create a news section for my website. Each section contains a title, an image, and the article itself. The problem is that the article text will refuse to go beside the image unless I use <br> to break it up myself.
Description
All the elements of each section is listed under a single div element. The section includes the title, image, and article. After that, the picture has its own class and the article also to CSS after.
The Title is a block element
The Picture is an inline-block element
The Article is an inline-block element
HTML CODE (STARTING FROM NEWS BOX NOT INCLUDING NAV BAR AND ABOVE)
<div id=newsboard>
<div class=newsboard_topic>
<h1>Website in Development!</h1>
<img src="/image/newsboard/construction.gif" alt="Dev">
<p class=newsboard_topic_article>
Greetings!
<br>The GeoVillage website is currently under construction, but feel free to register and login to check out the stuff we have so far!
<br>- Geo Jones
<br>Owner and Developer
</p>
</div>
<div class=newsboard_topic>
<h1>kimmy and donald!</h1>
<img class=newsboard_topic_picture src="/image/newsboard/kimdon.jpg" alt="kimmyanddonald">
<p class=newsboard_topic_article>
The fan fiction of Donald Trump and Kim Jong Un! Yes, they photoshopepd it. This is a test by the way to test the standing of articles.
</p>
</div>
</div>
CSS CODE FOR SECTION OF HTML
#newsboard {
margin-left: 100px;
margin-right: 100px;
margin-top: 25px;
margin-bottom: 25px;
border-color: #0099FF;
border-style: solid;
border-width: 5px;
}
.newsboard_topic {
padding: 20px;
display: block;
}
.newsboard_topic_article {
display: inline-block;
vertical-align: top;
word-wrap: break-word;
margin: 0px;
padding: 10px;
}
.newsboard_topic_picture {
display: inline-block;
}
LIVE EXAMPLE
is currently up at geo-village.com
Make the picture a floating element inside the text container, then the text will float next to it (and below it, if it's longer)
Separate your newsboard_topic class.
<div class=newsboard_topic>
<img src="/image/newsboard/construction.gif" alt="Dev">
<h1>Website in Development!</h1>
</div>
<p class=newsboard_topic_article>
Greetings!
<br>The GeoVillage website is currently under construction, but feel free to register and login to check out the stuff we have so far!
<br>- Geo Jones
<br>Owner and Developer
</p>
Then give your newsboard_topic class a display:flex;.
.newsboard_topic {
padding: 20px;
display: flex;
}
I think the obvious answer no one wanted to give, which would make a lot of your coding more smooth is... Bootstraps. If you are learning to code, I highly recommend learning from some of the great opensource solutions available.
<div class="row">
<div class="col-md-5">
<h1>Website in Development!</h1>
<img src="/image/newsboard/construction.gif" alt="Dev">
</div>
<div class="col-md-5">
<p class=newsboard_topic_article>
Greetings!
<br>The GeoVillage website is currently under construction, but feel free to register and login to check out the stuff we have so far!
<br>- Geo Jones
<br>Owner and Developer
</p>
</div>
</div>

css select element when sibling appears

Hello i have structure:
<section class="entry">
<div class="1">
<div class="IappearSometimes">text1</div>
<p class="ImAlwaysShowingText">text2</p>
</div>
</section>
I would like to hide by display:none p class .ImAlwaysShowingText element, only when div class .IappearSometimes appears.
By default class .ImAlwaysShowingText is always on screen and i want to hide it when class .IappearSometimes shows on.
I was trying by nth-child, ~ selector, but after 2 days of trying its hiding other elemtns on page, im really lost..
Can I select it somehow?
You can do it through jQuery
if ($('.IappearSometimes.').is(':visible')) {
$('.ImAlwaysShowingText').hide();
}
This will cause when element IAppearSometimes is visible on screen to hide ImAlwaysShowingText
This should work
.IappearSometimes ~ .ImAlwaysShowingText {
display: none;
}
<section class="entry">
<div class="1">
<div class="IappearSometimes">text1</div>
<p class="ImAlwaysShowingText">text2</p>
</div>
</section>
Edit: You can see here DEMO if .IappearSometimes exists .ImAlwaysShowingText will have display: none
I think this is enough (combined selector):
.IappearSometimes.ImAlwaysShowingText {
display: none;
}
EDIT: Sorry, no space in between the classes.
Here's a codepen (with another line added): http://codepen.io/anon/pen/pgybdL

Using CSS to change a class background but only if it is not after a h4

I am trying to change the background colour of PARAGRAPH 4 only. I want to leave Paragraph 2 alone (because it is after a H4). I have tried the not selector but can't seem to get the logic working right. Not wanting to use JavaScript, PHP or jQuery. Only pure CSS please.
.widget-wrap > .widget-title {
background-color: yellow;
}
.widget-title + .textwidget {
background-color: red;
}
<div class="widget-wrap">
<h4 class="widget-title">Paragraph 1 in the div.</h4>
<p class="textwidget">Paragraph 2 in the div.</p>
<p>Paragraph 3 in the div.</p>
</div>
<div class="widget-wrap">
<p class="textwidget">PARAGRAPH 4 INSIDE 2ND DIV.</p>
<p>PARAGRAPH 5 INSIDE 2ND DIV.</p>
</div>
If the first child of .widget-wrap will only either be an h4.widget-title, or a p.textwidget (i.e. when the h4 is not present), simply use :first-child:
.widget-wrap > .widget-title {
background-color: yellow;
}
.widget-wrap > .textwidget:first-child {
background-color: red;
}
<div class="widget-wrap">
<h4 class="widget-title">Paragraph 1 in the div.</h4>
<p class="textwidget">Paragraph 2 in the div.</p>
<p>Paragraph 3 in the div.</p>
</div>
<div class="widget-wrap">
<p class="textwidget">PARAGRAPH 4 INSIDE 2ND DIV.</p>
<p>PARAGRAPH 5 INSIDE 2ND DIV.</p>
</div>
If there any other elements may appear before the first p.textwidget absent an h4.widget-title, that will complicate things slightly. You would use :not() with a sibling selector in that case, but if there can be a variable number of elements, you won't be able to do this reliably.
check this out
.widget-wrap:nth-child(2) .textwidget {
background-color: green;
color: white;
}
Why you being not using different class name or id for the paragraph 4. that will be more simple and crystal clear. I would rather suggest you to use.
In current code as class names are same for parent div and P hence the color is changing for all not only for h4. sl please kindly use these.
Html
<div class="widget-wrap">
<p class="textwidget redcolor">PARAGRAPH 4 INSIDE 2ND DIV.</p>
<p>PARAGRAPH 5 INSIDE 2ND DIV.</p>
</div>
CSS:
.widget-wrap .redcolor {
background-color: Red !important; /*use important if not works*/
}
so now all elements having class redcolor inside class widget wrap will be having background color red. you can use id or any other class name.
that will be more easier and best approach for than using the any other javascript etc.
It will add more css lines but that will not cause any harm to it.

Scalable CSS naming and sub classing

If you have a div which has various elements inside it, what would be a good way to show relationships and hierarchy when it comes to writing the CSS rules for this HTML:
<div class="tweet-general-item">
<p>Some summary text in here</p>
</div>
I'm wondering how to write and apply a style for the <p> element. This could be done in two ways:
.tweet-general-item-summary {
...
font-size: 12px;
}
With HTML like this <p class="tweet-general-item-summary">Some summary text here</p>
OR
.tweet-general-item .summary {
...
font-size: 12px;
}
With HTML like this <p class="tweet-general-item summary">Some summary text here</p>
Which way would be better/scalable/good-practice and why? I have to be able to show some level of hierarchy/relationship in the CSS. I can't simply have a style of .summary by itself because it has no semantic meaning to anyone - the designers/devs need to know what kind of summary it is just from reading the CSS.
Have a look at the BEM Methodology:
http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/
https://bem.info/method/
Your example would look like:
<div class="tweet">
<p class="tweet__summary"></p>
</div>