I have a div with a pseudo :after element creating a circle after it. How can I add something else inside that circle? - html

I have a CSS circle appearing after a div using the :after pseudo class. I need to insert an arrow inside of that circle, just like this. My problem is putting anything inside the circle. Since I already used :after to create the circle, how can I add something else inside of that?
I need the circle to be pure CSS, but the arrow can be an image.
Here is my code:
http://jsfiddle.net/s7crao4b/
<div id="callus-phone">
<div class="tagline">Call us today!</div>
<div class="phone-number">1 (800) 555-5555</div>
</div>
#callus-phone {
color: white;
background: black;
padding: 25px 0px;
text-align: center;
}
.phone-number {
padding-bottom: 10px;
}
#callus-phone:after {
background: red;
border-radius: 50px;
content: "";
display: block;
height: 50px;
margin: auto;
width: 50px;
}

you can use Unicode character \25B6 in content
#callus-phone {
color: white;
background: black;
padding: 25px 0px;
text-align: center;
}
.phone-number {
padding-bottom: 10px;
}
#callus-phone:after {
background: red;
border-radius: 50px;
content: "\25B6";
display: block;
line-height: 50px;
height: 50px;
margin: auto;
width: 50px;
font-size: 22px
}
<div id="callus-phone">
<div class="tagline">Call us today!</div>
<div class="phone-number">1 (800) 555-5555</div>
</div>

You can achieve the same result using only CSS with Font Awesome. It does not use the :after you are referring to, but again, its pure CSS, if you don't want to include the font awesome library, you could study their CSS and see how they do it, and go from there to implement your own icon with the :after
In my example, I added a bunch of positioning, and font sizing to try to center the arrow to the best of my abilities, but you can disregard that if you want.
I hope this is helpful.
#callus-phone {
color: white;
background: black;
padding: 25px 0px;
text-align: center;
}
.phone-number {
padding-bottom: 10px;
}
.fa-circle {
color: red;
}
.fa-caret-right {
color: white;
left: 2px !important;
top: -2px !important;
position: relative;
font-size: 40px !important;
}
.fa-stack {
font-size: 30px;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<div id="callus-phone">
<div class="tagline">Call us today!</div>
<div class="phone-number">1 (800) 555-5555</div>
<span class="fa-stack fa-2x">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-caret-right fa-stack-1x fa-inverse"></i>
</span>
</div>
After seeing Vitorino Fernandes answer, I wanted to tell you that if you need to stick to the usage of the :after, but if you want a fancier character instead of an ugly character, you can use the code below. You dont need a reference to the Font Awesome CSS library, but you need to include the reference to their icons in your own CSS. (Or you can just include their CSS link tag in your HTML and forget about the #font-face that I added in your CSS).
#callus-phone {
color: white;
background: black;
padding: 25px 0px;
text-align: center;
}
.phone-number {
padding-bottom: 10px;
}
#callus-phone:after {
background: red;
border-radius: 50px;
content: " \f095";
display: block;
height: 50px;
margin: auto;
width: 50px;
font: normal normal normal 14px/1 FontAwesome;
font-size:45px;
text-rendering: auto;
}
#font-face {
font-family: 'FontAwesome';
src: url('//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/fonts/fontawesome-webfont.eot?v=4.2.0');
src: url('//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/fontawesome-webfont.eot?#iefix&v=4.2.0') format('embedded-opentype'), url('//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/fonts/fontawesome-webfont.woff?v=4.2.0') format('woff'), url('//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/fonts/fontawesome-webfont.ttf?v=4.2.0') format('truetype'), url('//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/fonts/fontawesome-webfont.svg?v=4.2.0#fontawesomeregular') format('svg');
font-weight: normal;
font-style: normal;
}
<div id="callus-phone">
<div class="tagline">Call us today!</div>
<div class="phone-number">1 (800) 555-5555</div>
</div>

Related

Css font not changing correctly or aligning to the center

I am trying to change the font-family of my tab and align the text to the center using "font-family" and "text-align" but it isn't working. Here is my code and the image. As you can see the font is not Roboto and the text "Chat" is not aligned properly.
<style>
div#olark_tab{
position: fixed;
right: 0;
bottom:50%;
z-index:5000;
}
#olark_tab div{
width: 150px;
margin-right: -59px;
transform: rotate(-90deg);
}
#olark_tab a{
/*Edit these to change the look of your tab*/
background-color: #DCDCDC;
color: #1EAFE6;
font-family: 'Roboto';
font-style: normal;
font-weight: bold;
font-size: 20px;
line-height: 20px;
height: 20px;
padding: 6px;
display: block;
text-decoration: none;
text-align: center;
width: auto;
border-top-right-radius:9px;
border-top-left-radius:9px;
border-top-style: none;
border-top-width: 0;
}
#olark_tab a:hover{
background-color: white;
}
</style>
<div id="olark_tab">
<div>
<a href="javascript:void(0);" onclick="olark('api.box.expand')">
<img src="icon-chat.svg">
Chat
</a>
</div>
</div>
For the font, the font-family declaration works if you try an already-included font, like Arial or Times New Roman. I don't believe Roboto is a default font that you can just include. Have you imported it from somewhere like Google Fonts?
For the text centering: I'm not entirely sure what you mean by "not aligned properly," but it is centered in your example. Both the "Chat" text and the SVG icon are part of the centered element (the <a> tag), so it's those two elements together being centered within the box. (The same distance extends from the "t" to the top and from the edge of the speech bubble to the bottom.) Depending on how you actually want it to be aligned, you may need to target the text or image and align them individually.
The Roboto font is not supported by css and is only available through google. I have added the code to get the font from google and display it in on the tab.
HTML
<style>
div#olark_tab{
position: fixed;
right: 0;
bottom:50%;
z-index:5000;
}
#olark_tab div{
width: 150px;
margin-right: -59px;
transform: rotate(-90deg);
}
#olark_tab a{
/*Edit these to change the look of your tab*/
<link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
background-color: #DCDCDC;
color: #1EAFE6;
font-family: 'Roboto', sans-serif;
font-style: normal;
font-weight: bold;
font-size: 20px;
line-height: 20px;
height: 20px;
padding: 6px;
display: block;
text-decoration: none;
text-align: center;
width: auto;
border-top-right-radius:9px;
border-top-left-radius:9px;
border-top-style: none;
border-top-width: 0;
}
#olark_tab a:hover{
background-color: white;
}
</style>
<div id="olark_tab">
<div>
<a href="javascript:void(0);" onclick="olark('api.box.expand')">
<img src="icon-chat.svg">
Chat
</a>
</div>
</div>
make your image smaller
div#olark_tab {
position: fixed;
right: 0;
bottom: 50%;
z-index: 5000;
}
#olark_tab div {
width: 150px;
margin-right: -59px;
transform: rotate(-90deg);
}
/* changes */
#olark_tab img{
width: 50%;/* or :75%; make it the much you want */
}
/* changes */
#olark_tab a {
/*Edit these to change the look of your tab*/
background-color: #DCDCDC;
color: #1EAFE6;
font-family: 'Roboto';
font-style: normal;
font-weight: bold;
font-size: 20px;
line-height: 20px;
height: 20px;
padding: 6px;
display: block;
text-decoration: none;
text-align: center;
width: auto;
border-top-right-radius: 9px;
border-top-left-radius: 9px;
border-top-style: none;
border-top-width: 0;
}
#olark_tab a:hover {
background-color: white;
}
<div id="olark_tab">
<div>
<a href="javascript:void(0);" onclick="olark('api.box.expand')">
<img src="icon-chat.svg"> Chat
</a>
</div>
</div>

How to create link in content element

I have been tasked with creating this.
I can create the box, font-awesome icon and the non-linking text using a pseudo element content, but I am unable to create the Learn More link (with a span class to include the >).
If I add text directly into the html, it will not fill the box (and spills out below it). I would also be forced to use inline styles to keep it top-aligned with the !.
We want to keep this in the CSS if at all possible. I realize that the real answer is that you can't do it, but I'm looking for a workaround to make it work.
This is the CSS I can use to place the non-linking message:
&:after {
color: #7b7b7b;
margin-top: -43px;
padding-left: 19%;
line-height: 18px;
display: flex;
font-weight: normal;
content: "You are no longer on FPC, you will now be back to your regular contract.";
#media #{$small} {
padding-left: 15%;
margin-top:-37px;
}
}
&:before {
color: #7b7b7b;
margin-left: 10px;
}
And this is the line of HTML:
<i class="fa fa-exclamation-circle"></i>; Learn more <span class="arrow-right"></span>
Does anyone have a solution to help me make this work?
Thanks
Here is a different structure & CSS if you end up going in that direction.
.message {
border: 2px solid #7b7b7b;
border-radius: 2px;
position: relative;
width: 220px;
font-size: 13px;
font-family: Arial;
background: #f7fcff;
padding: 7px 8px 5px 42px;
}
.message>.message-icon {
position: absolute;
color: #7b7b7b;
font-size: 26px;
left: 10px;
}
p {
color: #7b7b7b;
margin: 0 0 3px 0;
}
a {
color: #1464ae;
font-size: 12px;
text-decoration: none;
}
a .action-icon {
margin-left: 3px;
font-size: 10px;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="message">
<span class="message-icon"><i class="fa fa-exclamation-circle"></i></span>
<p>You are no longer on FPC, you will now be back to your regular contract.</p>
<a href="">Learn More
<span class="action-icon"><i class="fa fa-chevron-right"></i></span>
</a>
</div>

How can I make a line after a heading with font awesome icon in the middle?

Am trying to do the same as the photo shows but I don't really know how to do that
So I should be able to have that line with any fontawesome icon in the middle.
Here my initial markup:
<h1>Welcome</h1>
h1 {
font-size: 25pt;
display: inline-block;
margin: 0;
font-weight: 300;
}
h1:after {
content: '\f209';
font-family: FontAwesome;
display: block;
}
Here my fiddle
Hope you can help.
By giving your h1 a border-bottom and positioning your :after icon absolute in the center inside it. Also apply a white background to make sure the line gets interrupted.
h1 {
font-size: 25pt;
display: inline-block;
margin: 0;
font-weight: 300;
padding-bottom: 10px;
border-bottom: 1px solid #000;
}
h1:after {
content: '\f209';
position: absolute;
font-family: FontAwesome;
background-color: #FFF;
display: block;
margin-left: 50px;
}
Update fiddle
Well... the accepted answer works fine, but it involves set widths, and will need to be rewritten to cater for longer text in the heading. The following works regardless of width of text (it does, however, involve a little bit more HTML):
https://jsfiddle.net/jx4dv11g/3/
h1 {
font-size: 25pt;
margin: 0 auto;
font-weight: 300;
padding-bottom: 10px;
border-bottom: 1px solid #000;
text-align: center;
display: inline-block;
}
.headericon {
display: inline-block;
position: absolute;
}
.headericon i {
display: block;
margin-top: -25%;
background: white;
transform: translate(-50%,0);
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
<h1>Welcome to this page<br><span class="headericon"><i class="fa fa-hand-peace-o"></i></span></h1>
I'll suggest you to use following HTML structure for this:
<h1 class="styled-heading">
Welcome to HTML and CSS
<span class="fa fa-hand-peace-o"></span>
</h1>
Apply a class on h1 and use pseudo elements :before and :after to draw lines around icon.
This will allow you to have one time generic styling for all similar places in your web page. If you wants to use different icon in some other heading then all you need is just change the font awesome icon in that header.
body {
text-align: center;
margin: 0;
}
.styled-heading {
text-align: center;
font-size: 25pt;
display: inline-block;
margin: 0;
font-weight: 300;
position: relative;
overflow: hidden;
}
.styled-heading .fa {
display: block;
margin: 0 auto;
}
.styled-heading:before,
.styled-heading:after {
position: absolute;
background: black;
margin-left: 30px;
width: 999px;
height: 1px;
content: '';
bottom: 12px;
left: 50%;
}
.styled-heading:after {
margin-right: 30px;
margin-left: 0;
right: 50%;
left: auto;
}
.orange {
background: orange;
}
.green {
background: green;
}
.blue {
background: blue;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
<h1 class="styled-heading">
Welcome to HTML and CSS
<span class="fa fa-hand-peace-o"></span>
</h1>
<div class="orange">
<h1 class="styled-heading">
Welcome To HTML and CSS.
<span class="fa fa-home"></span>
</h1>
</div>
<div class="blue">
<h1 class="styled-heading">
Welcome To HTML and CSS.
<span class="fa fa-globe"></span>
</h1>
</div>
<div class="green">
<h1 class="styled-heading">
Welcome To HTML and CSS.
<span class="fa fa-power-off"></span>
</h1>
</div>

Font awesome, same icon with different width

I have a little problem with Font Awesome icon.
I have 2 same versions of website (for development and tests) and the icon displays differently while having same CSS styles.
I described this problem with this icon:
.btnFilter {
color: #666666;
padding-top: 4px;
font-size: 18px;
text-align: center;
}
.circle {
border: solid #999 1px;
border-radius: 13px;
box-sizing: border-box;
width: 26px;
height: 26px;
text-align: center;
font-size: 18px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<i class="fa fa-times circle btnFilter"></i>
This CSS and HTML markup is placed on both dev and test versions, chrome dev tools displays same styles, and hovering font-awesome icon :before pseudoelement's size gives result as on the image above.
I think you would be better served by using em rather than px values here...then everything adjusts to the font size.
As to your specific issue, there is a clash between line-height/font-size in font-awesome and your specific styles.
The top padding is also probably not required.
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
margin: 0;
padding: 0;
}
.btnFilter {
color: #666666;
font-size: 160px !important;
/* for demo only */
line-height: 1em;
text-align: center;
}
.fa::before {
line-height: inherit;
}
.circle {
border: solid #999 1px;
border-radius: 50%;
width: 1.1em;
height: 1.1em;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />
<i class="fa fa-times circle btnFilter"></i>
Codepen Demo
I believe it has to do with the font-size. I think its because font-awesome has a declaration of
font: normal normal normal 14px/1 FontAwesome;
So remove the font-size or adjust your font-size using em and it should work as expected
if you add !important to your font-size you will see the weird result that you see on one of your sites.
.btnFilter {
color: #666666;
padding-top: 4px;
font-size: 18px !important;
text-align: center;
}
.circle {
border: solid #999 1px;
border-radius: 13px;
box-sizing: border-box;
width: 26px;
height: 26px;
text-align: center;
font-size: 18px !important;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<i class="fa fa-times circle btnFilter"></i>
Or you could do this
.circle{
width:18px;
height:18px;
padding: 3px;
background-color:white;
border-radius:100%;
line-height:18px;
text-align:center;
vertical-align:middle;
display:inline-block;
border: solid #999 1px;
}
.btnFilter {
line-height: inherit;
font-size: 18px;
color: #666666;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="circle">
<i class="fa fa-times btnFilter"></i>
</div>

HTML/CSS css boxes and positioning

I have a CSS greybox: (When I say greybox, I mean the CSS box I have created that I have made with the color grey as you can see down below.)
.navigation-div
{
margin-top: 14px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.47);
padding: 0;
color: #E3E3E3;
background-color: #333;
}
This greybox is inside of my header and since this greybox is bigger than it appears, it goes past the header image but doesn't appear.
With this:
<div class="navigation-bar">
<a class="navigation-div-blur">
<div class="navigation-div">
<nav class="navigation">
<img id="mailpicture" src="images/gmail.png">
<h1 id="mailtext">Mail Us</h1>
<h1 id="nava">test</h1>
</nav>
</div>
</a>
</div>
The picture and Mail Us show in the correct position not exposing the box. The test however, when I put it in exposes the box.
Here is the CSS I have behind this
#mailtext
{
margin-top: 20px;
display: inline-block;
margin-left: 1230px;
font-size: 20px;
color: white;
font-style: italic;
}
#mailpicture
{
display: inline-block;
margin-top: 16px;
float: right;
}
#nava
{
font-size: 20px;
color: white;
font-weight: bold;
font-style: italic;
margin-top: 20px;
display: inline-block;
margin-left: 500px;
}
You already saw the box for CSS.
I would like to accomplish either one of two things: Make the CSS box smaller and lower it, or have the CSS correctly position the test along with more elements to stay in the same line as the Mail Us.
NOTE: I have tried for the test margin-top:-pixels, this does not go up high enough and stops going up after a while.
This is what it looks like with the test:
This is what it looks like without the test:
As you can notice the first one has a larger box that drops down beneath the header picture. The one without the test has stayed in the header's picture.
There are a few problems with your code.
First, you should not nest anchors (<a>) in other anchor elements.
Using margin to position elements is not a good idea, you are already trying to use inline-block to change default block display of headers and at the same time you are floating one of your inline-block elements to the right.
Adding big margin to the element makes the element use more space and moves next inline element to the new line if it cannot fit in one line with other elements.
If you want to position all your menu items to the right you can use text- align:right on your inline-block elements to stick them to the right.
If you want your mail element be on the right you may stick to using float:right on it, but it would also be easier to just place mail element as the last one in the nav
You can nest anchors <a> inside headers <h1> to create links inside headers
<h1 id="mailtext">Mail Us <img id="mailpicture" src="images/gmail.png"></h1>
http://jsbin.com/kazocekoba/1/
.navigation-div
{
margin-top: 14px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.47);
padding: 0;
color: #E3E3E3;
background-color: #333;
text-align: right;
}
#mailtext
{
margin-top: 20px;
display: inline-block;
/* margin-left: 1230px;*/
font-size: 20px;
color: white;
font-style: italic;
}
#mailpicture
{
display: inline-block;
margin-top: 16px;
float: right;
}
#nava
{
font-size: 20px;
color: white;
font-weight: bold;
font-style: italic;
margin-top: 20px;
display: inline-block;
/*margin-left: 500px;*/
}
/* use padding to separate your navigation elements */
.navigation > * {
padding-left: 2em;
}
<div class="navigation-bar">
<a class="navigation-div-blur">
<div class="navigation-div">
<nav class="navigation">
<!-- --><img id="mailpicture" src="images/gmail.png">
<h1 id="mailtext">Mail Us</h1>
<h1 id="nava">test</h1>
</nav>
</div>
</a>
</div>
A bit better solution http://jsbin.com/xunokaviju/1/
.navigation-div
{
margin-top: 14px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.47);
padding: 0;
color: #E3E3E3;
background-color: #333;
text-align: right;
}
#mailtext
{
margin-top: 20px;
display: inline-block;
/* margin-left: 1230px;*/
font-size: 20px;
color: white;
font-style: italic;
}
#mailpicture
{
display: inline-block;
margin-top: 16px;
/*float: right;*/
}
#nava
{
font-size: 20px;
color: white;
font-weight: bold;
font-style: italic;
margin-top: 20px;
display: inline-block;
/*margin-left: 500px;*/
}
/* use padding to pad elements */
.navigation > * {
padding-left: 1em;
}
<div class="navigation-bar">
<a class="navigation-div-blur">
<div class="navigation-div">
<nav class="navigation">
<!-- -->
<h1 id="nava">test</h1>
<h1 id="mailtext">Mail Us <img id="mailpicture" src="images/gmail.png"> </h1>
</nav>
</div>
</a>
</div>
In #mailtext the margin-left:1230 is the problem. Keeping your code just as it is the only change you'll have to make looks like this:
#mailtext
{
float: right;
font-size: 20px;
color: white;
font-style: italic;
}
change your
#mailtext
{
margin-top: 20px;
display: inline-block;
margin-left: 1230px;
font-size: 20px;
color: white;
font-style: italic;
}
to
#mailtext
{
margin-top: 20px;
display: inline-block;
float:right;
font-size: 20px;
color: white;
font-style: italic;
}
Hope it solves your problem