Internet explorer auto height with position absolute - explorer

I'm trying to make my columns same height, it works for columns without problems, but I have div inside and it has position: absolute, in every browsers it works, but in explorer there is a problem, can you help me?
http://days.cz.uvds268.active24.cz/new/
SCREEN: https://www.dropbox.com/s/rqld6xrwb3wc2m4/Bez%20n%C3%A1zvu-1.jpg?dl=0
enter code here*
row-full-height {
height: 100%;
}
.col-full-height {
height: 100%;
vertical-align: middle;
}
.row-same-height {
display: table;
width: 100%;
/* fix overflow */
table-layout: fixed;
}
.col-xs-height {
display: table-cell;
float: none !important;
}
#media (min-width: 768px) {
.col-sm-height {
display: table-cell;
float: none !important;
}
}
#media (min-width: 992px) {
.col-md-height {
display: table-cell;
float: none !important;
}
}
#media (min-width: 1200px) {
.col-lg-height {
display: table-cell;
float: none !important;
}
}
/* vertical alignment styles */
.col-top {
vertical-align: top;
}
.col-middle {
vertical-align: middle;
}
.col-bottom {
vertical-align: bottom;
}
/* CSS of box */
#third .row-same-height >div:first-of-type .box{ position: absolute;}`
<div class="row">
<div class="row-same-height ">
<div class="col-sm-6 col-sm-height col-top">
<div class="box">
<h2>DAYS MENU s.r.o.</h2>
<p>Naše společnost zahájila výrobu v lednu 1998. Díky vysoké kvalitě a příznivé ceně svých výrobků si brzy vybudovala pevnou pozici mezi konkurencí.</p>
<p>Důkazem toho je i neustále se zvyšující počet spokojených zákazníků a pravidelných odběratelů. Snažíme se jim maximálně vyjít vstříc a podle jejich přání a požadavků pravidelně rozšiřujeme a obměňujeme naši nabídku hotových i mražených jídel.</p><br>
<div class="row display-flex">
<div class="col-sm-6 vertical-align">
<strong class="certifikace">Jsme držitelem certifikátů</strong><br><br>
</div>
<div class="col-sm-6">
<div class="row">
<div class="col-xs-6">
<img src="image/certificate_haccp.png" alt="HACCP certifikát systému kvality" class="img-responsive">
</div>
<div class="col-xs-6">
<img src="image/certificate_bisnode.png" alt="AA certifikát vysoké důvěryhodnosti" class="img-responsive">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-sm-height ">
<div class="box">
<h3>AKTUALITY</h3>
<blockquote>
<strong>4.3.2015 | HOTOVÁ TEPLÁ JÍDLA</strong>
<p>Vážení zákazníci. Z důvodu plné kapacity vozidel pro rozvoz hotových teplých jídel již bohužel nepřijímáme nové drobné odběratele (obědy pro jednotlivce). Děkujeme za pochopení.</p>
</blockquote>
<blockquote>
<strong>4.3.2015 | HOTOVÁ TEPLÁ JÍDLA</strong>
<p>Vážení zákazníci, informace o složení našich jídel a alergenech v nich obsažených dle nařízení EU č.1169/2011 - O označování potravin - Vám na vyžádání zodpovíme na tel. č. 466 951 571 nebo jsou tyto informace k dispozici na našich stránkách v nabídce jídelníčků a v nabídce mražených jídel.</p>
</blockquote>
<a class="more-news" href="vsechny-aktuality.php"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>VŠECHNY AKTUALITY</a>
</div>
</div>
</div>
</div>

Related

Swiper.js Forced Reflow performance issues when responsive

A question about using swiper.js carousel/slider gallery. I'm getting bad performance issues with "forced reflow" when making the slider responsive.
If the viewport is resized then the forced reflow is extreme. How do I go about debugging this?
Swiper github says this is the best place for asking for support.
I've added example code here.
Codepen
// Just duplicating swiper 20 times
const listing = document.getElementsByClassName("listing")[0];
for (let i = 0; i < 19; i++) {
let clone = listing.cloneNode(true);
clone.getElementsByClassName("swiper-container")[0].id = `carousel-${i+1}`;
document.getElementsByClassName("grid")[0].appendChild(clone);
newSwiper(i + 1);
}
function newSwiper(i) {
let swiper = new Swiper(`#carousel-${i}`, {
initialSlide: Math.floor(Math.random() * 6),
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
}
});
}
#import url('https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.1/css/swiper.min.css');
.grid {
display: grid;
grid-gap: 0.5rem;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.swiper-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.listing {
background: orange;
width: 100%;
position: relative;
}
.listing::before {
content: "";
display: inline-block;
width: 1px;
height: 0;
padding-bottom: 70%;
}
img {
height: 100%;
width: 100%;
object-fit: cover;
}
<div class="grid">
<div class="listing">
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<img src="https://i.imgur.com/8aoOSaob.jpg" alt="thumb">
</div>
<div class="swiper-slide">
<img src="https://i.imgur.com/FB5IGMgb.jpg" alt="thumb">
</div>
<div class="swiper-slide">
<img src="https://i.imgur.com/GBpr1JR.png" alt="thumb">
</div>
<div class="swiper-slide">
<img src="https://i.imgur.com/UYqiudHb.jpg" alt="thumb">
</div>
<div class="swiper-slide">
<img src="https://i.imgur.com/BBFBbuA.jpeg" alt="thumb">
</div>
<div class="swiper-slide">
<img src="https://i.imgur.com/tpZvfRn.jpg" alt="thumb">
</div>
</div>
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.1/js/swiper.min.js"></script>
I spent way too much time trying to fix this problem. Playing with the css over and over. I've come to the conclusion it's swiper.js. Perhaps how things are recalculated somewhere.
I switched the code over the glide.js and no performance problems. There's no lazy loading included so more development time needed to plug that gap.

How do I convert my vue into a component.vue

I have a fiddle that changes the contrast and brightness of an image.
When I try and add it as a .vue component onto my site the slider no longer effects the image. I know the issue is around my filter function. I just can't understand why my :style attribute isn't applying the change to me element.
What am I doing wrong/not getting?
fiddle that works - https://jsfiddle.net/BBMAN/fxtrtqpj/14/
code for my .vue component that does not work.
<template>
<div class="brightness-slider container">
<h1>{{ msg }}</h1>
<h2>Built using Vue.js</h2>
<div class="row">
<div class="col-md-10">
<img ref="img" class="img img-responsive" :style="filters" />
</div>
<div class="col-md-2">
<strong>Contrast ({{contrast}})</strong>
<input class="slider vertical" type="range" orient="vertical" v-model="contrast" max="1" min="0" step="0.01" />
</div>
</div>
<div class="row">
<div class="col-md-12">
<h4>
<strong>Brightness ({{brightness}})</strong>
</h4>
<input class="slider horizontal" type="range" v-model="brightness" max="3" min="0" step="0.01" />
</div>
</div>
</div>
</template>
<script>
export default {
name: 'ImageBrightnessSlider',
data() {
return {
//sending data to view.
msg: 'Audience Republic Brightness Modifier',
brightness: 1,
contrast: 1
}
},computed: {
filters() {
const toDash = (str) => str.replace( /([a-z])([A-Z])/g, '$1-$2' ).toLowerCase()
debugger;
return { filter: Object.entries(this._data).filter(item => typeof(item[1]) !== 'object').map(item => `${toDash(item[0])}(${item[1]})`).join(' ') }
}
},
mounted() {
this.$refs.img.src = require('../assets/pleasure-garden-1200-by-768.jpg')
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1,
h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
input[type=range][orient=vertical]{
writing-mode: bt-lr; /* IE */
-webkit-appearance: slider-vertical; /* WebKit */
width: 8px;
height: 100%;
padding: 0 5px;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 3px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
</style>
"fiddle that works" = incorrect
you are trying to shove HTML CSS JavaScript into Javascript!!!
interpreter Javascript does not understand HTML CSS!
you code must be something like this
index.html
<div id="App">
<!-- HTML code -->
</div>
<script>
// js code
</script>
<style scoped>
/* css code */
</style>
you have many mistakes, please see official documentation
also, you can see my vue examples
UPDATED:
SFC example

Media query not working, hiding Bootstrap jumbotron when viewed from mobile device

can't get media query to work, trying to hide jumbotron when viewed from mobile device.
url tyrescanner.net
code below
/* Extra Small Devices, Phones */
#media screen and (max-width: 380px) {
.customjumbotron{
background-color: black;
}
}
<div class="row no-container">
<div class="col-md-12">
<div class="jumbotron text-center customjumbotron">
<img class="img-responsive image-center" src="../Images/Nectar-CollectPoints.png" height="130" width="490" style= "margin-bottom: -10px"" />
<h2>Search for tyres and prices in your local area</h2>
<div class="searchbox">
<div class="input-group input-group-lg">
<div class="input-btn-toolbar" style="width:107%; height: 100%;">
<div class="input-btn-toolbar" style=" background-color:#313131; padding-left:5px; padding-top:7px; padding-bottom:3px; padding-right:3px;">
<asp:TextBox style="text-transform: uppercase; width:100%; font-size: 23px; text-align: center;" ID="txtReg" class="form-control" runat="server" placeholder="Enter Registration"></asp:TextBox>
<span class="input-group-btn" >
<asp:LinkButton class ="btn btn-default btn-default1" OnClick="ButtonSearch_Click" height="49" runat="server" type="button" style="color:white" ID="bntSearch"><span aria-hidden="true" class="glyphicon glyphicon-search"></span></asp:LinkButton>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
To make the jumbotron appear as a black background on small screens, add color: black; to your media query. That way, everything in the jumbotron will appear black (though there are probably much more elegant ways to do it).
Working example:
/* Extra Small Devices, Phones */
#media screen and (max-width: 380px) {
.customjumbotron{
background-color: black;
color: black;
}
#imgID {
display: none;
}
#imgHide {
display: block;
}
}
/* Larger Devices */
#media screen and (min-width: 381px) {
#imgHide {
display: none;
}
}
<div class="row no-container">
<div class="col-md-12">
<div class="jumbotron text-center customjumbotron">
<img class="img-responsive image-center" id="imgID" src="../Images/Nectar-CollectPoints.png" height="130" width="490" style="margin-bottom: -10px" />
<img class="img-responsive image-center" id="imgHide" src="" height="130" width="490" style="margin-bottom: -10px"></div>
<h2>Search for tyres and prices in your local area</h2>
<div class="searchbox">
<div class="input-group input-group-lg">
<div class="input-btn-toolbar" style="width:107%; height: 100%;">
<div class="input-btn-toolbar" style=" background-color:#313131; padding-left:5px; padding-top:7px; padding-bottom:3px; padding-right:3px;">
<asp:TextBox style="text-transform: uppercase; width:100%; font-size: 23px; text-align: center;" ID="txtReg" class="form-control" runat="server" placeholder="Enter Registration"></asp:TextBox>
<span class="input-group-btn" >
<asp:LinkButton class ="btn btn-default btn-default1" OnClick="ButtonSearch_Click" height="49" runat="server" type="button" style="color:white" ID="bntSearch"><span aria-hidden="true" class="glyphicon glyphicon-search"></span></asp:LinkButton>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
EDIT: Now hides the image in the jumbotron for small screens.
I fund the problem, I had to add another Media query to the Jumbotrom
#media only screen and (min-width : 992px) {
.customjumbotron {
/*.jumbotron*/
background: url('../Images/Tyre.jpg') no-repeat center center;
background-size: cover;
background-attachment: fixed;
min-height: 410px;
min-width: 100%;
width: 100%;
margin-right: 0px !important;
margin-left: 0px !important;
margin-bottom: 0px;
padding-right: 0px;
padding-left: 0px;
padding-bottom: 0px;
}
}
First identify what kind of iPhone you need to make it hide read iPhone 6 Screen Size and Web Design Tips first. Then use the points of different iPhone versions to add value for max-width or min-width to create changes, you can use either of the two. But take note of other devices breakpoints not only iPhone if you add breakpoints of more than one iPhone version breakpoints. I use in the sample codes below the minimum width of the largest iPhone version in order for your design make changes for all iPhone easily, but it depends:
USING LARGEST iPHONE VERSION MINIMUM POINTS:
<style type="text/css">
/* iPhone 6/7 Plus | 414 x 736 points */
#media only screen and (max-width : 414px) {
body{
background-color: teal;
}
.customjumbotron{
display: none;
}
}
</style>
USING iPHONE VERSION MAX-WIDTH:
<style type="text/css">
/* iPhone 4 | 320 x 480 points */
#media only screen and (max-width : 480px) {
body{
background-color: gold;
}
.customjumbotron{
display: none;
}
}
/* iPhone 5 | 320 x 568 points */
#media only screen and (max-width : 568px) {
body{
background-color: silver;
}
.customjumbotron{
display: none;
}
}
/* iPhone 6/7 | 375 x 667 points */
#media only screen and (max-width : 667px) {
body{
background-color: teal;
}
.customjumbotron{
display: none;
}
}
/* iPhone 6/7 Plus | 414 x 736 points */
#media only screen and (max-width : 736) {
body{
background-color: teal;
}
.customjumbotron{
display: none;
}
}
</style>
USING DIFFERENT iPHONE VERSION MIN-WIDTH:
<style type="text/css">
/* iPhone 4 | 320 x 480 points */
#media only screen and (min-width : 320px) {
body{
background-color: gold;
}
.customjumbotron{
display: none;
}
}
/* iPhone 5 | 320 x 568 points */
#media only screen and (min-width : 320px) {
body{
background-color: silver;
}
.customjumbotron{
display: none;
}
}
/* iPhone 6/7 | 375 x 667 points */
#media only screen and (min-width : 375px) {
body{
background-color: teal;
}
.customjumbotron{
display: none;
}
}
/* iPhone 6/7 Plus | 414 x 736 points */
#media only screen and (min-width : 414px) {
body{
background-color: teal;
}
.customjumbotron{
display: none;
}
}
</style>
DEFAULT BOOTSTRAP MEDIA QUERIES
<style type="text/css">
/*==================================================
Bootstrap 3 Media Queries
==================================================*/
/* Extra Small Devices, Phones */
#media only screen and (min-width : 480px) {
/* YOUR CODE HERE|EXAMPLE CODES*/
body{
background-color: black;
}
}
/* Small Devices, Tablets */
#media only screen and (min-width : 768px) {
/* YOUR CODE HERE|EXAMPLE CODES*/
body{
background-color: blue;
}
}
/* Medium Devices, Desktops */
#media only screen and (min-width : 992px) {
/* YOUR CODE HERE|EXAMPLE CODES| SET HERE WHAT YOU NEED TO HIDE OR ANYTHING*/
body{
background-color: green;
}
}
/* Large Devices, Wide Screens */
#media only screen and (min-width : 1200px) {
/* YOUR CODE HERE*/
}
</style>

Create alert using materialize css

I want to create an alert using materialize css. I don't know how. Please help. I just want to create a simple html that will display an alert error without using javascript. Thanks.
since this has no answer yet, I made something that may help you. Here is the repo
And here is a preview.
html {
line-height: 1.5;
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
}
.materialert{
position: relative;
min-width: 150px;
padding: 15px;
margin-bottom: 20px;
margin-top: 15px;
border: 1px solid transparent;
border-radius: 4px;
transition: all 0.1s linear;
webkit-box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2);
box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2);
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
.materialert .material-icons{
margin-right: 10px;
}
.materialert .close-alert{
-webkit-appearance: none;
border: 0;
cursor: pointer;
color: inherit;
background: 0 0;
font-size: 22px;
line-height: 1;
font-weight: bold;
text-shadow: 0 1px 0 rgba(255, 255, 255, .7);
filter: alpha(opacity=40);
margin-bottom: -5px;
position: absolute;
top: 16px;
right: 5px;
}
.materialert.info{
background-color: #039be5;
color: #fff;
}
.materialert.success{
background-color: #43a047;
color: #fff;
}
.materialert.error{
background-color: #c62828;
color: #fff;
}
.materialert.danger{
background-color: #c62828;
color: #fff;
}
.materialert.warning{
background-color: #fbc02d;
color: #fff;
}
<html lang="es-MX">
<head>
<meta charset="UTF-8">
<link href="css/materialert.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="materialert">
<i class="material-icons">check_circle</i> <span>Bienvenido, Linebeck</span>
<button type="button" class="close-alert">×</button>
</div>
<div class="materialert info">
<div class="material-icons">info_outline</div>
Oh! What a beautiful alert :)
</div>
<div class="materialert error">
<div class="material-icons">error_outline</div>
Oh! What a beautiful alert :)
</div>
<div class="materialert success">
<div class="material-icons">check</div>
Oh! What a beautiful alert :)
</div>
<div class="materialert warning">
<div class="material-icons">warning</div>
Oh! What a beautiful alert :)
</div>
</body>
</html>
Hope it helps!
Materializecss alert box
Codepen link
<div class="row" id="alert_box">
<div class="col s12 m12">
<div class="card red darken-1">
<div class="row">
<div class="col s12 m10">
<div class="card-content white-text">
<p>1. Username cant be empty</p>
<p>2. Password cant be empty</p>
<p>3. Address cant be empty</p>
<p>4. Name cant be empty</p>
</div>
</div>
<div class="col s12 m2">
<i class="fa fa-times icon_style" id="alert_close" aria-hidden="true"></i>
</div>
</div>
</div>
</div>
</div>
.icon_style{
position: absolute;
right: 10px;
top: 10px;
font-size: 20px;
color: white;
cursor:pointer;
}
$('#alert_close').click(function(){
$( "#alert_box" ).fadeOut( "slow", function() {
});
});
Unfortunately materialize doesn't provide alerts as bootstrap does.
You can use card-panel class instead:
http://materializecss.com/color.html
But you won't have close button to hide it.
This is a pretty late answer but you can use the modal class for these kind of things.
Example:
$(document).ready(function(){
// the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
$('.modal').modal();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/js/materialize.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.css" rel="stylesheet"/>
<!-- Modal Trigger -->
<a class="waves-effect waves-light btn" href="#modal1">Modal</a>
<!-- Modal Structure -->
<div id="modal1" class="modal">
<div class="modal-content">
<h4>Alert</h4>
<p>You can use this as a alert!</p>
</div>
<div class="modal-footer">
OK
</div>
</div>
Reference: http://materializecss.com/modals.html#!
$(document).ready(function(){
Materialize.toast('I am Alert', 4000)
});
See DEMO here: http://codepen.io/ihemant360/pen/pbPyJb
You can use Matdialog.js to create different types of dialogboxes.
check it out at - MatDialog.js website
Install Toastr
bower install toastr
Require files
/bower_components/toastr.css
/bower_components/toastr.js
initialize toastr
toastr.options = {
"closeButton": true,
"debug": false,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-bottom-left",
"preventDuplicates": true,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "3000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
Use
Success: toastr.success('success');
Error: toastr.error('fail');
Info: toastr.info('info');
Credit
Documentation: https://github.com/CodeSeven/toastr
Demo: http://codeseven.github.io/toastr/demo.html
I resolved this issue by using chips (https://materializecss.com/chips.html) and formating css style to fit the purpose.
https://codepen.io/krazer_spa/pen/VRmxzy
<div class="container">
<div class="flash_message">
<div class="chip chip_message_info">
This is an info message
<i class="close material-icons">close</i>
</div>
<div class="chip chip_message_warning">
This is a warning message
<i class="close material-icons">close</i>
</div>
<div class="chip chip_message_alert">
This is an alert message
<i class="close material-icons">close</i>
</div>
</div>
</div>
<style>
.flash_message {
position: fixed;
top: 70px;
z-index: 99999;
min-width: 80%;
}
.chip_message_info,
.chip_message_warning,
.chip_message_alert {
text-align: center;
padding-top: 10px !important;
padding-bottom: 10px !important;
font-size: 20px !important;
min-width: 80%;
min-height: 50px;
}
.chip_message_info {
background-color: #bbdefb !important;
}
.chip_message_warning {
background-color: #ffcc80 !important;
}
.chip_message_alert {
background-color: #ef9a9a !important;
}
</style>
ReactJS + Materialize
Alert.js
import React, { useState } from "react";
const Alert = ({ type, children }) => {
const [isVisible, setIsVisible] = useState(true);
// set alert color based on type
let color;
switch (type) {
case "danger":
color = "red lighten-2";
break;
case "success":
color = "green lighten-2";
break;
case "info":
color = "blue lighten-2";
break;
case "warning":
color = "yellow lighten-2";
break;
default:
color = "white lighten-2";
break;
}
return (
<>
{isVisible && (
<div className="row mv--small" id="alert-box">
<div className="col s12 m12">
<div className={`card m--none z-depth-0 ${color}`}>
<div className="card-content black-text">{children}</div>
<i
className="material-icons icon_style"
id="alert_close"
aria-hidden="true"
onClick={() => setIsVisible(false)}
>
close
</i>
</div>
</div>
</div>
)}
</>
);
};
export default Alert;
You can then use it like this:
<Alert type="info">
test
</Alert>
And it looks like this:

Correct naming convention for styling only classes in Bootstrap 3?

Im using Twitter Bootstrap 3 and I want to make reusable styling classes. The code below works exactly how I want it to but does it conform to the SMACKS /OOCSS naming convention used by Bootstrap?
Note - Im using LESS not plain CSS so ill be using variables for things like border thickness that are repeated.
<div class="box box-red">
<div class="odd">
First content
</div>
<div class="even">
second content
</div>
<div class="odd">
third content
</div>
</div>
<div class="box box-green">
<div class="odd">
First content
</div>
<div class="even">
second content
</div>
<div class="odd">
third content
</div>
</div>
/* Box styles */
.box {
margin: 10px;
border-radius: 10px;
}
.box > .odd,
.box > .even {
padding: 10px;
}
.box > .odd:last-child,
.box > .even:last-child {
border-bottom: none;
}
/* Red box styles */
.box-red {
background: #ffcccc;
border: 1px solid #ff0000;
}
.box-red > .odd,
.box-red > .even {
border-bottom: 1px solid #ff0000;
}
.box-red > .even {
background: #ff4c4c;
}
/* Green box styles */
.box-green {
background: #BCED91;
border: 1px solid #3B5323;
}
.box-green > .odd,
.box-green > .even {
border-bottom: 1px solid #3B5323;
}
.box-green > .even {
background: #78AB46;
}
http://codepen.io/anon/pen/jduyE
You need to think about what is common between all of the components and what are the differences. In your case, you just want to have different colors, so don't repeat for example the styles for the border-width or border-style. Additionally, it would be tedious and error-prone if you have to markup odd and even rows differently. The :nth-child pseudo class accepts odd and even as keywords. It's important to note that nth-child isn't supported on IE8, but neither is last-child, and you were already using that so I figured that IE8 wasn't important for you.
CSS:
/* Box styles */
.box {
margin: 10px;
border-radius: 10px;
border: 1px solid transparent;
}
.box > .box-content-row {
padding: 10px;
border-bottom: 1px solid transparent;
}
.box > .box-content-row:last-child {
border-bottom: none;
}
/* Red box styles */
.box-red {
background: #ffcccc;
border-color: #ff0000;
}
.box-red > .box-content-row:nth-child(even) {
background: #ff4c4c;
}
.box.box-red > .box-content-row {
border-color: #ff0000;
}
/* Green box styles */
.box-green {
background: #BCED91;
border-color: #3B5323;
}
.box-green > .box-content-row:nth-child(even) {
background: #78AB46;
}
.box.box-green > .box-content-row {
border-color: #3B5323;
}
HTML:
<div class="box box-red">
<div class="box-content-row">
First content
</div>
<div class="box-content-row">
second content
</div>
<div class="box-content-row">
third content
</div>
<div class="box-content-row">
add a fourth div for fun
</div>
<div class="box-content-row">
and what the heck a fifth one too
</div>
</div>
<div class="box box-green">
<div class="box-content-row">
First content
</div>
<div class="box-content-row">
second content
</div>
<div class="box-content-row">
third content
</div>
</div>