I am trying to use :before and :after elements to spice up my page, but when I push it, the live site does not have them. On my local computer, both :before and :after is showing up correctly. My live site is here: https://findingfutures.eu
I am using Netlify and Github to push my site. I have tried adding the code to a codepen, and the elements are being displayed correctly there: https://codepen.io/Barsnes/pen/pKBzrK
Here is my code, with a lot of removed content to make it simpler,
.products_design:before {
content: " ";
display: block;
width: 70%;
height: .3em;
position: absolute;
background: #FFF;
top: -16.5em;
margin-left: 15%;
box-shadow: 0 0 20px #00000040;
}
.products_design:after {
content: " ";
display: block;
width: 70%;
height: .3em;
position: absolute;
background: #FFF;
bottom: -10.5em;
margin-left: 15%;
box-shadow: 0 0 20px #00000040;
}
.products_design {
position: relative;
height: auto;
width: 80vw;
margin: 25em 10vw 10em 10vw;
display: inline-block;
box-shadow: 0 0 30px #00000030;
background: linear-gradient(to top right, #23232320, #23232305);
}
.products_design h1 {
display: block;
position: absolute;
top: -2em;
line-height: .8em;
text-transform: uppercase;
text-shadow: 0 0 10px #00000060;
}
.products_design span {
display: block;
}
.products_design img {
width: 100%;
height: auto;
padding: 0;
margin: 0;
}
.project_1,
.project_2,
.project_3,
.project_4,
.project_5,
.project_6 {
width: 33.33%;
float: left;
padding: 0;
margin: 0;
position: relative;
display: block;
}
.products_design h2 {
font-size: 1.8em;
padding: .4em .4em 0 .2em;
}
.products_design p {
padding: .4em .4em 2em .4em;
font-size: 1em;
margin-bottom: 3em;
}
.products_design a {
display: block;
color: orange;
margin: auto;
position: relative;
text-decoration: none;
}
.products_design a:hover {
text-shadow: 0 0 10px #000;
color: #FFFFFF
}
<div class="products_design">
<div class="products">
<div class="products_title">
<h1>our past<span>projects</span></h1>
</div>
</div>
<div class="project_1">
<img src="images/projects/project__tobias_barsnes_website.png" />
<h2>Portfolio Website</h2>
<p>LoremClick to view project</p>
</div>
<div class="project_2">
<img src="images/projects/project__portrait_photography.png">
<h2>Portrait Photography</h2>
<p>LoremClick to view project</p>
</div>
<div class="project_3">
<img src="https://source.unsplash.com/1920x1080/?photoshop">
<h2>Design</h2>
<p>LoremClick to view project</p>
</div>
</div>
Pseudo elements does not work well with #import, and can therefor cause problems in the browser.
If you move all your ::before and ::after to the main css wihtout using #import, it should work perfectly.
Correct Example Code
#import url("_styles/header.css");
#import url("_styles/body.css");
.products_design::before {
content: " ";
display: block;
width: 70%;
height: 5px;
position: absolute;
background: #FFF;
top: -16.5em;
margin-left: 15%;
box-shadow: 0 0 20px #00000040;
}
.products_design::after {
content: " ";
display: block;
width: 70%;
height: 5px;
position: absolute;
background: #FFF;
bottom: -10.5em;
margin-left: 15%;
box-shadow: 0 0 20px #00000040;
}
.about_images::before {
content:" ";
display: block;
width: 50%;
margin-left: 25%;
height: 5px;
background: #FFF;
position: absolute;
top: -13em;
box-shadow: 0 0 20px #00000040
}
Wrong Example Code
#import url("_styles/media_query.css");
#import url("_styles/cookie.css");
#import url("_styles/pseudeo_elements.css");
It's ::before and ::after.
For some environments selectors may work with a single :, but it's not the proper syntax in CSS3.
Update:
:before and ::before will both work, as CSS3 is backwards compatible with CSS2, as CBroe pointed out.
Related
I am trying to dash after border in H tag using :after and :before it's working fine on desktop & android devices but create issue in IOS devices
border made using :after and :before but text of h element doesn't display
below is a demo of other devices
below is a demo of IOS devices
h2.service-heading {
font-size: 36px;
color: #762d2f;
text-transform: uppercase;
position: relative;
display: table;
margin-left: auto;
margin-right: auto;
max-width: calc(100% - 36px);
position: relative;
}
h2.service-heading::after {
content: '';
position: absolute;
width: calc(100% - 5px);
display: block;
height: 6px;
border-bottom: 6px solid #762d2f;
z-index: 9999;
clear: both;
left: 0;
bottom: 0px;
}
h2.service-heading::before {
content: '';
position: absolute;
width: 10px;
display: block;
height: 6px;
border-bottom: 6px solid #762d2f;
z-index: 9999;
clear: both;
bottom: 0px;
right: -10px
}
<h2 class="service-heading" align="center"> Our Services</h2>
Can anyone help with this
Thanks in advance
You don't need to pseudo element for that. Can be made easily with only background.
h2.service-heading {
font-size: 36px;
color: #762d2f;
text-transform: uppercase;
display: table;
margin-left: auto;
margin-right: auto;
max-width: calc(100% - 36px);
padding-right: 15px;
background: linear-gradient(#762d2f, #762d2f) 0 100% / calc(100% - 15px) 6px no-repeat,
linear-gradient(#762d2f, #762d2f) 100% 100% / 10px 6px no-repeat;
}
<h2 class="service-heading" align="center"> Our Services</h2>
Also can be used some CSS variables to control everything easily.
h2.service-heading {
--border-height: 6px;
--second-border-width: 20px;
--border-gap: 10px;
font-size: 36px;
color: #762d2f;
text-transform: uppercase;
display: table;
margin-left: auto;
margin-right: auto;
max-width: calc(100% - 36px);
padding-bottom: 5px; /* bottom distance of border */
padding-right: calc(var(--second-border-width) + var(--border-gap));
background: linear-gradient(#762d2f, #762d2f) 0 100% / calc(100% - (var(--second-border-width) + var(--border-gap))) var(--border-height) no-repeat,
linear-gradient(#762d2f, #762d2f) 100% 100% / var(--second-border-width) var(--border-height) no-repeat;
}
<h2 class="service-heading" align="center"> Our Services</h2>
I had the similar problem: dropdown-arrow for menu item performed as pseudoclass ::after didn't work for IOS. enter image description here
Next code snippet I utilized for SASS:
.nav-link {
border-top: 1px solid var(--color-white);
color: var(--color-white);
font-size: 18px;
line-height: 22px;
font-weight: 400;
text-decoration: none;
padding: 10px 15px 10px 0;
&::after {
content: " ";
border: none;
background-image: var(--arrow-down);
background-position: center center;
background-repeat: no-repeat;
width: 40px;
height: 20px;
}
}
so the solution was to remove arrows from pseudoclass ::after and perform it as a background image for menu item, like next:
.nav-link {
display: block;
border-top: 1px solid var(--color-white);
color: var(--color-white);
font-size: 18px;
line-height: 22px;
font-weight: 400;
text-decoration: none;
padding: 10px 15px 10px 0;
background-image: var(--arrow-down);
background-position: 98%;
background-repeat: no-repeat;
background: var(--arrow-down) no-repeat 98%;
&::after {
display: none;
}
}
I've noticed that IOS14.4 and lower doesn't support background-image, and older versions IOS are needed only full form background not just background-image:
background: var(--arrow-down) no-repeat 98%;
I have a "small" issue on my website with Firefox. On Google Chrome and Safari it is working just fine.
What it should be (Chrome and Safari):
Issue on Firefox:
.headline {
line-height: 1.5em;
position: relative;
}
.headline:after {
content: ' ';
position: absolute;
display: block;
width: 230px;
margin: 5px 2%;
border: 2px solid #64c800;
border-radius: 4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
left: 50%;
transform: translateX(-50%);
}
<h2><span class="headline">Contact</span></h2>
The expected result is that the green line should be below the header (in this case below "Contact".
Reproducible code:
Important forgotten note; I use Bootstrap 4 too.
<style>
#wrapper {
position: relative;
margin: 25px auto 5px auto;
max-width: 820px;
min-height: 600px;
padding: 1px 0px 30px 0px;
background-color: #ffffff;
color: #603813;
text-align: center;
}
.headline {
line-height: 1.5em;
position: relative;
}
.headline:after {
content: ' ';
position: absolute;
display: block;
width: 230px;
margin: 5px 2%;
border: 2px solid #64c800;
border-radius: 4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
left: 50%;
transform: translateX(-50%);
}
</style>
<div class="container-fluid">
<div class="row-fluid">
<div id="wrapper">
<div class="row">
<div class="col-md-12">
<h2><span class="headline">Contact</span></h2>
</div>
</div>
</div>
</div>
I think the problem is that you don't define a vertical position (top or bottom) for your line, so the browser kinda just does anything.
Try adding
.headline:after {
top: 100%;
}
JSFiddle: https://jsfiddle.net/0p7948Lx/2/
I can't reproduce your issue in Firefox 60.8 on Debian. However, here is a somewhat simplified approach that works without position, transform and border. I find it a little more elegant.
Maybe it fixes the issue as well?
h2 {
width: 230px;
text-align: center;
}
.headline {
line-height: 1.5em;
}
.headline:after {
content: '';
display: block;
width: 100%;
height: 8px;
margin-top: 1em;
background: #64c800;
border-radius: 4px;
}
<h2><span class="headline">Contact</span></h2>
I have a text in the middle of the div block with a font size 80px. When I hover on the div block, it will change the border size from 1px to 5px with a blue color but the text will moves down.
.calendar-content {
width: 81%;
display: block;
padding: 0;
background: #fff;
float: left;
position: relative;
margin-bottom: 150px;
}
.calendarday-container {
width: 139px;
height: 139px;
float: left;
position: relative;
margin-top: -1px;
margin-left: -1px;
border: 1px solid #ccc;
}
.calendarday-add .calendarday-number {
display: inline-block;
width: 100%;
font-size: 80px;
color: #f1f1f1;
margin: 12px 0px;
text-align: center;
}
.calendarday-number:hover {
margin: 12px 2px;
}
.calendarday-container:hover {
border: 5px solid #2e7ad1;
}
.add-day-ico {
display: none;
width: 21px;
height: 21px;
margin: 22px 0px;
float: right;
}
.calendarday-container:hover .add-day-ico {
display: block;
margin: 22px 0px;
}
<div class="calendarday-container" data-day="0" data-dropable="true">
<a href="/autoresponder/create_day.php?day=0" data-action="click" class="calendarday-add">
<span class="calendarday-number">0</span>
<img src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png" sytle="height: 21px; width: 21px;" align="right" style="margin-top: 3px;" class="add-day-ico">
</a>
</div>
Jsfiddle: http://jsfiddle.net/f0k6r9nb/
I have tried to change the margin in the calendarday-container:hover .add-day-ico but it didn't help to resolve the issue.
Can you please show me an example how I can stop the text moving down on hover?
Thank you.
Changing the width of the border from 1px to 5px and recalculating the inner parts is not a practical solution. You could use an additional element, which has 5px of transparent border and change it to 5px of colored border on hover.
Another simple solution would be to use outline instead, as it doesn't add to the elements dimensions:
.calendar-content {
width: 81%;
display: block;
padding: 0;
background: #fff;
float: left;
position: relative;
margin-bottom: 150px;
}
.calendarday-container {
width: 139px;
height: 139px;
float: left;
position: relative;
margin-top: -1px;
margin-left: -1px;
border: 1px solid #ccc;
}
.calendarday-container:hover {
outline: 5px solid #2e7ad1;
}
.calendarday-add .calendarday-number {
display: inline-block;
width: 100%;
font-size: 80px;
color: #f1f1f1;
margin: 12px 0px;
text-align: center;
}
.add-day-ico {
opacity: 0;
width: 21px;
height: 21px;
position: absolute;
bottom: 0;
right: 0;
}
.calendarday-container:hover img {
opacity: 1;
}
<div class="calendarday-container" data-day="0" data-dropable="true">
<a href="/autoresponder/create_day.php?day=0" data-action="click" class="calendarday-add">
<span class="calendarday-number">0</span>
<img src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png" class="add-day-ico">
</a>
</div>
A typical approach to showing a border on hover is to have the non-hover state be transparent or a color that matches the background along with the width matching that of the border when hovered.
In this case, there's an existing 1px border. Here, I would change the gray border blue, then use an inset box-shadow to add the additional 4px of the border.
Note: I also removed some margin for .calendarday-number on hover so the number does not shift.
.calendar-content {
width: 81%;
display: block;
padding: 0;
background: #fff;
float: left;
position: relative;
margin-bottom: 150px;
}
.calendarday-container {
width: 139px;
height: 139px;
float: left;
position: relative;
margin-top: -1px;
margin-left: -1px;
border: 1px solid #ccc;
}
.calendarday-add .calendarday-number {
display: inline-block;
width: 100%;
font-size: 80px;
color: #f1f1f1;
margin: 12px 0px;
text-align: center;
}
/*
.calendarday-number:hover {
margin: 12px 2px;
}
*/
.calendarday-container:hover {
border-color: #2e7ad1;
box-shadow: inset 0 0 0 4px #2e7ad1;
}
.add-day-ico {
display: none;
width: 21px;
height: 21px;
margin: 22px 0px;
float: right;
}
.calendarday-container:hover .add-day-ico {
display: block;
margin: 22px 0px;
}
<div class="calendarday-container" data-day="0" data-dropable="true">
<a href="/autoresponder/create_day.php?day=0" data-action="click" class="calendarday-add">
<span class="calendarday-number">0</span>
<img src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png" sytle="height: 21px; width: 21px;" align="right" style="margin-top: 3px;" class="add-day-ico">
</a>
</div>
Add this:
.calendarday-container {
border: 5px solid transparent;
outline: 1px solid #ccc;
outline: none;
}
.calendarday-container:hover {
outline: none;
}
Remove this:
.calendarday-number:hover {
margin: 12px 2px;
}
You can use a pseudo element like this. I also removed lot of unnecessary css that was fighting each other
* { margin: 0; padding: 0; box-sizing: border-box; }
body { margin: 5%; }
/* Normal */
.calendarday-container {
width: 150px; height: 150px;
position: relative;
display: flex; align-items: center; justify-content: center;
}
.calendarday-container:after {
content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0;
border: 1px solid #ccc; z-index: -1;
}
.caldndarday-add { text-decoration: none; }
.calendarday-number { font-size: 80px; color: #ccc; }
.add-day-ico { width: 24px; height: 24px; position: absolute; bottom: -8px; right: -8px; }
/* Hover FX */
.calendarday-container:hover:after { border: 10px solid navy; }
.calendarday-container:hover .calendarday-number { color: navy; }
<div class="calendarday-container" data-day="0" data-dropable="true">
<a class="caldndarday-add" href="/autoresponder/create_day.php?day=0" data-action="click">
<span class="calendarday-number">0</span>
<img class="add-day-ico" src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png">
</a>
</div>
The text was moving down because, There was increase in border-width from 1px to 5px while hover.
You can either maintain a outline around the box using outline property, and keeping the border: 5px solid transparent to border: 5px solid #2e7ad1 while hovering.
I've created a working fiddle for you, for better understanding: Link to Jsfiddle
i have an issue with floating div's in responsive template. You can see empty spaces on images below. And it happens not at every page, at some pages blocks fill all space properly.
Here is the code of a simple block:
<div class="movie-item ignore-select short-movie">
<div class="movie-img img-box">
<img src="/templates/movie-groovie/dleimages/no_image.jpg" alt="text" />
<i class="fa fa-info show-desc"></i>
<div class="movie-img-inner">
<i class="fa fa-play-circle-o go-watch pseudo-link" data-link="#"></i>
</div>
<div class="movie-series">Поле зеленое</div>
<span>доп поле</span>
</div>
<a class="movie-title" href="#">TITLE</a>
<div class="movie-tags nowrap">Some text</div>
<div class="movie-desc">
<div class="movie-date">2 март 2017</div>
<div class="movie-director"><b>Доп поле название:</b> доп поле Джеймс Кэмерон</div>
<div class="movie-text">Some text</div>
<div class="movie-rate"><i class="fa fa-thumbs-o-up"></i><span id="ratig-layer-5846" class="ignore-select"><span class="ratingtypeplus ignore-select" >0</span></span></div>
</div>
</div>
and it's styles:
.short-movie {
float: left;
width: 18%;
margin: 0 1% 20px 1%;
}
styles.css:146
.movie-item {
position: relative;
z-index: 50;
margin: 0 10px;
max-width: 200px;
}
.movie-img {
height: 210px;
z-index: 50;
border: 4px solid #fff;
box-shadow: 0 0 0 1px #e3e3e3;
border-radius: 2px;
}
styles.css:6
.img-box {
overflow: hidden;
position: relative;
}
.fa {
display: inline-block;
font: normal normal normal 14px/1 FontAwesome;
font-size: inherit;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
styles.css:155
.show-desc {
position: absolute;
right: 0;
top: 0;
z-index: 150;
font-size: 18px !important;
cursor: pointer;
border-radius: 0 0 0 3px;
background-color: #fff;
color: #487a1b;
width: 30px;
height: 30px;
line-height: 30px !important;
text-align: center;
}
.movie-img-inner {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 100;
border: 5px solid #97ce68;
opacity: 0;
background-color: rgba(0,0,0,0.6);
}
.movie-series {
position: absolute;
left: 0;
bottom: 0;
z-index: 50;
width: 100%;
background-color: rgba(151, 206, 104, 0.8);
color: #487a1b;
padding: 10px;
font-weight: 700;
text-align: center;
}
.movie-title {
display: block;
margin: 10px 0 3px 0;
height: 36px;
overflow: hidden;
color: #333;
}
.movie-desc {
position: absolute;
left: 100%;
top: 0;
z-index: 150;
width: 400px;
padding: 20px;
background-color: #FFF;
display: none;
box-shadow: 0 0 15px 0 rgba(0,0,0,0.3);
min-height: 80px;
border-radius: 4px;
}
I can't find what causes the problem. Tried it on OS X Chrome and Safari. Does anybody know what can it be?
Just set:
.short-movie {
height: 275px;
}
To make all movie items be of the same height and stop them being affected by the previous elements height.
Set standard height for this div, For Example
.img-box
{
height:300px;
}
I have the following. However, I've been trying to get the blue title area to expand with the outter div and the arrow to be aligned in the middle. I have an outer div set at 25% just so the text wraps.
.breakingNewsRec {
width: 100%;
background: #FFF;
position: relative;
border: solid 2px #6A7791;
}
.breakingNewsRec>.bn-rec {
width: auto;
display: inline-block;
background: #6A7791;
position: relative;
margin-right: 20px;
}
.breakingNewsRec>.bn-rec>h2 {
display: inline-block;
margin: 0;
padding: 0 20px;
line-height: 40px;
font-size: 0.8em;
color: #FFF;
box-sizing: border-box;
}
.breakingNewsRec>.bn-rec>span {
position: absolute;
right: -10px;
top: 10px;
height: 0;
border-style: solid;
border-width: 10px 0 10px 10px;
border-color: transparent transparent transparent #6A7791;
}
.breakingNewsTown {
width: 100%;
height: 40px;
background: #FFF;
position: relative;
border: solid 2px #74936A;
}
.breakingNewsTown>.bn-rec {
width: auto;
height: 40px;
display: inline-block;
background: #74936A;
position: relative;
margin-right: 20px;
}
.breakingNewsTown>.bn-rec>h2 {
display: inline-block;
margin: 0;
padding: 0 20px;
line-height: 40px;
font-size: 0.8em;
color: #FFF;
height: 40px;
box-sizing: border-box;
}
.breakingNewsTown>.bn-rec>span {
width: 0;
position: absolute;
right: -10px;
top: 10px;
height: 0;
border-style: solid;
border-width: 10px 0 10px 10px;
border-color: transparent transparent transparent #74936A;
}
<div style="width: 25%">
<div class="breakingNewsRec">
<div class="bn-rec">
<h2>Recreation News</h2><span></span>
</div>fdsasdf asdif ksd jfkasjdfasj dfla sjdflj
<img src="imgs/slides/slide2.jpg" width="25%">asdfljas dflkjsdf alskdjf asdfl</div>
<div class="breakingNewsTown">
<div class="bn-rec">
<h2>Town News</h2><span></span>
</div>fareveae vasev</div>
</div>
Using display:table-cell this is very easy to accomplish:
#news {
width: 50%;
}
#news .item {
border-width: 1px;
border-style: solid;
}
#news .item h2 {
color: white;
font-size: 100%;
white-space: nowrap;
position: relative;
border-color: inherit;
}
#news .item h2:after {
content: '';
display: inline-block;
border-style: solid;
border-width: 10px 0 10px 10px;
border-color: transparent;
border-left-color: inherit;
vertical-align: middle;
position: absolute;
left: 100%;
}
#news .item h2,
#news .item div {
display: table-cell;
vertical-align: middle;
padding: 0 1.5em;
}
.style1 { border-color: #697791 }
.style1 h2 { background: #697791 }
.style2 { border-color: #74936a }
.style2 h2 { background: #74936a }
<div id="news">
<div class="item style1">
<h2>Recreation News</h2>
<div>
<p>fdsasdf asdif ksd jfkasjdfasj dfla sjdflj asdfljas dflkjsdf alskdjf asdfl</p>
</div>
</div>
<div class="item style2">
<h2>Town News</h2>
<div>
<p>fareveae vasev</p>
</div>
</div>
</div>
I am not sure exactly what you are trying to achieve, but it sounds like something like this:
which would just be applying width:100%; to .bn-rec
EDIT
Regarding your comment - I think I understand then. How about surrounding the text in a <div> and making both <div> tags display:inline-block; and restricting their width by %. Then increasing the margin of the arrow, also by a % like I did here:
https://jsfiddle.net/030y329m/
Is that closer to what you were thinking?