Select middle elements with different classes from css - html

I am stuck in an issue where I want to select divs having specific classes within other divs. I want to target middle element with "active" class. In this case the third div with "active" class
I tried using .container .active:nth-child(3) but it is not working. Please help
.container .active:nth-child(3) {
background-color: red;
}
.container .active:nth-of-type(3) {
background-color: red;
}
<div class="container">
<div class="item">abc</div>
<div class="item">abc</div>
<div class="item">abc</div>
<div class="item active">active</div>
<div class="item active">active</div>
<div class="item active">Active but highlighted</div>
<div class="item active">active</div>
<div class="item active">active</div>
<div class="item">abc</div>
<div class="item">abc</div>
<div class="item">abc</div>
</div>

The :nth-of-type() actually only accounts for the type of element, not the type of class. This is the best solution I can think of right now, I'll update if I figure out a better way:
.container :is(.active + .active + .active):not(.active + .active + .active + .active) {
background-color: red;
}
<div class="container">
<div class="item">abc</div>
<div class="item">abc</div>
<div class="item">abc</div>
<div class="item active">active</div>
<div class="item active">active</div>
<div class="item active">Active but highlighted</div>
<div class="item active">active</div>
<div class="item active">active</div>
<div class="item active">active</div>
<div class="item">abc</div>
<div class="item">abc</div>
<div class="item">abc</div>
</div>

Related

How can I select all elements except those inside divs with particular classes

I'd like to find a way to select all the makes of cars except those that are inside a div with the class discontinued or scrapped. Here's my markup:
div:not(.discontinued):not(.scrapped) > .make {
color: green;
}
<div class="car">
<div class="make">NISSAN</div>
<div class="model">MICRA</div>
</div>
<div class="discontinued">
<div class="car">
<div class="make">FORD</div>
<div class="model">MONDEO</div>
</div>
</div>
<div class="scrapped">
<div class="car">
<div class="make">SEAT</div>
<div class="model">IBIZA</div>
</div>
</div>
<div class="scrapped">
<div class="preowned">
<div class="car">
<div class="make">BMW</div>
<div class="model">100</div>
</div>
</div>
</div>
<div class="car">
<div class="make">HONDA</div>
<div class="model">INTEGRA</div>
</div>
</div>
<div class="car">
<div class="make">PEUGEOT</div>
<div class="model">206</div>
</div>
<div class="car">
<div class="make">TOYOTA</div>
<div class="model">COROLLA</div>
</div>
As you can see above, I tried the following:
div:not(.discontinued):not(.scrapped) > .make
...but this still included FORD, SEAT, and BMW.
Unfortunately CSS selectors cannot traverse up parent elements, so if you are just trying to style them differently you may want to reverse your thought process and select ones that are .discontinued or .scrapped and apply overriding styles:
.model {
padding-left: 10px;
}
.make {
color: green;
}
.scrapped .make,
.discontinued .make {
color: red;
}
<div class="car">
<div class="make">NISSAN</div>
<div class="model">MICRA</div>
</div>
<div class="discontinued">
<div class="car">
<div class="make">FORD</div>
<div class="model">MONDEO</div>
</div>
</div>
<div class="scrapped">
<div class="car">
<div class="make">SEAT</div>
<div class="model">IBIZA</div>
</div>
</div>
<div class="scrapped">
<div class="preowned">
<div class="car">
<div class="make">SEAT</div>
<div class="model">IBIZA</div>
</div>
</div>
</div>
<div class="car">
<div class="make">HONDA</div>
<div class="model">INTEGRA</div>
</div>
<div class="car">
<div class="make">PEUGEOT</div>
<div class="model">206</div>
</div>
<div class="car">
<div class="make">TOYOTA</div>
<div class="model">COROLLA</div>
</div>
Why don't you try this style code,
div.make:not(.discontinued .make):not(.scrapped .make) {
color: green;
}

How to create table without breaking row? (Bootstrap)

I have this bootstrap snippet:
<div class="col-xs-12">
<div class="row">
<div class="col-xs-3">
<div class="col-xs-12">Project Name</div>
</div>
<div class="col-xs-9">
<div class="col-xs-1">Jan</div>
<div class="col-xs-1">Feb</div>
<div class="col-xs-1">Mar</div>
<div class="col-xs-1">Apr</div>
<div class="col-xs-1">May</div>
<div class="col-xs-1">Jun</div>
<div class="col-xs-1">Jul</div>
<div class="col-xs-1">Aug</div>
<div class="col-xs-1">Sep</div>
<div class="col-xs-1">Okt</div>
<div class="col-xs-1">Nov</div>
<div class="col-xs-1">Dec</div>
</div>
</div>
<div class="row">
<div class="col-xs-3">
<div class="col-xs-12">Project #1</div>
</div>
<div class="col-xs-9">
<div class="col-xs-1">10</div>
<div class="col-xs-1">20</div>
<div class="col-xs-1">30</div>
<div class="col-xs-1">40</div>
<div class="col-xs-1">50</div>
<div class="col-xs-1">60</div>
<div class="col-xs-1">70</div>
<div class="col-xs-1">80</div>
<div class="col-xs-1">90</div>
<div class="col-xs-1">100</div>
<div class="col-xs-1">110</div>
<div class="col-xs-1">120</div>
</div>
</div>
</div>
it creates this table:
Everything looks good on the Desktop, but when I watch it on mobile or tablet it breaks:
Is it possible to create it without breaking? (version with tables does not fit)
Try setting a min-width on the container like this:
.container {
min-width: 630px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-xs-12 container">
<div class="row">
<div class="col-xs-3">
<div class="col-xs-12">Project Name</div>
</div>
<div class="col-xs-9">
<div class="col-xs-1">Jan</div>
<div class="col-xs-1">Feb</div>
<div class="col-xs-1">Mar</div>
<div class="col-xs-1">Apr</div>
<div class="col-xs-1">May</div>
<div class="col-xs-1">Jun</div>
<div class="col-xs-1">Jul</div>
<div class="col-xs-1">Aug</div>
<div class="col-xs-1">Sep</div>
<div class="col-xs-1">Okt</div>
<div class="col-xs-1">Nov</div>
<div class="col-xs-1">Dec</div>
</div>
</div>
<div class="row">
<div class="col-xs-3">
<div class="col-xs-12">Project #1</div>
</div>
<div class="col-xs-9">
<div class="col-xs-1">10</div>
<div class="col-xs-1">20</div>
<div class="col-xs-1">30</div>
<div class="col-xs-1">40</div>
<div class="col-xs-1">50</div>
<div class="col-xs-1">60</div>
<div class="col-xs-1">70</div>
<div class="col-xs-1">80</div>
<div class="col-xs-1">90</div>
<div class="col-xs-1">100</div>
<div class="col-xs-1">110</div>
<div class="col-xs-1">120</div>
</div>
</div>
</div>
This approach can work for narrow viewports:
[class^="col-"] {
font-size: 2.5vw;
padding: 0;
}
You can wrap it into #media for x-small screens only.
You can set the elements wrapping the breaking divs to display: flex, which will by default display them in one row instead of breaking:
.flex {
display: flex;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-xs-12 container">
<div class="row">
<div class="col-xs-3 flex">
<div class="col-xs-12">Project Name</div>
</div>
<div class="col-xs-9 flex">
<div class="col-xs-1">Jan</div>
<div class="col-xs-1">Feb</div>
<div class="col-xs-1">Mar</div>
<div class="col-xs-1">Apr</div>
<div class="col-xs-1">May</div>
<div class="col-xs-1">Jun</div>
<div class="col-xs-1">Jul</div>
<div class="col-xs-1">Aug</div>
<div class="col-xs-1">Sep</div>
<div class="col-xs-1">Okt</div>
<div class="col-xs-1">Nov</div>
<div class="col-xs-1">Dec</div>
</div>
</div>
<div class="row">
<div class="col-xs-3 flex">
<div class="col-xs-12">Project #1</div>
</div>
<div class="col-xs-9 flex">
<div class="col-xs-1">10</div>
<div class="col-xs-1">20</div>
<div class="col-xs-1">30</div>
<div class="col-xs-1">40</div>
<div class="col-xs-1">50</div>
<div class="col-xs-1">60</div>
<div class="col-xs-1">70</div>
<div class="col-xs-1">80</div>
<div class="col-xs-1">90</div>
<div class="col-xs-1">100</div>
<div class="col-xs-1">110</div>
<div class="col-xs-1">120</div>
</div>
</div>
</div>

Bootstrap 3 grid row span

I'm trying to make a grid based on bootstrap only I need 1 div to span 3 rows.
I've added a picture below inclusive the code I used. For the main grid I used a generator but now I get stuck.
The div which says REMOVE I added as a dummy and need to be removed. only when I do that the div with MOST READ will move to the right and closes the gap.
What I'm trying to achieve is that COMMENTS - SITE FEED will span 3 rows (vertically downwards) next to, in the spot light, quiz/poll and most read.
How can I do this with wrapping some stuff so it not move and shift anymore :-)
<div class="container">
<div class="row">
<div class="col-md-12">col-md-12 - MARQUE</div>
</div>
<div class="row">
<div class="col-md-8">col-md-8 - CAROUSEL</div>
<div class="col-md-4">col-md-4 - MY STUFF</div>
</div>
<div class="row">
<div class="col-md-12">col-md-12 - 5 ARTICLES</div>
</div>
<div class="row">
<div class="col-md-6">col-md-6 - LOCAL NEWS</div>
<div class="col-md-6">col-md-6 - SEGMENTS NEWS</div>
<div class="col-md-6">col-md-6 - COUNTRY NEWS</div>
<div class="col-md-6">col-md-6 - TWITTER</div>
</div>
<div class="row">
<div class="col-md-3">col-md-3 - BLOG</div>
<div class="col-md-3">col-md-3 - IN SPOT LIGHT</div>
<div class="col-md-6">col-md-6 - - COMMENTS - SITE FEED</div>
<div class="col-md-3">col-md-3 - STEEL FABRIC</div>
<div class="col-md-3">col-md-3 - QUIZ/POLL</div>
<div class="col-md-6">col-md-6 - remove !!!!</div>
<div class="col-md-6">col-md-6 - MOST READ</div>
</div>
<div class="row">
<div class="col-md-3">col-md-3 - UNDETER 1</div>
<div class="col-md-3">col-md-3 - UNDETER 2</div>
<div class="col-md-3">col-md-3 - UNDETER 3</div>
<div class="col-md-3">col-md-3 - SHAREHOLDER</div>
</div>
<div class="row">
<div class="col-md-12">col-md-12 - QUICK ACCESS</div>
</div>
I have not tried the suggested code but I will soon. I've noticed I was not so clear after all so I made a second picture. The Red block represent the COMMENTS SITE FEED div how i need it in the end result. Hopefully it helps a bit thanks so far guys. it#s really appreciated!
enter image description here
You have to nest row in another row to achieve your goal.
HTML:
<div class="container">
<div class="row">
<div class="col-md-12 red col">col-md-12 - MARQUE</div>
</div>
<div class="row">
<div class="col-md-8 blue col">col-md-8 - CAROUSEL</div>
<div class="col-md-4 green col">col-md-4 - MY STUFF</div>
</div>
<div class="row">
<div class="col-md-12 orange col">col-md-12 - 5 ARTICLES</div>
</div>
<div class="row">
<div class="col-md-6 blue col">col-md-6 - LOCAL NEWS</div>
<div class="col-md-6 green col">col-md-6 - SEGMENTS NEWS</div>
</div>
<div class="row">
<div class="col-md-6 green col">col-md-6 - COUNTRY NEWS</div>
<div class="col-md-6 blue col">col-md-6 - TWITTER</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-6 orange col">col-md-3 - BLOG</div>
<div class="col-md-6 blue col">col-md-3 - IN SPOT LIGHT</div>
</div>
<div class="row">
<div class="col-md-6 green col">col-md-3 - STEEL FABRIC</div>
<div class="col-md-6 orange col">col-md-3 - QUIZ/POLL</div>
</div>
<div class="row">
<div class="col-md-12 red col">col-md-6 - MOST READ</div>
</div>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-12 green comments-site-feed">
col-md-6 - - COMMENTS - SITE FEED
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3 green col">col-md-3 - UNDETER 1</div>
<div class="col-md-3 blue col">col-md-3 - UNDETER 2</div>
<div class="col-md-3 orange col">col-md-3 - UNDETER 3</div>
<div class="col-md-3 green col">col-md-3 - SHAREHOLDER</div>
</div>
<div class="row">
<div class="col-md-12 red col">c`ol-md-12 - QUICK ACCESS</div>
</div>
</div>
CSS:
.col {
background: #ccc;
height: 125px;
}
.row > .red {
background: red;
color: #fff;
}
.row .blue {
background: blue;
color: #fff;
}
.row .green {
background: green;
}
.row .orange {
background: orange;
}
.row > .comments-site-feed {
background: black;
color: #fff;
height: 375px;
}
CODEPEN
I may have misunderstood what exactly you are going for but I think you may have to nest some elements in order to get the rowspan effect you are looking for.
<div class="row">
<div class="col-md-6">COMMENTS - SITE FEED</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-12">STEEL FABRIC</div>
</div>
<div class="row">
<div class="col-md-12">QUIZ/POLL</div>
</div>
<div class="row">
<div class="col-md-12">MOST READ</div>
</div>
</div>
</div>
You need to group these divs as two columns.
The following should achieve the desired grid layout:
<div class="row">
<div class="col-md-6">
<div class="col-md-6">col-md-6 - BLOG</div>
<div class="col-md-6">col-md-6 - IN SPOT LIGHT</div>
<div class="col-md-6">col-md-6 - STEEL FABRIC</div>
<div class="col-md-6">col-md-6 - QUIZ/POLL</div>
<div class="col-md-12">col-md-12 - MOST READ</div>
</div>
<div class="col-md-6">
col-md-6 - - COMMENTS - SITE FEED
</div>
</div>

How to make content inside a circle div fitting correctly

I need to implement a structure like the graph following (with HTML, CSS) and I don't have any idea how to make the content (the circles) fit inside the bigger circle.
I would appreciate any solution that solves the problem at least partially.
I added a simplified page with some basic HTML and CSS for this problem. What I need is for the content inside the div.structure to fit (see the first image).
That would be a good start for what I need.
.structure {
float: left;
text-align: center;
background-color: #ccc;
border-radius: 50%;
margin: 20%;
width: 60%;
display: table;
}
.item {
width: 50px;
height: 50px;
float: left;
margin: 10px 5px;
background-color: deeppink;
border-radius: 50%;
display: table-cell;
vertical-align: middle;
}
.item.s1 {
background-color: deeppink;
}
.item.s2 {
background-color: green;
}
.item.s3 {
background-color: red;
}
.item.s4 {
background-color: blue;
}
.item.s5 {
background-color: aqua;
}
.structura_dep.dep6 {
background-color: gray;
}
<div class="structure">
<div class="item s1">
</div>
<div class="item s1">
</div>
<div class="item s1">
</div>
<div class="item s1">
</div>
<div class="item s1">
</div>
<div class="item s1">
</div>
<div class="item s1">
</div>
<div class="item s1">
</div>
<div class="item s1">
</div>
<div class="item s1">
</div>
<div class="item s1">
</div>
<div class="item s1">
</div>
<div class="item s1">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s2">
</div>
<div class="item s3">
</div>
<div class="item s3">
</div>
<div class="item s3">
</div>
<div class="item s3">
</div>
<div class="item s3">
</div>
<div class="item s3">
</div>
<div class="item s3">
</div>
<div class="item s3">
</div>
<div class="item s3">
</div>
<div class="item s3">
</div>
<div class="item s3">
</div>
<div class="item s3">
</div>
<div class="item s3">
</div>
<div class="item s3">
</div>
</div>
I just worked a little bit on this but i think you can get the idea you just have to add your shapes i gave you a start in the right direction though
Codepen http://codepen.io/noobskie/pen/NGqPEJ?editors=110
There is probably other better ways to complete this but this is just to give you a idea.
Ive wrapped all your colors into spans just for better orginazation.
To add a new circle all you need to do is copy ie:<a href='#' class='deg10'></a> paste it into the same span rename the class to <a href='#' class='deg20'></a> and then just change the scss accordingly.
All its using primarily is the css transform property and moving it along the page.
A good article to checkout and help you along with this could be found here Position icons into circle

CSS - target last instance of div

I have a div structure as below and i want to only target the last .pcontain on the page so i can remove the border-right - how do i go about it?
<div class="container">
<div class="postcontainer">
<div class="latest-posts">
<div class="thumbnail"></div>
<div class="pcontain"></div>
<div class="more"></div>
</div>
</div>
<div class="postcontainer">
<div class="latest-posts">
<div class="thumbnail"></div>
<div class="pcontain"></div>
<div class="more"></div>
</div>
</div>
<div class="postcontainer">
<div class="latest-posts">
<div class="thumbnail"></div>
<div class="pcontain"></div>
<div class="more"></div>
</div>
</div>
<div class="postcontainer">
<div class="latest-posts">
<div class="thumbnail"></div>
<div class="pcontain"></div>
<div class="more"></div>
</div>
</div>
</div>
Working Fiddle
Use last child
.postcontainer:last-child .pcontain{
background: black;
color: white;
}
Read more about last-child here
You can use the last-child pseudo-class like:
.postcontainer:last-child .pcontain {
color: darkolive;
}
http://jsfiddle.net/ZZMZn/10/