How to make a section of hr transparent - css

I'm currently designing a website based on this bootstrap theme (https://blackrockdigital.github.io/startbootstrap-freelancer/). I like what he's done with the hr styling (see code below), but I really want to use it against a background that isn't a plain colour, i.e. a background image.
The problem with this is that when changing the star icon background-color property to transparent (i.e. not the same colour as the background), the hr line still remains beneath.
Example image . If anyone can come up with a simple way of achieving the same effect against a non-plain background, I'd be really grateful!
hr.star-primary {
max-width: 250px;
margin: 25px auto 30px;
padding: 0;
text-align: center;
border: none;
border-top: solid 5px;
border-color: #2C3E50;
}
hr.star-primary:after {
font-family: FontAwesome;
font-size: 2em;
position: relative;
top: -.8em;
display: inline-block;
padding: 0 0.25em;
content: '\f005';
color: #2C3E50;
background-color: white;
}

I don't think you can do what you're asking with a single element. I would suggest creating a div with a span inside for the icon, and then using the :before and :after pseudo elements to create two horizontal lines, either side of the star.
body {
background-color: #f00;
}
.hr {
overflow: hidden;
position: relative;
text-align: center;
}
.hr::before, .hr::after {
background-color: white;
content: '';
display: inline-block;
height: 5px;
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 100%;
}
.hr::before {
left: calc(50% + 30px);
}
.hr::after {
right: calc(50% + 30px);
}
.hr .icon {
background-color: transparent;
color: white;
display: inline-block;
font-family: FontAwesome;
font-size: 2em;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="hr">
<span class="icon fa fa-star"></span>
</div>

Change pseudo element :after to :before
<link rel="stylesheet" href="https://blackrockdigital.github.io/startbootstrap-freelancer/vendor/bootstrap/css/bootstrap.min.css" type="text/css"/>
<link href="https://blackrockdigital.github.io/startbootstrap-freelancer/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<style>
hr.star-primary {
max-width: 250px;
margin: 25px auto 30px;
padding: 0;
text-align: center;
border: none;
border-top: #2C3E50 solid 5px;
color: #2C3E50
}
hr.star-primary:before {
font-family: FontAwesome;
font-size: 2em;
position: relative;
top: -.8em;
display: inline-block;
padding: 0 .25em;
content: '\f005';
color: #2C3E50
}
</style>
<hr class="star-primary" />
Sample Output
Hope this helps!

Related

CSS for custom font icon with two backgrounds

I am working on a new font icon library, and trying to get a desired result that looks like below using only CSS. I can get the single color backgrounds working with css without any issues, but trying to find the best way to do the angled second background layer in a way that will keep ratio based on the font-size used.
Here is my current wip css.
.aw-#{$app_name}:before {
content: $app_code;
}
.aw-#{$app_name}-app:before {
content: $app_code;
position: relative;
border-top-left-radius: 1.25rem;
border-top-right-radius: 1.25rem;
border-bottom-right-radius: 1.25rem;
position: relative;
}
.bg-app-black {
position: relative !important;
}
.bg-app-black:before {
position: absolute;
content: "";
display:block;
width: 5rem;
height: 5rem;
border-radius: 1.25rem;
background-color: #222;
display:inline-block;
background: -0.1rem -0.1rem 0 1.5rem #000;
transform: rotate(-20deg);
}
Here is the html:
<div class="bg-app-black"><i class="aw-actions-app bg-development-app"></i></div>
Here is the results I am getting, and it doesn't scale as the font size changes.
To do it, you need to know that em unit is equal to the computed value of the font-size property of the element on which it is used. And, by default, descendants inherit font-size.
b {
position: relative;
display:inline-block;
font-size: 3rem;
}
b:before {
content: 'N';
position: relative; z-index:1;
display: inline-flex;
font-size: .8em;
width: 1.25em;
height: 1.25em;
border-radius: .3125em .3125em .3125em 0;
margin: .33em 0 0 .33em;
color: #fff;
background: #db2828;
justify-content: center;
align-items: center;
}
b:after {
content: "";
position: absolute;
bottom: 0;
right: 0;
width: 1em;
height: 1em;
border-radius: .25em;
background: #222;
transform: rotateZ(-20deg);
transform-origin: 0 100%;
}
<b></b>
<b style="font-size:5em"></b>
<b style="font-size:24px"></b>

Center favicon in background CSS

I am currently trying to center favicons in this circular background so it can change color on hover. I am struggling a little bit to center it, though. I tried text-align: center but that was no use. Not very up to speed with CSS. What should I be doing instead?
https://codepen.io/teecp/pen/gOYRwbO
One way to solve this problem is to set fixed height and width on the parent element. Then set the icon's dimensions the same with a line height that measures its height.
body {
font-family: "Lato", sans-serif;
}
.sidebar {
height: 100%;
width: 75px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #7b68ee;
transition: 0.5s;
overflow-x: hidden;
padding-top: 60px;
white-space: nowrap;
}
.sidebar a {
position: relative;
left: 20%;
text-decoration: none;
text-align: center;
font-size: 25px;
background: red;
border-radius: 90px;
width: 20%;
color: #ffffff;
display: block;
margin-bottom: 10px;
/* Added the properties below */
height: 50px;
width: 50px;
}
main .sidebar {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
#main {
padding: 16px;
margin-left: 85px;
transition: margin-left 0.5s;
}
.sidebar .fas:hover {
background: #ffffff1a;
border-radius: 90px;
}
.sidebar-bottom {
position: absolute;
bottom: 0;
width: 100%;
margin-bottom: 4rem;
}
/* Added the block below */
.fa, .far, .fas {
font-family: "Font Awesome 5 Pro";
line-height: 50px!important;
}
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<script src="https://kit.fontawesome.com/b61e574d7a.js"></script>
<div class="sidebar">
<i class="fas fa-home"></i>
<i class="fas fa-chess-queen"></i>
<div id="main">
hello
</div>
Remove padding, add width, height and line-height.
.sidebar a {
position: relative;
left: 20%;
height: 50px;
width: 50px;
line-height: 55px;
text-decoration: none;
text-align: center;
font-size: 25px;
background: red;
border-radius: 90px;
color: #ffffff;
display: block;
margin-bottom: 10px;
}

Can't style the button using ::after & ::before in CSS

I've used the ::before and ::after elements in my CSS class to put a bottom border in my button, but that doesn't seem to work in my case.
I've positioned the ::before element tag as absolute so that the border would be inside the button, but for some reasons the border extends all the way throughout the page instead of just the button.
.mydiv {
background-color: #242128;
border-radius: 0;
height: 1000px;
width: 100%;
}
body {
margin: 0px;
}
.mybtn2 {
border: none;
font-size: 2em;
border-radius: 5px;
cursor: pointer;
color: white;
font-family: Serif;
margin-top: 50px;
margin-left: 5%;
background-color: #242128;
padding: 5px 10px;
}
.mybtn2::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-bottom: 2px solid white;
}
<body>
<div class="mydiv">
<button class="mybtn2">Hover Me</button>
</div>
</body>
You need position: relative; on .mybtn2.

New Div acting weird? Not showing Up?

Okay guys so I have created multiple div classes, and they seem to work. But when I want to add another div class underneath them, it just doesn't show up.
Here's my html code;
<!DOCTYPE html>
<html>
<head>
<!--LINKING THE STYLESHEETS-->
<link rel="stylesheet" type="text/css" href="style.css">
<!--DO NOT EDIT THIS STYLE SHEET-->
<link rel="stylesheet" type="text/css" href="reset.css">
<style>
html, body {min-width: 600px; background-image: url(bg.jpg);}
/*Navigation Bar*/
ul
{
list-style-type:none;
margin:0;
padding:0;
background-image: url(nav_bg.png); background-repeat: repeat;
border-style: solid;
border-color: #fff;
width: 50em;
height: 50px;
margin-left: auto;
margin-right: auto;
}
ul.nav {
margin-left: auto;
margin-right: auto;
margin-top: 1em;
width: 80%;
text-align: center;
border-style: solid;
border-color: #fff;
border-width: 2px;
}
li
{
display:inline;
text-align: center;
margin: 30px;
}
.nav a {
line-height:50px;
}
#font-face {
font-family: corbel;
src: url('fonts/corbel.ttf');
}
#font-face {
font-family: orator;
src: url('fonts/OratorStd.otf');
}
/*CUSTOMIZING THE LINKS*/
a {
color: #fff;
text-decoration: none;
font-family: corbel;
font-size: 18px;
}
a:visited {
color: #fff;
}
a:active {
color: #fff;
}
a:hover {
color: #111;
}
/*THE CONTAINERS*/
.box-long {
width: 80%;
height: 100px;
border-style: solid;
border-color: #fff;
border-width: 2px;
margin-left: auto;
margin-right: auto;
margin-top: 1em;
}
.box-half-long {
width: 39.4%;
height: 100px;
border-style: solid;
border-color: #fff;
border-width: 2px;
margin-left: 9.9%;
margin-top: 1em;
float: left;
}
.box-half-long-r {
width: 39.4%;
height: 100px;
border-style: solid;
border-color: #fff;
border-width: 2px;
margin-left: 50.5%;
margin-top: 1em;
}
/*Keeping images in containers even when browser resizes. */
img {
width: 100%;
height: 100%;
}
/*styling headers*/
h1.center {
text-align: center;
line-height: 110px;
font-size: 30px;
color: #fff;
font-family: orator;
}
h2.center {
text-align: center;
line-height: 110px;
font-size: 30px;
color: #fff;
font-family: orator;
}
</style>
</head>
<body>
<ul class="nav">
<li>Home</li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
<div class="box-long">
<h1 class="center">SERVER BANNER HERE</h1>
<!--YOU COULD AD AN IMAGE HERE. REMOVE THIS COMMENT AND DELETE THE <H1> TAGS TO SEE
IT WORKING WITH AN IMAGE. IMAGE SIZE IS -->
<!-- REMOVE ME FOR IMAGE // <img src="server_banner.jpg"> // -->
</div>
<div class="box-half-long">
<h2 class="center">SUB-CAT 1</h2>
</div>
<div class="box-half-long-r">
<h2 class="center">SUB-CAT 2</h2>
</div>
</body>
</html>
Here's the site this code is on: here
So, when I go ahead and add a new div class at the end, for example, this; (p.s, yes I know the div hasn't been set up in css, this is just a demonstation..)
.box-newdiv{
width: 80%;
height: 100px;
border-style: solid;
border-color: #fff;
border-width: 2px;
margin-left: auto;
margin-right: auto;
margin-top: 1em;
}
It just doesn't show up?
EDIT: Link is now working to view.
The reason you can't see the new div's is because you have provided fixed height for the div having the classes named as "box-half-long" and "box-half-long-r".
.box-half-long-r {
width: 39.4%;
height: 100px;
border-style: solid;
border-color: #fff;
border-width: 2px;
margin-left: 50.5%;
margin-top: 1em;
}
.box-half-long {
width: 39.4%;
height: 100px;
border-style: solid;
border-color: #fff;
border-width: 2px;
margin-left: 9.9%;
margin-top: 1em;
float: left;
}
Since they have a fixed height, they don't show the elements contained in them which lie below the height of 100px.
Let the height 'adapt' to the height of the containing elements. You can do this by:
height :auto;
Just change these classes to:
.box-half-long-r {
width: 39.4%;
height: auto;
border-style: solid;
border-color: #fff;
border-width: 2px;
margin-left: 50.5%;
margin-top: 1em;
}
.box-half-long {
width: 39.4%;
height: auto;
border-style: solid;
border-color: #fff;
border-width: 2px;
margin-left: 9.9%;
margin-top: 1em;
float: left;
}
I have added new div's to show that they can be displayed once you change the hieght to auto.
Just see here : http://jsfiddle.net/Bj3vr/
Hope this helps you to understand the concept of using "height as auto" and solves your issue.
I can't see the example but first thing I noticed is
.box-long {
height: 100px;
This could be why
EDIT:
Works for me: http://jsfiddle.net/4rhAz/

How to get hovering shadow under a letter with CSS-only?

I would like to reproduce the following logo, add a shadow below one letter as in the using only CSS.
How to do it as box-shadow overflow on both side of the letter ? I would prefer to avoid having an extra <span class="shadow"></span> following my "hovering" letter but manage it only with the letter tag/CSS rule (see HTML below).
N.B.: I'm aware of jQuery / CSS3 Animated shadow effect.
HTML
<span>Pr<span class="text-info">o</span>be</span>
CSS
element.style {
box-shadow: 0 4px 3px #AAAAAA;
position: relative;
top: -3px;
}
Using pseudo-elements (:before and :after), :hover and opacity properties, the solution looks like the following (it can be extended w/animation effects on opacity)
HTML
<div class="text-effects"><span>Pr<span class="text-info">o</span>be</span></div>
CSS
body {
font-size: 10em;
font-family: Arial;
}
div.text-effects {
text-transform:uppercase;
}
span.text-info {
position: relative;
cursor:pointer;
}
.text-info:hover {
color: #008080;
bottom: 0.1em;
}
span.text-info:before {
content: ".";
color: transparent;
position: absolute;
width: 40%;
box-shadow: 0 5px 4px -4px #303030;
display: block;
left: 30%;
bottom: 1em;
opacity:0;
}
span.text-info:after {
content: ".";
color: transparent;
position: absolute;
bottom: 0;
width: 40%;
box-shadow: 0 5px 4px -4px #303030;
display: block;
left: 30%;
bottom:0.15em;
opacity:0;
}
span.text-info:hover:before{
opacity:1;
}
span.text-info:hover:after{
opacity:1;
}
Technique
I had to use pseudo-element as described by #Alex Bell.
But instead of box-shadow I use text-shadow and tweak the pseudo-element position.
pseudo-element text is ˍ aka U+02CD MODIFIER LETTER LOW MACRON (ˍ or \u02CD)
Final result is available as a fiddle.
HTML
<div class="text-effects">
<span>Pr<span class="text-info">o</span>be</span>
</div>
CSS
body {
font-size: 10em;
font-family: Arial;
}
div.text-effects {
text-transform:uppercase;
}
span.text-info {
position: relative;
color: #008080;
bottom: 0.1em;
width: 1em;
height: 1em;
}
span.text-info:after {
bottom: 0.15em;
color: transparent;
content: "ˍ";
display: block;
font-size: 120px !important;
height: 1em;
left: 26%;
position: absolute;
text-shadow: 0 0 11px #999;
width: 1em;
}

Resources