CSS classes overlapping in an unintended way - css

What I'm trying to achieve is that when hovering over the td, that the background changes to black and the text color to white, but I only get the black background. I believe this happens because there is an interference with the "blueColor" and "redColor" classes with the "hover:hover" class.
td {
text-align: center;
}
table {
width: 100%;
font-size: 35px;
font-family: Arial;
font-weight: bold;
}
.blackBorder {
border: 1px solid black;
}
p.redColor {
color: red;
}
p.blueColor {
color: blue;
}
.lightGreenBackground {
background-color: #b5f79e;
}
.hover:hover {
background-color: black;
color: white;
}
<table>
<tr>
<td class="lightGreenBackground blackBorder hover">
<p class="redColor">1</p>
<p class="blueColor">H</p>
</td>
</tr>
</table>
I have tried using the !important property without any success and I'm not allowed to use id's.

Because you already have a color defined on p and not td.hover means you will have to change the color of <p> when td.hover is in a hovered state.
You'll notice if you remove both colors from your CSS, the text will turn white as expected on hover.
You can target both p's and change the color using .hover:hover > p.
td {
text-align: center;
}
table {
width: 100%;
font-size: 35px;
font-family: Arial;
font-weight: bold;
}
.blackBorder {
border: 1px solid black;
}
p.redColor {
color: red;
}
p.blueColor {
color: blue;
}
.lightGreenBackground {
background-color: #b5f79e;
}
.hover:hover {
background-color: black;
}
.hover:hover > p {
color: #fff;
}
<table>
<tr>
<td class="lightGreenBackground blackBorder hover">
<p class="redColor">1</p>
<p class="blueColor">H</p>
</td>
</tr>
</table>

Related

Adding a colour class to an element in scss based on existence of element

I have an article block that looks like this:
The SCSS for this box is here:
/* Styling for all articles on index page */
#news-grid {
.article {
margin: 0px;
text-align: left;
border: none;
.article-featured-image-box {
position: relative;
.featured-image {
max-width: 100%;
height: auto;
display: block;
position: relative;
width: 100%;
object-fit: cover;
}
}
.article-meta-information {
color: #cacacd;
font-size: 15px;
font-family: $balto-font;
font-weight: 300;
border-bottom: 1px solid #f0f0f0;
padding-bottom: 5px;
}
.article-content {
padding: 30px 30px 30px 30px;
background-color: #ffffff;
}
.article-title {
font-family: $circular-font;
color: $newable-navy;
font-size: 24px;
font-weight: 500;
margin-top: 10px;
margin-bottom: 10px;
word-wrap: break-word;
a {
color: $newable-navy;
}
}
.article-body {
line-height: 24px;
font-family: $balto-font;
font-size: 18px;
font-weight: 300;
p {
line-height: 24px;
font-family: $balto-font;
color: $newable-dark-grey;
font-size: 18px;
font-weight: 300;
word-wrap: break-word;
a {
color: $newable-blue;
}
}
a {
color: $newable-blue;
}
.article-excerpt p {
line-height: 24px;
font-family: CircularStd;
color: $newable-navy;
font-size: 21px;
font-weight: 500;
word-wrap: break-word;
}
}
.article-footer {
padding-top: 15px;
border-top: 1px solid $newable-grey;
padding-bottom: 30px;
}
.interactions-panel {
width: auto;
float: right;
}
.sticker {
background-color: #fff;
background-color: rgba(255, 255, 255, 0.92);
text-transform: uppercase;
font-size: 12px;
line-height: 18px;
color: #282C35;
-webkit-box-sizing: border-box;
box-sizing: border-box;
position: absolute;
display: inline-block;
top: 0px;
right: 0px;
height: 45px;
width: 45px;
}
}
}
What I'm looking to do is add a class that dictates colour, for instance, if an image is not provided I want the news article to have a dark theme.
This class .dark will change the background colour, text colour and title colour.
The articles are generated using a foreach loop
#foreach($articles as $article)
<div class="grid-item element-item {{ str_slug($article->category) }}">
<div class="article">
<div class="article-featured-image-box">
#if($article->featuredVideo != NULL)
{!! $article->featuredVideo !!}
#else
<img class="featured-image" style="width: 100%; height:auto;" src="{{ $article->featuredImage }}" alt="{{ $article->title }}">
#endif
#if($article->featuredArticle)
<div class="sticker yellow">
<span class="icon icon-news"></span>
</div>
#endif
</div>
<div class="article">
<div class="article-content">
<div class="article-meta-information">
{{ $article->created_at->format('d F Y') }} | {{ $article->author }}
</div>
<div class="article-title">
{{ $article->title }}
</div>
<div class="article-body">
<p>{{ $article->excerpt }}</p>
</div>
</div>
</div>
</div>
</div>
#endforeach
At the top of the foreach I can check if there is a featured image and redefine <div class="article"> to <div class="article dark">
Is there a way in SaSS that I can say if the class is .article .dark change the colours of the inner elements, or would I have to have a separate bunch of styling?
Also, would you just hide the featured image box or redefine the whole block?
I'd essentially like to be able to have many themes for the article block in which I can append a class to control the colouring.
This is probably really simple but I've hit a wall
You could add a aggregate class to the .article class using &:
#news-grid {
.article {
// Your current styles and nested classes...
// When .article.dark
&.dark {
// Your custom overrides
.article-title {
color: white;
}
}
}
}
I built a working compilation example here. Note that i added some variables at the top just to make the code work.
Hope it helps.
This seems like a good use for Sass maps.
You could create your two themes (light and dark) as maps, then use them in a mixin, switching themes by passing an argument to the mixin. For example:
// All styles for .article go here
#mixin article($theme) {
background-color: map-get($theme, main-bg);
.article-title {
color: map-get($theme, title-col);
}
}
// Colours stored as Sass maps
$theme--light: (
main-bg: gainsboro,
title-col: dimgrey
);
$theme--dark: (
main-bg: darkslategrey,
title-col: whitesmoke
);
// Finally, here we call the mixin, passing name of the correct map
.article {
#include article($theme--light);
}
.article.dark {
#include article($theme--dark);
}
This compiles to:
.article {
background-color: gainsboro;
}
.article .article-title {
color: dimgrey;
}
.article.dark {
background-color: darkslategrey;
}
.article.dark .article-title {
color: whitesmoke;
}

CSS not working on table

The style settings i'm making for my table in my CSS file do not work in the html that i made
CSS:
body {
background-color: #ccffff;
}
h1 {
font-family: verdana;
}
h2 {
font-family: verdana;
}
h3 {
font-family: verdana;
}
h4 {
color: red;
font-family: verdana;
border: 3px solid black;
padding: 15px;
margin: 10px;
}
table {
width: 100%;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
p {
font-family: verdana
}
#p01 {
color: blue;
font-size: 200%;
}
p.error {
color: red;
}
HTML:
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>My second HTML</title>
<link rel="stylesheet" href="css/mijn_eerste_css.css">
</head>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jan</td>
<td>Jansens</td>
<td>20</td>
</tr>
<tr>
<td>Kees</td>
<td>Pieters</td>
<td>21</td>
</tr>
</table>
When I put the exact same style settings in the HTML file like so:
<style>
table {
width: 100%;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
It works just fine.
Why doesn't this work when it's in the CSS and what do I have to do to fix it?
(The CSS is linked properly, all the other style settings work just fine.)
I tried and it works just fine for me. it shows border also correctly.
<link rel="stylesheet" href="css/mijn_eerste_css.css">.
I am not seeing any issue.

navigation bar links move when hover

In my html page I have the following for the hover action on the navigation links.
<td class="menuNormal"
onmouseover="expand(this);"
onmouseout="collapse(this);"
width="130"
align="left">
<p><b>Vida de Mulher</b></p>
<div class="menuNormal">
<table class="menu" width="130">
<tr>
<!-- ... -->
And this is the css style sheet which is used for the hover action:
table.navbar {
font-size: 12pt;
margin: 0px;
padding: 0px;
border: 0px;
}
table.menu {
font-size: 11pt;
margin: 5px;
padding: 0px;
}
td.menuNormal {
padding: 0px;
color: #003399;
vertical-align: top;
background-color: #f6f6f6;
}
td.menuHover {
padding: 0px;
color: #003399;
width: 112px;
vertical-align: top;
background-color: lightblue;
}
This may be caused by a :hover effect in your css, or maybe removing the width of your td class .menuNormal in your html code will remove this moving effect, in last case if none of these works I suggest adding the same width to td.menuHover assuming this class was created for some hover effect on your td
td.menuHover {
padding: 0px;
color: #003399;
width: 130px; /* changing this value for the same as .menuNormal */
vertical-align: top;
background-color: lightblue;
}

div with background color, semi opacity and border has invisible border?

I have some divs like this:
The second div has the class highlit
The third div has the class framed
The fourth div has both highlit and framed.
Why is the border disappearing in the fourth case?
http://jsfiddle.net/ycyrwgcz/3/
html
<table>
<tr>
<td>
<div class="thumb"><div class="overlay"></div></div>
</td>
<td>
+
</td>
<td>
<div class="highlit thumb"><div class="overlay"></div></div>
</td>
<td>
+
</td>
<td>
<div class="framed thumb"><div class="overlay"></div></div>
</td>
<td>
=
</td>
<td>
<div class="highlit framed thumb"><div class="overlay"></div></div>
</td>
</tr>
</table>
with the css
body
{
background-color: #ff8888;
}
.thumb
{
width: 40px;
height: 40px;
display: inline-block;
margin: 10px;
background-color: #8888ff;
}
.overlay
{
height: 100%;
}
.thumb.framed .overlay
{
border: 2px solid #fff;
box-sizing: border-box;
}
.thumb.highlit .overlay
{
background-color: #fff;
opacity: 0.4;
}
These are the css rules you have:
.thumb.highlit .overlay {
background-color: #FFF;
opacity: 0.4;
}
.thumb.framed .overlay {
box-sizing: border-box;
border: 2px solid #FFF;
}
Now, for the 4th <div> both the above styles get mixed up. Means, there is a background-color: #fff along with border: 2px solid #fff.
As you can see, both these are white color. And because of this you're not able to distinguish the border.
Try to change the color of any one of the above rules and you'll get the solution.
Hope this helps. :)
You want this, should be self explaining ;)
.thumb.highlit .overlay {
background-color: rgba(255,255,255,0.4);
}
http://jsfiddle.net/fxxf6kcs/1/
It isn't disappearing - just blending in with the rest of the overlay and as you have set it to be opaque it will turn purple. If you are only wanting the background to be opaque and not the whole overlay you will need to use rgba background colours:
.thumb.highlit .overlay
{
background-color: rgba(255,255,255,0.4);
}
Example
This should work back to ie 8
Try this:
body
{
background-color: #ff8888;
}
.thumb
{
width: 40px;
height: 40px;
display: inline-block;
margin: 10px;
background-color: #8888ff;
}
.overlay
{
height: 100%;
}
.thumb.framed
{
border: 2px solid #fff;
box-sizing: border-box;
}
.thumb.framed .overlay
{
box-sizing: border-box;
}
.thumb.highlit .overlay
{
background-color: #fff;
opacity: 0.4;
}
Because the background-color and border-color is same (#fff) in the fourth div.
You are using .overlay class which has the following:
.thumb.highlit .overlay {
background-color: #fff;
opacity: 0.4;
}
.thumb.framed .overlay {
border: 2px solid #fff;
box-sizing: border-box;
}

Nav Pills not active after I styled them differently in twitter bootstrap

I have tried to style the nav-pills. Everything works fine except the active state is broken. How do I get the nav-pill to be active on the first tab with the new style?
<div class="container-fluid">
<div class="row clearfix">
<div class="col-md-12 column">
<div class="tabbable" style="text-align: center;">
<ul class="nav nav-pills">
<li class="active"> <h1>Webinars</h1>
</li>
<li> <h1>Case Review Sessions</h1>
</li>
<li> <h1>Networking Meetups</h1>
</li>
<li> <h1>Certification</h1>
</li>
</ul>
and here is the css (I know it's ugly)
#menu-webinars {
color: #326799;
background-color: #ebedef;
border-radius: 0;
}
#menu-webinars:hover {
background-color: #1abc9c;
}
#menu-webinars:focus {
background-color: #1abc9c;
}
#menu-webinars:focus h1 {
color: #fff;
}
#menu-webinars:hover h1 {
color: #fff;
}
#menu-webinars h1 {
color: #545454;
margin-top: -13px;
margin-bottom: 10px;
line-height: 21px;
font-size: 21px;
}
#menu-case-review {
color: #326799;
background-color: #ebedef;
border-radius: 0;
}
#menu-case-review:hover {
background-color: #e4a824;
}
#menu-case-review:hover h1 {
color: #fff;
}
#menu-case-review:focus {
background-color: #e4a824;
}
#menu-case-review:focus h1 {
color: #fff;
}
#menu-case-review h1 {
color: #545454;
margin-top: -13px;
margin-bottom: 10px;
line-height: 21px;
font-size: 21px;
}
#menu-networking-meetups {
color: #326799;
background-color: #ebedef;
border-radius: 0;
}
#menu-networking-meetups:hover {
background-color: #326699;
}
#menu-networking-meetups:hover h1 {
color: #fff;
}
#menu-networking-meetups:focus {
background-color: #326699;
}
#menu-networking-meetups:focus h1 {
color: #fff;
}
#menu-networking-meetups h1 {
color: #545454;
margin-top: -13px;
margin-bottom: 10px;
line-height: 21px;
font-size: 21px;
}
#menu-certification {
color: #326799;
background-color: #ebedef;
border-radius: 0;
}
#menu-certification:hover {
background-color: #d8782e;
}
#menu-certification:hover h1 {
color: #fff;
}
#menu-certification:focus {
background-color: #d8782e;
}
#menu-certification:focus h1 {
color: #fff;
}
#menu-certification h1 {
color: #545454;
margin-top: -13px;
margin-bottom: 10px;
line-height: 21px;
font-size: 21px;
}
Your problem is with specificity (see http://css-tricks.com/specifics-on-css-specificity/ if you are interested in learning more). Your #menu-webinars selector is overriding the active class background color.
You could fix it by adding a selector like this:
li.active > #menu-webinars {
background-color: #0000FF;
}
But you will also need a similar rule for the other nav pills and their ids. This is because an ID selector is "stronger" than almost any other selector.
Another way would be to add something like:
li.active > a {
background-color: #0000FF !important;
}
This will work for all your nav pills, but it is considered bad practice because that !important destroys the "cascading" in "cascading style sheets" for that property.
The best (but also longest) solution is to stop using so many ID selectors in your CSS. Id selectors are not good because they can only ever apply to one element (because in HTML no two elements can have the same ID). Better to use class names or element selectors to set your styles.
Hope that helps.

Resources