Cover image with dynamic height CSS - html

I am trying to find solution for the problem.
I have following block
As you can image takes more space than content. But in general image looks nice.
I want to get the same behavior but to crop/cover image according to the text size. Currently this block doesn't have fixed height. So I guess it is impossible to get desired result without fixed height.
My html
<article id="post-313" class="col-md-12 l-post post post--short post-type--post">
<div class="l-post-thumbnail col-md-4 col-xs-12">
<div class="post-thumbnail">
<img src="http://martinsolutionsrd.com/wp-content/uploads/2016/05/para1.png" alt="Image for Remove all comments from your project" class="post-thumbnail__image">
</div>
</div>
<div class="l-post-description col-md-8 col-xs-12">
<div class="post-description">
<div class="post-title">
<h3 class="post-title__header">
<a class="post-title__link" href="#">Remove all comments from your project</a>
</h3>
</div>
<div class="post-meta">
<a href="#" class="post-meta__link is-first-item">
<span class="post-meta__icon fa fa-user"></span>
CROSP
</a>
<a href="#" class="post-meta__link">
<span class="post-meta__icon fa fa-calendar"></span>
June 27, 2016
</a>
<a href="#" class="post-meta__link">
<span class="post-meta__icon fa fa-comment"></span>
2
Comments
</a>
</div>
<div class="post-content">
<p class="post-content__text">
Sometimes you need to do such weird things like remove all comments from your project.
This may mean that you have reached the highest level of writing code, so no one need comments to understand written in the source files. Sometimes you need to do such weird things like remove all comments from your project.
This may mean that you have reached the highest level of writing code, so no one need comments to understand written in the source files.
</p>
</div>
<div class="post-footer">
<div class="post-categories">
<div class="post-categories__links-wrapper">
<span class="post-categories__icon fa fa-folder-open"></span>
<a href="http://crosp.net/category/software-development/regex/" class="post-categories__link is-last-item">
Regex
</a>
</div>
</div><!-- Inline block fix width
--><div class="post-more">
Read More
</div>
</div>
</div>
</div>
</article>
My CSS
/* Post module */
.l-post {
margin-bottom: 1.875em;
padding: 0 !important; }
#media only screen and (max-width: 560px) {
.l-post.post--short {
padding-right: 0;
padding-left: 0; } }
.l-post-thumbnail {
padding: 0;
margin: 0; }
/* Post content */
#media only screen and (max-width: 560px) {
#main-content {
padding: 0; } }
.l-sidebar {
margin-bottom: 2.5em; }
.l-header {
height: 90%;
width: 100%; }
#media only screen and (max-width: 560px) {
.l-header {
height: 100%; } }
#media only screen and (min-width: 1440px) {
.l-header {
height: 60%; } }
#media only screen and (min-width: 1600px) {
.l-header {
height: 40%; } }
.l-header-content {
font-size: 1.6rem;
display: table;
width: 100%;
position: relative; }
.l-header-content .header-content__wrapper {
width: 100%;
height: 100%;
display: table-cell;
vertical-align: middle; }
.l-footer {
position: relative;
padding: 3rem 0;
background-color: #081c24; }
.l-footer .social-icons {
padding-right: 1.875em;
text-align: right; }
#media only screen and (max-width: 992px) {
.l-footer .social-icons {
display: block;
margin: 2rem 0;
text-align: center; } }
.l-footer .copyright {
text-align: left; }
#media only screen and (max-width: 992px) {
.l-footer .copyright {
text-align: center;
display: block; } }
.l-blog-pagination {
text-align: center; }
.l-search-form {
width: 100%; }
.l-search-form .search-form__input {
width: 50%; }
#media only screen and (max-width: 480px) {
.l-search-form .search-form__input {
display: block;
width: 70%;
margin: 0 auto; } }
#media only screen and (max-width: 480px) {
.l-search-form .search-form__submit {
margin: 0.625em auto;
display: block; } }
/* Post module */
.post {
overflow: hidden;
background-color: #fff;
border: 1px solid #c8c8c8;
-moz-box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.19), 0 2px 10px 0 rgba(0, 0, 0, 0.19);
-webkit-box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.19), 0 2px 10px 0 rgba(0, 0, 0, 0.19);
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.19), 0 2px 10px 0 rgba(0, 0, 0, 0.19);
-webkit-transition: all 0.7s;
-moz-transition: all 0.7s;
-o-transition: all 0.7s;
transition: all 0.7s;
/* Image submodule */
/* Title submodule */
/* Content submodule */
/* Meta submodule */
/* Footer submodule */
/* Description submodule */
/* Categories submodule */
/* More submodule */
/* States */ }
.post-thumbnail {
overflow: hidden;
height: 100%; }
.post-thumbnail__image {
max-width: 150%;
width: 140%;
height: auto; }
.post-title {
display: block;
margin-bottom: 0.625em;
margin-top: 0.9375em; }
.post-title__header {
color: #52b3d9;
font-weight: 700; }
.post-title__link {
color: #337ab7; }
.post-content {
line-height: 1.4; }
.post-meta {
margin: 0.5625em 0;
color: #68c3a3; }
.post-meta__link {
white-space: nowrap;
margin-right: 0.75em;
color: #797e83; }
.post-meta__link:hover {
color: #52b3d9; }
.post-meta__icon {
font-size: 1.25em;
margin-right: 0.2em; }
.post-footer {
width: 100%;
padding: 0;
margin-top: 1.25em; }
.post-description {
padding: 0.3125em 1.5625em 1.5625em 0.625em; }
#media only screen and (max-width: 560px) {
.post-description {
padding-left: 0.3125em;
padding-right: 0.3125em; } }
.post-categories {
margin: 0;
width: 60%;
word-wrap: break-word;
vertical-align: middle;
display: inline-block; }
#media only screen and (max-width: 768px) {
.post-categories {
width: 100%;
display: block; } }
.post-categories__link {
color: #797e83; }
.post-categories__link:hover {
color: #52b3d9; }
.post-categories__link::after {
content: "/"; }
.post-categories__link.is-last-item::after {
content: ""; }
.post-categories__icon {
display: inline-block;
color: #797e83;
margin-right: 0.25em;
font-size: 1.25em; }
.post-categories__links-wrapper {
vertical-align: middle;
display: inline-block; }
.post-more {
margin: 0;
width: 40%;
display: inline-block;
text-align: right; }
#media only screen and (max-width: 768px) {
.post-more {
margin-top: 1.5rem;
width: 100%;
display: block;
text-align: center; } }
.post:hover {
-moz-box-shadow: 0 6px 15px 0 rgba(0, 0, 0, 0.19), 0 5px 17px 0 rgba(0, 0, 0, 0.19);
-webkit-box-shadow: 0 6px 15px 0 rgba(0, 0, 0, 0.19), 0 5px 17px 0 rgba(0, 0, 0, 0.19);
box-shadow: 0 6px 15px 0 rgba(0, 0, 0, 0.19), 0 5px 17px 0 rgba(0, 0, 0, 0.19); }
/* Post info module used in header mostly */
.post-info {
text-align: center;
padding: 1.25em 1.25em; }
.post-info__header {
text-align: center;
font-size: 1.375em;
color: #f7f7f7;
background-color: rgba(48, 56, 67, 0.6);
border: 1px solid #6e6e6e;
border-radius: 10px;
padding: 0.45455em 1.13636em;
display: inline-block;
-webkit-transition: all 0.7s;
-moz-transition: all 0.7s;
-o-transition: all 0.7s;
transition: all 0.7s; }
.post-info__header:hover {
border: 1px solid #52b3d9; }
#media only screen and (max-width: 560px) {
.post-info__header {
padding: 0.45455em 0.68182em; } }
.post-info__date-link {
color: #52b3d9; }
.post-info__date-link:visited, .post-info__date-link:active, .post-info__date-link:focus {
color: #52b3d9; }
.post-info__date-link:hover {
color: #68c3a3; }
.post-info__category-link {
color: #52b3d9; }
.post-info__category-link:visited, .post-info__category-link:active, .post-info__category-link:focus {
color: #52b3d9; }
.post-info__category-link:hover {
color: #68c3a3; }
You can find working example (open in fullscreen) JSFiddle
I tried to set fixed height, and set image properties to
&__image {
width: auto;
height: 100%;
}
But it produces following result. As you can see only top left part is visible.
I have only idea to make image absolute and set width and height to 120%, for instance in order to cover image. But I am not really want to make images absolute positions (get of normal flow).
Please suggest the best solution to get desired and nice looking result.
Thanks.
UPDATE
I am not big fan of bootstrap components, so I use only grid.
I am looking for pure css solution.

As you're using bootstrap, you should use bootstap's default Media object. Best solution. Check their documentation here : http://getbootstrap.com/components/#media
<div class="media">
<div class="media-left">
<a href="#">
<img class="media-object" src="..." alt="...">
</a>
</div>
<div class="media-body">
<h4 class="media-heading">Media heading</h4>
...
</div>
</div>

Not sure if you mean that you want the image to have an equal height as the text div, but I made an equalHeight function for you in jsfiddle https://jsfiddle.net/ux6k02g9/3/
let me know if this is what you mean :-)
jquery code:
$(document).ready(function(){
if ($(window).width() >= 1){
equalHeight();
}
});
$(window).resize(function(){
if ($(window).width() >= 1){
equalHeight();
}
});
function equalHeight()
{
var tallest = 0;
$('.l-post-description').each(function() {
/*if ($(this).find('.article-text').height() > tallest) {
tallest = $(this).height();
} */
if($(this).height() > tallest){
tallest = $(this).height();
}
//$(this).find('.col .item').css('min-height', tallest + 'px');
});
console.log(tallest);
$('.post-thumbnail__image').css('height', tallest + 'px');
}
$(document).ready(function(){
if ($(window).width() >= 1){
equalHeightt();
}
});
$(window).resize(function(){
if ($(window).width() >= 1){
equalHeightt();
}
});

This is best done with just CSS and as little DOM as possible.
My favorite trick is to put the after element next to the siblings, adding dipslay: flex to the parent. Now set width: 200% for both children and left: -50% for :: after.
body{
overflow-x: hidden;
}
.gradient, .gradient img {
width: 200%;
height: clamp(20rem, 70vw, 60rem);
margin: 0;
overflow: hidden;
}
.gradient{
display: flex;
}
.gradient::after{
pointer-events: none;
content: "";
height: inherit;
object-fit: cover;
width: inherit;
display: block;
background: linear-gradient(180deg, #336b25, #aa9210 41.07%, #aa2f10 76.05%);
mix-blend-mode: screen;
position: relative;
top: 0;
left: -50%;
z-index: 3;
}
<div class="gradient">
<img src="https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg"/>
</div>

Related

Invalid property value for paragraph tag with border bottom line

I have header component where active element is shown with bottom border line with padding. Here is this component with styles.
<div class="account-header">
<div class="account-header-inner">
<div v-for="item in accountHeaderItems" :key="item.title" :class="[item.active ? 'active' : '']" class="item-box">
<p :class="[item.active ? 'active' : '']" class="item" #click="changeSubpage(item)">
{{item.title}}
</p>
</div>
</div>
</div>
And styles:
.account-header {
width: 100%;
height: 50px;
display: flex;
position: absolute;
.account-header-inner {
width: 50%;
margin: 0 auto;
display: flex;
border-bottom: 1px solid v.$main-color-light;
#media only screen and (max-width: 930px) { width: 100%; }
.item-box {
height: calc(100% - 15px);
padding-top: 15px;
margin: 0 auto;
&.active { border-bottom: 3px solid v.$main-color; }
.item {
cursor: pointer;
margin: 0;
color: rgba(#fff, 0.5);
transition: .2s;
&.active { color: v.$main-color-light;}
#media screen and (max-width: 520px) { font-size: 12px; }
}
.item:hover { color: v.$main-color-light; }
}
}
}
So, on matter how and where I try to add padding bottom to active element it doesn't work and on page it looks like this:
Also, when I was trying to fix it in browser styles, it says Invalid property value.
I can't get what is wrong. It doesn't seem like I overwrite styles somewhere else in my project.
EDIT
Look how it looks like when I set padding-bottom property:
.item-box {
height: calc(100% - 15px);
padding-top: 15px;
margin: 0 auto;
&.active { border-bottom: 3px solid v.$main-color; }
.item {
cursor: pointer;
margin: 0;
color: rgba(#fff, 0.5);
transition: .2s;
&.active { color: v.$main-color-light; padding-bottom: 15px; }
#media screen and (max-width: 520px) { font-size: 12px; }
}
.item:hover { color: v.$main-color-light; }
}
You can add padding-bottom on the active class itself.
for example 5px
&.active { border-bottom: 3px solid v.$main-color; padding-bottom: 5px; }
or you can use style directive.
<div class="account-header">
<div class="account-header-inner">
<div v-for="item in accountHeaderItems" :key="item.title" :class="[item.active ? 'active' : '']" class="item-box">
<p :class="[item.active ? 'active' : '']" class="item" :style="{paddingBottom: item.active ? '5px' : 'unset' }" #click="changeSubpage(item)">
{{item.title}}
</p>
</div>
</div>
</div>

Not working show and hide accordion? where is problem

There is a "show preview" / "hide preview" button that appears in edit mode between the textarea and the preview container. This toggle allows, well, to show and hide this preview.
So of course I thought that would solve my problem, until I realize that all it does is to set a display: none on the container.
-> NOT WORKING :( WHY
.panel-item {
position: relative;
margin-top: -1px;
}
.panel-title {
cursor: pointer;
min-height: 110px;
border: 1px solid #FEE4CF;
border-radius: 6px;
padding: 15px 65px 15px 20px;
background-image: url(https://cdn.myshoptet.com/usr/www.manulo.cz/user/documents/upload/sablona/arrow-down.svg);
background-repeat: no-repeat;
background-position: right 20px center;
}
.flex-between-center {
display: flex;
align-items: center;
justify-content: space-between;
}
.panel-title > div:first-of-type {
max-width: 540px;
}
.flex-center-wrap {
display: flex;
align-items: center;
flex-wrap: wrap;
}
.in-doprava-a-platba .panel-title > div img {
margin-right: 20px;
}
img {
max-width: 100%;
height: auto;
}
.panel-body {
display: none;
padding: 0 20px 25px;
}
.type-page .content-wrapper-in ul {
list-style-type: none;
padding-left: 0;
}
.type-page .content-wrapper-in ul li {
font-size: 14px;
padding-left: 12px;
position: relative;
margin-bottom: 8px;
}
.type-page .content-wrapper-in ul li::before {
content: '';
width: 6px;
height: 6px;
display: block;
background-color: #AE6830;
border-radius: 50%;
position: absolute;
left: 0;
top: 6px;
}
.panel-show + .panel-body {
display: block;
}
#media screen and (max-width: 991px){
.panel-title {
background-size: 20px auto;
background-position: right 10px center;
padding: 15px 40px 15px 15px;
}
.panel-title > div > span, .panel-title > div > p {
font-size: 18px;
margin: 0 !important;
}
.panel-title.panel-show + .panel-body {
background-color: #FEE4CF;
display: block;
border: 1px solid #FEE4CF;
border-top: none;
border-radius: 0 0 6px 6px;
}
.panel-show + .panel-body {
display: block;
}
.panel-body {
padding: 0 20px 25px;
display: none;
}
.panel-body {
padding: 0 15px 25px;
}
}
<div class="panel-item">
<div class="panel-title flex-between-center">
<div class="flex-center-wrap"><img src="https://cdn.myshoptet.com/usr/446290.myshoptet.com/user/documents/upload/sablona/ppl.svg"> <span>PPL</span></div>
<div><span>99 Kč</span></div>
</div>
<div class="panel-body">
<ul>
<li>Když nakoupíte od 1900 Kč, máte dopravu zdarma. Jinak doručení stojí 99 Kč.</li>
<li>doručení a kontaktem na řidiče pro pohodlnější domluvu.</li>
<li>zkusí to ještě následující pracovní den. Následně váš balík uloží na nejbližší PPL zasielka.</li>
</ul>
</div>
</div>
where is problem not show and hide..
The quickest solution is
to change the .panel-title into an anchor tag <a>, making it an element that can receive focus.
and with CSS combinator selector +, the .panel-body can be toggled in/visible when the <a> loses/gets focus using the :focus pseudo selector.
I made those changes for you and added a second panel-item in <body> so you can see the accordion mechanism at work.
I also removed obsolete .panel-show references and cleaned up the #media.
Notice the two href="javascript:void(0)", without a href defined, an <a> cannot receive focus making the accordion fail to work...
Check the below snippet
/* NEW */
.panel-title {
/* To override standard <a> markup */
text-decoration: none;
color: currentColor;
}
.panel-title:focus+.panel-body {
/* make it visible */
display: block;
}
/**/
.panel-item {
position: relative;
margin-top: -1px;
}
.panel-title {
cursor: pointer;
min-height: 110px;
border: 1px solid #FEE4CF;
border-radius: 6px;
padding: 15px 65px 15px 20px;
background-image: url(https://cdn.myshoptet.com/usr/www.manulo.cz/user/documents/upload/sablona/arrow-down.svg);
background-repeat: no-repeat;
background-position: right 20px center;
}
.flex-between-center {
display: flex;
align-items: center;
justify-content: space-between;
}
.panel-title>div:first-of-type {
max-width: 540px;
}
.flex-center-wrap {
display: flex;
align-items: center;
flex-wrap: wrap;
}
.in-doprava-a-platba .panel-title>div img {
margin-right: 20px;
}
img {
max-width: 100%;
height: auto;
}
.panel-body {
display: none;
padding: 0 20px 25px;
}
.type-page .content-wrapper-in ul {
list-style-type: none;
padding-left: 0;
}
.type-page .content-wrapper-in ul li {
font-size: 14px;
padding-left: 12px;
position: relative;
margin-bottom: 8px;
}
.type-page .content-wrapper-in ul li::before {
content: '';
width: 6px;
height: 6px;
display: block;
background-color: #AE6830;
border-radius: 50%;
position: absolute;
left: 0;
top: 6px;
}
#media screen and (max-width: 991px) {
.panel-title {
background-size: 20px auto;
background-position: right 10px center;
padding: 15px 40px 15px 15px;
}
.panel-title>div>span,
.panel-title>div>p {
font-size: 18px;
margin: 0 !important;
}
/* Cleaned the clutter and removed obsolete code */
.panel-title:focus+.panel-body {
background-color: #FEE4CF;
display: block;
border: 1px solid #FEE4CF;
border-top: none;
border-radius: 0 0 6px 6px;
padding: 0 15px 25px;
}
/**/
}
<div class="panel-item">
<a class="panel-title flex-between-center" href="javascript:void(0)">
<div class="flex-center-wrap">
<img src="https://cdn.myshoptet.com/usr/446290.myshoptet.com/user/documents/upload/sablona/ppl.svg"> <span>PPL</span>
</div>
<div><span>99 Kč</span></div>
</a>
<div class="panel-body">
<ul>
<li>Když nakoupíte od 1900 Kč, máte dopravu zdarma. Jinak doručení stojí 99 Kč.</li>
<li>doručení a kontaktem na řidiče pro pohodlnější domluvu.</li>
<li>zkusí to ještě následující pracovní den. Následně váš balík uloží na nejbližší PPL zasielka.</li>
</ul>
</div>
<a class="panel-title flex-between-center" href="javascript:void(0)">
<div class="flex-center-wrap">
<img src="https://cdn.myshoptet.com/usr/446290.myshoptet.com/user/documents/upload/sablona/ppl.svg"> <span>PPL</span>
</div>
<div><span>99 Kč</span></div>
</a>
<div class="panel-body">
<ul>
<li>Když nakoupíte od 1900 Kč, máte dopravu zdarma. Jinak doručení stojí 99 Kč.</li>
<li>doručení a kontaktem na řidiče pro pohodlnější domluvu.</li>
<li>zkusí to ještě následující pracovní den. Následně váš balík uloží na nejbližší PPL zasielka.</li>
</ul>
</div>
</div>

how to create flexbox design cards with fixed footer

I'm having trouble with flexbox. I'm trying to present book cards with a fixed footer (which will contain edit / remove buttons). but the footer of each card keeps running away, and results not in the same height. I searched in google and sof and found that:
.product-modify {
margin-top: auto;
margin-bottom: auto;
}
but it does not seem to work.
I would appreciate any tips.
I USE REACT BTW. DONT LAUGH AT ME. THIS IS A CODE SNIPPET WHICH DOES NOT RUN because I could not figure out how to add react es6 to here.
Thank You for any help (:
this is my css:
<div>
<h1 className="searchResultsHeadline">Search Results:</h1>
<section className="products">
{books.map((book, index) => (
<div key={book.id} className="product-card">
<BookCard />
</div>
))}
</section>
</div>
/* Book List */
.searchResultsHeadline {
font-family: "Montserrat", sans-serif;
}
.products {
display: flex;
flex-wrap: wrap;
}
.product-card {
flex: 1 17%;
margin: 30px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
width: 40%;
min-height: 100%;
padding: 5px;
}
.product-card:hover {
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
.product-card:after {
content: "";
flex: auto;
}
.product-image img {
max-width: 100%;
border-radius: 5%;
}
.product-modify {
margin-top: auto;
margin-bottom: auto;
}
.empty-space {
height: 0 !important;
padding-top: 0 !important;
padding-bottom: 0 !important;
margin-top: 0 !important;
margin-bottom: 0 !important;
width: 130px;
height: 180px;
margin: 0 1% 24px;
}
#media (max-width: 600px) {
.product-card {
flex: 1 46%;
}
}
#media (max-width: 480px) {
.product-filter {
flex-direction: column;
}
}
Did you try a simple position:relative / position:absolute relationship like this
.product-card {
...
position:relative;
}
.product-modify {
position:absolute;
bottom:0;
}
First of all. Thank you very much for your answers.
I found out this piece of code that fixed my footer and makes it sticky footer which allways stick to the bottom:
.card-inner {
display: flex;
flex-flow: row wrap;
align-items: stretch;
}
credit for the source:
flexbox sticky footer

CSS Tablet vs Phone size

I have a row that displays the following in a browser (any size) and a phone (1440 x 2560 portrait mode):
But on a tablet (1600 x 2560 portrait mode), it displays the following:
I am able to fix it for the one, but then the other does not display as I would like.
Question
Is there a way in css to determine if I am on a phone or tablet? Or, is the a generic way I can handle this?
Thanks
html
<div class="person-job">
<ion-row class="person-job-row">
<p class="small-text-search small-text-by">by</p>
<ion-col class="col-person-avatar">
<ion-avatar item-right class="person-avatar" (click)="person(searchJobsParent.jobModel.person)">
<img [src]="getPersonAvatar(searchJobsParent.jobModel)">
</ion-avatar>
</ion-col>
<ion-col class="col-person">
<button ion-button (click)="person(searchJobsParent.jobModel.person)" color="primary" clear small>
<div *ngIf="searchJobsParent.jobModel.person" class="icon-text icon-text-displayname">{{searchJobsParent.jobModel.person.displayName}}</div>
</button>
<br>
<ion-note class="small-text-search person-last-online">
Active {{searchJobsParent.jobModel.person.lastAccessDate | amTimeAgo:true}} ago
</ion-note>
</ion-col>
</ion-row>
</div>
css
.col-person-avatar ion-avatar img {
float: left;
}
.col-person.col {
white-space: nowrap;
padding-left: 0;
}
.col {
padding: 5px;
position: relative;
width: 100%;
margin: 0;
min-height: 1px;
-webkit-flex-basis: 0;
-ms-flex-preferred-size: 0;
flex-basis: 0;
-webkit-flex-grow: 1;
-ms-flex-positive: 1;
flex-grow: 1;
max-width: 100%;
}
ion-avatar, ion-thumbnail {
display: block;
line-height: 1;
}
.contracted-content {
max-width: 369px;
margin: 0 auto;
}
Note: .contracted-content is a higher level <div> that wraps the above code.
UPADTE
I think #Kamuran Sönecek is correct, its not a media screen widt issue. The reason I say this is because the devises I test this on are: tablet: 8.40 inches 1600 x 2560 pixels and phone: 5.1-inch 2560x1440. Also when I resize the browser on my desktop, not matter what size it is, I do not get the overlapping issue seen on the tablet.
You can take a look at Media Queries / MQ Devices Your site doesn't seem to be responsive.
Desktop
Phone
Sample: Desktop / Tablet / Phone
/*-- Common --*/
* {
margin: 0;
padding: 0;
}
p {
font: normal 14px/1.4 Arial, Helvetica, sans-serif;
margin: 6px 0 0;
text-align: center;
}
.container {
text-align: center;
}
.the-device {
display: inline-block;
margin: 20px auto;
}
.edge {
background: #333;
}
.screen {
background: #fff;
position: relative;
}
/*-- Mobile --*/
.edge {
border-radius: 15px;
padding: 40px 8px 50px;
position: relative;
}
.screen:before {
border: 1px solid rgba(255, 255, 255, .3);
border-radius: 10px;
content: " ";
display: block;
height: 6px;
margin-left: -35px;
position: absolute;
top: -24px;
left: 50%;
width: 70px;
}
.screen {
height: 400px;
width: 250px;
}
.screen:after {
border: 1px solid rgba(255, 255, 255, .3);
border-radius: 10em;
content: " ";
height: 30px;
margin: 10px 0 0 -15px;
position: absolute;
left: 50%;
bottom: -41px;
width: 30px;
}
.base {
display: none;
}
/*-- Tablet --*/
#media all and (min-width: 700px) {
.edge {
padding: 50px 40px;
}
.screen {
height: 600px;
width: 450px;
}
.screen:before {
height: 10px;
margin-left: -5px;
top: -30px;
width: 10px;
}
}
/*-- Desktop --*/
#media all and (min-width: 1024px) {
.the-device {
width: 90%;
}
.edge {
padding: 3%;
}
.screen {
height: 600px;
width: auto;
}
.screen:before,
.screen:after {
display: none;
}
.base {
background: #333;
display: block;
height: 60px;
margin: 0 auto;
width: 15%;
}
.base:after {
background: #333;
border-radius: 8px 8px 0 0;
content: " ";
height: 15px;
margin: 60px 0 0 -20%;
position: absolute;
width: 40%;
}
}
<p>Resize your browser viewport to see the device change. For best results, maximize the output window.</p>
<div class="container">
<div class="the-device">
<div class="edge">
<div class="screen"></div>
</div>
<div class="base"></div>
</div>
</div>
Please use the following media queries,
#media screen and (min-width: 480px) {//Your code}
#media screen and (min-width: 768px) {//Your code}
#media screen and (min-width: 960px) {//Your code}
#media screen and (min-width: 1200px) {//Your code}
Please use CSS3 #media rule. For example:
#media screen and (min-width: 480px) {
put your styles,its works only small screen
}

Media Query not formatting correctly with Safari

I am running into a very odd situation. I believe it to be occurring in Safari, but not 100% sure. It is only happening in my 640 or less media query. What is wrong is when the device gets into that viewport (640px or less) my boxes should be 2 columns and 2 rows, just like it is doing in the jsfiddle. It is working like this mostly everywhere, except like I said in Safari, even with Chrome developer tools open with the iPhone6 responsive toolbar open the issue isn't occurring.
Click here to see it in a jsfiddle.
When the problem occurs it looks like this:
The B is moved to the 2nd row and it looks as if margin-left is being applied and my margin-right: 0 is not taking effect.
However, I have the following in the media query.
.marketing-service:nth-child(2) {
margin-right: 0;
}
.marketing-service:nth-child(3) {
margin-left: 0;
}
Does nth-child() not work in Safari?
Does anyone else know what could be happening for this to not work right for Safari?
$('#marketing-tab1').addClass('active');
$('#marketing1').show();
//For tabs to stay active
$('.marketing-service').click(function() {
$('.marketing-service.active').removeClass('active');
$(this).toggleClass('active');
//To get the service display box to show
var item_number = $(this).attr('id').replace('marketing-tab', '');
/* $('html, body').animate({
scrollTop: $("#service-display-box").offset().top
}, 1500);*/
$('#marketing'+item_number).show().siblings('.marketing-service-section').hide();
});
#marketing-services {
width: 80%;
margin: 0 10%;
}
.marketing-service {
display: inline-block;
width: 22%;
margin: 0 2%;
height: 400px;
background: #F0F0F0;
position: relative;
cursor: pointer;
}
.marketing-service:first-child {
margin-left: 0;
}
.marketing-service:last-child {
margin-right: 0;
}
.marketing-service:hover {
background: rgba(0, 255, 170, .4);
z-index: 1;
}
.marketing-service-wrap {
padding: 10%;
width: 80%;
}
.marketing-service-title {
font-size: 1.6em;
margin-bottom: 100px;
}
.marketing-img {
width: 125px;
height: 125px;
}
/*-- Down Arrow for boxes --*/
.marketing-service.active, #marketing-tab1.active {
background: rgba(0, 255, 170, .4);
}
.marketing-service.active:after, .marketing-service.active:before, #marketing-tab1.active:after, #marketing-tab1.active:before {
top: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
}
.marketing-service.active:after, #marketing-tab1.active:after {
border-width: 0px;
margin-left: 0px;
border-color: rgba(0, 255, 170, .4);
border-right-color: rgba(0, 255, 170, .4);
margin-top: -30px;
}
.marketing-service.active:before, #marketing-tab1.active:before {
border-color: transparent;
border-top-color: rgba(0, 255, 170, .4);
border-width: 36px;
margin-left: -36px;
margin-top: 0;
}
#media screen and (max-width:640px) {
/*--- Marketing Service Tabs -----*/
#marketing-services {
width: 100%;
margin: 0;
}
.marketing-service {
display: inline-block;
width: 45%;
margin: 25px 5%;
height: 250px;
}
.marketing-service:nth-child(2) {
margin-right: 0;
}
.marketing-service:nth-child(3) {
margin-left: 0;
}
.marketing-service-wrap {
padding: 5%;
width: 90%;
}
.marketing-service-title {
font-size: 1.3em;
margin-bottom: 60px;
}
.marketing-img {
width: 75px;
height: 75px;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="marketing-services">
<div class="marketing-service" id="marketing-tab1">
<div class="marketing-service-wrap total-center">
<h2 class="marketing-service-title">A</h2>
<img src="../images/marketing-seo.png" class="marketing-img">
</div>
</div><div class="marketing-service" id="marketing-tab2">
<div class="marketing-service-wrap total-center">
<h2 class="marketing-service-title">B</h2>
<img src="../images/marketing-ppc.png" class="marketing-img">
</div>
</div><div class="marketing-service" id="marketing-tab3">
<div class="marketing-service-wrap total-center">
<h2 class="marketing-service-title">C</h2>
<img src="../images/marketing-conversion.png" class="marketing-img">
</div>
</div><div class="marketing-service" id="marketing-tab4">
<div class="marketing-service-wrap total-center">
<h2 class="marketing-service-title">D</h2>
<img src="../images/marketing-email.png" class="marketing-img">
</div>
</div>
</div>