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

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>

Related

2 lines of text. 1st line can have max 2 lines. Bottom needs to ALWAYS be on second line, wrapped behind line 1. CSS only solution please

I have this HTML
<div class="link">
<i class="icon" />
<div class="text-wrapper">
<span class="label">Some label which can span at most 2 lines</span>
<span class="subtext">(optional)</span>
</div>
</div>
One way of displaying is:
Notice how the label wraps to the second line while the subtext is trailing behind it.
The other way of display is:
Notice how the label here is not long enough to wrap, but the subtext is still on the second line.
Can anyone suggest how I can achieve the above with HTML/CSS only? Feel free to ignore the icon in the solution. I have that already. Thanks in advance.
The code I have so far...
.link {
position: relative;
font-size: 0.875rem;
padding-left: 26px;
text-align: left;
line-height: 1.25rem;
}
.icon {
padding: 0;
width: 18px;
height: 18px;
font-size: 18px;
border-radius: 50%;
transform: translateY(2px);
position: absolute;
top: 0;
left: 0;
}
.label {
margin-right: 4px;
color: #007dbb;
}
.subtext { color: #686868; }
Set the first span as display: block; (see css for label-element). That will display the first span as a block element, forcing the second span to begin on a new line.
.link {
position: relative;
font-size: 0.875rem;
padding-left: 26px;
text-align: left;
line-height: 1.25rem;
}
.icon {
padding: 0;
width: 18px;
height: 18px;
font-size: 18px;
border-radius: 50%;
transform: translateY(2px);
position: absolute;
top: 0;
left: 0;
}
.label {
display: block;
margin-right: 4px;
color: #007dbb;
}
.subtext { color: #686868; }
<div class="link">
<i class="icon">Icon</i>
<div class="text-wrapper">
<span class="label">Some label which can span at most 2 lines</span>
<span class="subtext">(optional)</span>
</div>
</div>
Instead of having two separate span for title and subtitle. You can have one parent for title and add subtitle span inside it.
.link {
display: flex;
flex-direction: row;
}
.link i {
margin-right: 10px;
}
.text-wrapper {
display: flex;
width: 175px;
}
.text-wrapper p {
margin-top: 0;
}
.text-wrapper .subtitle {
color: blue;
font-style: italic;
}
<div class="link">
<i class="icon">Icon</i>
<div class="text-wrapper">
<p class="title">Some label which can span at most 2 lines
<span class="subtitle">(optional)</span>
</p>
</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 do I center each element with the element above it? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have attached the HTML and CSS I have so far but I am new to front end so I'm not sure what the best approach is.
I just want each text element to be aligned with the respective numbers underneath them.
h1 {
font-family: 'Biryani', sans-serif;
font-size: 20px;
font-weight: bold;
text-align: center;
padding: 50px;
}
ul {
text-align: justify;
}
ul:after {
content: '';
display: inline-block;
width: 100%;
}
ul:before {
content: '';
display: block;
margin-top: 0em;
}
li1 {
font-family: 'Biryani', sans-serif;
font-size: 14px;
font-weight: light;
color: #929292;
display: inline-block;
margin-left: 10em;
margin-right: 13em;
position: relative;
top: 1.25em;
}
li2 {
font-family: 'Biryani', sans-serif;
font-size: 16px;
font-weight: light;
color: #929292;
display: inline-block;
margin-left: 10em;
margin-right: 13em;
position: relative;
top: 1.25em;
}
<!DOCTYPE HTML>
<html>
<head>
<title> REALSURF</title>
<link rel="stylesheet" type="text/css" href="realsurfcss.css">
<link href="https://fonts.googleapis.com/css?family=Biryani:300,400,800" rel="stylesheet">
</head>
<body>
<h1>
REALSURF
</h1>
<ul>
<li1>Wind</li1>
<li1>Wave Height</li1>
<li1>Tide</li1>
</ul>
<ul>
<li2>6</li2>
<li2>3-4</li2>
<li2>1.8^</li2>
</ul>
</body>
</html>
Simply, wrap each columns of elements in the same block and set it's property text-align to center in CSS.
Here is an approach using CSS's flex (https://css-tricks.com/snippets/css/a-guide-to-flexbox/)
.container {
display: flex;
width: 100%;
}
.column {
text-align: center;
flex-grow: 1;
}
<div class="container">
<div class="column">Text<br />Number</div>
<div class="column">Text<br />Number</div>
<div class="column">Text<br />Number</div>
</div>
You can also do that with tables, take a look:
table {
width: 100%;
}
td {
text-align: center;
}
<table>
<tr>
<td>Text<br/>Number</td>
<td>Text<br/>Number</td>
<td>Text<br/>Number</td>
</tr>
</table>
You asked about styling of each rows, all you need to do is wrap each row in each element like below:
.container {
display: flex;
width: 100%;
}
.column {
text-align: center;
flex-grow: 1;
}
.text {
font-weight: bold;
font-family: Helvetica;
color: red;
}
.number {
font-size: 18px;
margin-top: 16px;
color: green;
}
<div class="container">
<div class="column">
<div class="text">Text</div>
<div class="number">Number</div>
</div>
<div class="column">
<div class="text">Text</div>
<div class="number">Number</div>
</div>
<div class="column">
<div class="text">Text</div>
<div class="number">Number</div>
</div>
</div>
Easiest with Ruby annotations, but it'll only work in more modern browsers:
body {
font-size: 30px;
}
<ruby>
5<rp>(</rp><rt>text</rt><rp>)</rp>
</ruby>
<ruby>
1-2<rp>(</rp><rt>text</rt><rp>)</rp>
</ruby>
<ruby>
8<rp>(</rp><rt>text</rt><rp>)</rp>
</ruby>
using pseudo element after JSFiddle
li{
display: inline-block;
padding: 0 20px;
font-size: 50px;
position: relative;
line-height: 90px;
}
li:before{
content: 'text';
position: absolute;
left: 0;
right: 0;
top: 0;
margin: auto;
font-size: 12px;
line-height: 12px;
text-align: center;
}

CSS prevents links from acting like links

I'm just getting started on HTML5 and CSS3 (working through The Odin Project) and the first project is to duplicate the Google homepage. I was able to get everything set up, but it seems like my CSS is somehow preventing my header links from acting like links. You can't click on them and the hover effects don't work.
They work fine on my footer and my nav text-decoration is applied, so I'm not sure what's making it act like it's not a link. I've only tested it in Chrome, so I'm not even worried about compatability issues yet. Am I doing the HTML5 wrong? Or is it some kind of weird rule like you can't use hover effects with inline-block or something? I'm not familiar enough with it yet to have learned all those nuances yet...
Here's the HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Google</title>
<link rel="stylesheet" href="style.css">
<link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
</head>
<body>
<nav>
<ul>
<li>+Mara</li>
<li>Gmail</li>
<li>Images</li>
<li><img src="images/options.png" width="35px"></li>
<li><img src="images/bell.png" width="35px"></li>
<li><img src="images/plus.png" width="35px"></li>
<li><img src="images/photo.jpg" width="40px" class="rounded_img"></li>
</ul>
</nav>
<div class="container">
<img class="logo" src="https://www.google.com/images/srpr/logo11w.png" width="320px"/>
<center><form action="#" method="post" name="google_search_form">
<input type="search" name="googlesearch" class="search"><br/><br/>
<input type="submit" value="Google Search" class="button">
<input type="submit" value="I'm Feeling Lucky" class="button">
</form></center>
</div> <!--End container-->
<footer>
<ul>
<span class="left"><li>Advertising</li></span>
<span class="left"><li>Business</li></span>
<span class="left"><li>About</li></span>
<span class="right"><li>Settings</li></span>
<span class="right"><li>Terms</li></span>
<span class="right"><li>Privacy</li></span>
</ul>
</footer>
</body>
</html>
And the CSS:
.container{
position: relative;
vertical-align: middle;
}
.logo {
display: block;
margin-left: auto;
margin-right: auto;
padding-top: 270px;
clear: right;
}
.search {
width: 650px;
height: 35px;
margin-top: 40px;
font-size: 27px;
background: url('images/voice.gif') 97% 50% no-repeat;
opacity:0.6;
background-size: 17px;
border: blue solid 1px;
}
.button {
font-family: Helvetica, Roboto, sans-serif;
font-weight: bold;
color: black;
background: #f2f2f2;
border: #d6d6d6 solid 1px;
border-radius: 2px;
width: 140px;
height: 40px;
}
nav {
width: 600px;
height: 30px;
font-size: 1em;
font-family: Helvetica, Roboto, sans-serif;
font-weight: lighter;
text-align: center;
position: relative;
float: right;
}
nav ul {
height: auto;
padding: 0;
margin: 0;
}
nav li {
display: inline-block;
padding: 10px;
vertical-align: middle;
}
.atext {
text-decoration: none;
color: black;
}
.atext: hover {
text-decoration: underline;
background-color: yellow;
}
.aicon {
opacity: 0.6;
}
.aicon:hover {
opacity: 1.0;
}
footer {
width: 102%;
height: 40px;
left: -20px;
right: -20px;
font-size: 1em;
font-family: Arial, sans-serif;
position: absolute;
bottom: 0;
background: #f2f2f2;
border: #d6d6d6 solid 1px;
}
footer ul {
height: auto;
padding: 0;
margin: 0;
}
footer li {
display: table-cell;
padding: 10px;
vertical-align: middle;
}
footer li a {
text-decoration: none;
color: gray;
}
.left {
float: left;
margin-left: 20px;
}
.right {
float: right;
margin-right: 20px;
}
.rounded_img {
border-radius: 20px;
}
Any help will be greatly appreciated. Thanks!
Oh, and I haven't even started on JavaScript yet, so I'd like to avoid JavaScript if possible!
Here is a fiddle: http://jsfiddle.net/Lvfmwhvu/
The problem is your container element, if you remove the position relative it will work, but not sure if it will be maintained in the same position, but you can check it and modify your css accordingly:
.container{
vertical-align: middle;
}
Hope this helps.
Your main container isn't clearing the floated navbar. Because it falls later in your document, it has a higher layer index and covers the navbar. Try this:
.container {
...
clear: both;
}
Demo

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

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>