how to add padding top in CSS pseudo element class::after - css

I want to add padding top to ::after and want to make it centered.
But it's not happening, this is what I get :
After using this css :
.list-unstyled li::after {
content: url(images/heartborder.png)
text-align:center;
padding-top: 30px;
}
and this is my HTML CODE :
<li>
<div class="col span-1-of-3 box">
<span class="icon-small">
<i class="fa fa-eye" aria-hidden="true"></i>
<div class="details">
<h5 class="heading">View / Edit Profile</h5>
<p>You can view or edit your profile from here. Phone no., address, other information etc. etc.</p>
</div>
</span>
</div>
</li>

Your :after is set by default to display: inline so padding has no effect on it. Change it to inline-block or block and then it will.
To center it (as requested in comments), use flex on the div as below:
div {
width: 50px;
height: 50px;
background: green;
display: flex;
justify-content: center;
}
div:after {
content: "";
width: 20px;
height: 20px;
background: blue;
display: inline-block;
padding-top: 5px;
}
<div></div>

you need to add semicolon after content: url(images/heartborder.png) attribute
OR
I think you need to do like this:
.list-unstyled li::after {
content: url(images/heartborder.png);
text-align: center;
padding-top: 30px;
}

Use display:block or display:inline-block to apply padding or margin. add margin:0 auto to get center.
.list-unstyled li::after {
content: url(images/heartborder.png) 0 0 no-repeat;
text-align: center;
padding-top: 30px;
display: block;
margin: 0 auto;
}
<li>
<div class="col span-1-of-3 box">
<span class="icon-small">
<i class="fa fa-eye" aria-hidden="true"></i>
<div class="details">
<h5 class="heading">View / Edit Profile</h5>
<p>You can view or edit your profile from here. Phone no., address, other information etc. etc.</p>
</div>
</span>
</div>
</li>

Related

Responsive content with font-awsome and VueJs 3

I want to change the style of my component to fit the content,
My component Plan.vue:
<template>
<div class="plan">
<div id="planFlex">
<font-awesome-icon icon="fa-solid fa-user fa-xl" />
<font-awesome-icon icon="fa-solid fa-arrow-left fa-xl" />
<h1>Plan</h1>
<font-awesome-icon icon="fa-solid fa-arrow-right fa-xl" />
<font-awesome-icon icon="fa-solid fa-robot fa-xl" />
</div>
</div>
</template>
<script>
export default {
name: "Plan"
};
</script>
<style>
#import "../css/Plan.css";
</style>
my stylesheet Plan.css:
#planFlex {
display: flex;
justify-content: space-between;
padding: 5px;
}
.fa-user {
color: white;
}
.fa-robot {
color: white;
}
.fa-arrow-right {
color: white;
position: relative;
padding-left: 80px;
}
.fa-arrow-left {
color: white;
padding-right: 80px;
}
#planFlex h1 {
text-align: center;
margin: 0px;
color: antiquewhite;
}
#planFlex h1:hover {
cursor: pointer;
}
#planFlex h2 {
margin: 0px;
padding-left: 3%;
color: white;
}
I have tried to add flex-shrink: 1, and width: fit-content to my stylesheet, but it didn't work well with me, can you please tell me how can I make my design responsive? thanks in advance.
The problem is with .plan outer div which by default will display as block, making your #planFlex stretch to its borders.
If you add the following you should find that #planFlex will just be the width of your content:
.plan {
display: flex;
justify-content: center;
}
In your specific case, you should consider removing the 80px padding on your arrow icons and let flex do the spacing for you. Assuming you want the icons to stick to the sides and your title right in the middle, just wrapped them around in some div, that did the trick for me running your project:
<div id="planFlex">
<div>
<i class="fa-solid fa-user fa-xl"></i>
<i class="fa-solid fa-arrow-left fa-xl"></i>
</div>
<h1 #click="addPopUp(testPopup, `Lego not in the right place`)">Plan</h1>
<div>
<i class="fa-solid fa-arrow-right fa-xl"></i>
<i class="fa-solid fa-robot fa-xl"></i>
</div>
</div>

How to display navigation elements in the same line with toggle button?

So, I got a homework from school to create a landing page, of our own design. I thought to have an overlay menu and besides the toggle button, to have three icons within the navbar (2 for social media and one for user account).
I have the below HTML and CSS code that allows me to use an image as a toggle button for an overlay menu which works fine:
HTML
<header>
<ul class="social">
<li>
<img src="/images/facebook.svg" alt="">
</li>
</ul>
MyWebSite
<img src="/images/menu.svg" alt="" class="menu-btn" id="open-menu">
</header>
CSS
header {
padding: 2em;
.logo {
font-weight: bold;
margin-left: 7em;
}
.menu-btn {
float: right;
cursor: pointer;
width: 35px;
margin-right: 7em;
}
.social {
display: flex;
float: right;
list-style: none;
}
}
Also, I would like to add the icons in front of the toggle menu button. However, what I am getting now using the above code is as you can see in the print screen below which is not the expected results:
Current results
What I would to obtain though is as is shown in the below print screen:
Expected results
Could anyone give me a hint? I'd appreciate it. Thanks
You can use flexbox to create desired layout.
Example
header {
background-color: #ee4;
padding: 20px 40px;
display: flex;
justify-content: space-between;
align-items: center;
}
header h1 {
margin: 0;
}
.social-icons-container {
display: flex;
align-items: center;
}
.social-icons-container i {
font-size: 20px;
padding: 0 0 0 30px;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<header>
<h1>Logo</h1>
<div class="social-icons-container">
<i class="fab fa-facebook"></i>
<i class="fab fa-instagram"></i>
<i class="fas fa-user-alt"></i>
<i class="fas fa-bars"></i>
</div>
</header>

Center images while maintaining responsive design

I'd like to push the three icons below towards the center of the page while still retaining a responsive layout.
Is display: grid; or display: row; more suitable?
And depending on your answer, what are the cleanest properties to apply?
<html>
<div id="contact">
<h1>Let's connect.</h1>
<div id="image-holder">
<div id="github-div">
<a href="https://github.com/klin-nj-97" target="_blank" id="profile-link">
<img src="https://image.flaticon.com/icons/svg/25/25231.svg" alt="github" class="contact-img">
</a>
</div>
<div id="linkedin-div">
<a href="https://www.linkedin.com/in/kevin-lin-33085a133/" target="_blank">
<img src="http://simpleicon.com/wp-content/uploads/linkedin.png" alt="linkedin" class="contact-img">
</a>
</div>
<div id="email-div">
<a href="mailto:kevin_lin#brown.edu">
<img src="https://image.freepik.com/free-icon/email-envelope-outline-shape-with-rounded-corners_318-49938.jpg" alt="email" class="contact-img">
</a>
</div>
</div>
</div>
</html>
<style>
#contact h1 {
text-align: center;
padding-top: 75px;
padding-bottom: 55px;
}
#image-holder {
display: flex;
flex-flow: row;
margin-left:
}
#contact a{
color: white;
}
.contact-img {
height: 35px;
width: 35px;
padding: 30px;
border-radius: 15px;
border: 2px solid black;
}
</style>
You should be use this simple trick.
Please give align-items: center; justify-content: center; into #image-holder
For more details Go to display:flex
Hope this help.
Let me know further clarifications.
#contact h1 {
text-align: center;
padding-top: 75px;
padding-bottom: 55px;
}
#image-holder {
display: flex;
flex-flow: row;
align-items: center;
justify-content: center;
}
#contact a{
color: white;
}
.contact-img {
height: 35px;
width: 35px;
padding: 30px;
border-radius: 15px;
border: 2px solid black;
}
<html>
<div id="contact">
<h1>Let's connect.</h1>
<div id="image-holder">
<div id="github-div">
<a href="https://github.com/klin-nj-97" target="_blank" id="profile-link">
<img src="https://image.flaticon.com/icons/svg/25/25231.svg" alt="github" class="contact-img">
</a>
</div>
<div id="linkedin-div">
<a href="https://www.linkedin.com/in/kevin-lin-33085a133/" target="_blank">
<img src="http://simpleicon.com/wp-content/uploads/linkedin.png" alt="linkedin" class="contact-img">
</a>
</div>
<div id="email-div">
<a href="mailto:kevin_lin#brown.edu">
<img src="https://image.freepik.com/free-icon/email-envelope-outline-shape-with-rounded-corners_318-49938.jpg" alt="email" class="contact-img">
</a>
</div>
</div>
</div>
</html>
Add the property justify-content: center; to the #image-holder id.
The buttons will be centered.
Code below
JSFiddle
The cleanest way to do this is to:
Use class-based selectors instead of ID selectors
Use flexbox to centre the layout (and text) horizontally, and centre the layout vertically
I've changed your HTML to use class-based selectors instead of IDs, e.g. class="contact" instead of id="contact":
<div class="contact">
<h1 class="contact__title">Let's connect.</h1>
<div class="contact__images">
<a class="contact__link" href="https://github.com/klin-nj-97" target="_blank">
<img src="https://image.flaticon.com/icons/svg/25/25231.svg" alt="github" class="contact__icon">
</a>
<a class="contact__link" href="https://www.linkedin.com/in/kevin-lin-33085a133/" target="_blank">
<img src="http://simpleicon.com/wp-content/uploads/linkedin.png" alt="linkedin" class="contact__icon">
</a>
<a class="contact__link" href="mailto:kevin_lin#brown.edu">
<img src="https://image.freepik.com/free-icon/email-envelope-outline-shape-with-rounded-corners_318-49938.jpg" alt="email" class="contact__icon">
</a>
</div>
</div>
For the cleanest CSS, it's ideal that all your selectors have the same level of specificity, and the best way to do that is use only class-based selectors. This will let you override styles more easily. You can read more about CSS specificity here.
The following CSS uses flexbox to position your content accordingly, assuming you are trying to centre everything vertically within the page:
body {
margin: 0; /* browser adds margins by default */
}
.contact {
display: flex;
flex-direction: column;
justify-content: center; /* centers your content horizontally */
align-items: center; /* centers your content vertically */
height: 100vh;
}
.contact__title {
margin: 0 0 55px; /* if you have a header you'd like to account for, the first value can be the header height */
}
.contact__images {
/* you don't even need anything here but the wrapping div of this classname is required to keep your icons aligned */
}
.contact__link {
text-decoration: none; /* proper way to hide the text link underline */
}
.contact__icon {
height: 35px;
width: 35px;
padding: 30px;
border-radius: 15px;
border: 2px solid black;
}
The CSS class naming convention I used is called BEM. I recommend reading more about it if you are interested in writing clean CSS. You can do so here or here.
I have a working example here on CodePen. You can change the height of the page to see it's centred vertically.

How to centralize second element inline relative to parent?

I'm trying make a layout for mobile application.
How do I centralize the title label relative to parent?
Here's my HTML:
<div id="title">
<i class="fa fa-th-large" id="menuButton"></i>
<small class="title">PROFILE</small>
</div>
See in jsBIN
try to add margin to title, like this:
#title{
margin: 0 auto;
}
Do u mean you want to centralize the text inside ? If so, try this code:
#title {
text-align: center;
}
Centering the Profile only:
HTML:
<div id="title">
<div id="icon">
<i class="fa fa-th-large" id="menuButton"></i>
</div>
<div id="text">
<small class="title">PROFILE</small>
</div>
</div>
CSS:
#title {
background: #13A3B5;
padding: 10px 5%;
font-size: 2em;
overflow: hidden;
}
#icon {
float: left;
width: 5%;
}
#text {
float: left;
width: 95%;
text-align: center;
}

How to center a fontawesome icon inside a div element

I have a div with width: 180px; and height: 180px;.
How can I center a fontawesome icon horizontally and vertically inside the container?
Note: i may also add text below the icon
<div style="width:180px; height:180px; float:left;">
<i class="fa fa-search fa-4x"></i>
</div>
should look something like this:
Try this:
.centered{
position:relative;
top:50%;
left:50%;
transform:translate(-50%,-50%)
}
.container{
width:100px;
height:100px;
}
On mobile.
You can do it like this
#search{
background: gray;
width:180px;
height:180px;
float:left;
line-height: 180px;
text-align: center;
vertical-align: bottom;
}
#search > p {
margin-top: -155px;
}
Working example http://jsfiddle.net/kasperFranz/h91p8w4e/3/ (using icon instead of fa in the example, but shouldn't affect the result.)
I'm probably too late here, but it's a common question, so here's a simple working idea, the interesting side of it is that it adapts to the container size:
span{
margin: auto;
top: 0;
bottom: 0;
left: 0;
right: 0;
position: absolute;
text-align: center;
width: 15px;
height: 15px;
display: block;
}
Asuming to my comment, here is a JSFIDDLE
Without setting relative or absolute
html
<div class="myDiv">
<div class="content_wrapper">
<!--i class="fa fa-search fa-4x">test</i-->
<i class="icon-search icon-4x"></i><br />
<span class="myText">Search</span>
</div>
</div>
css
.myDiv{
width: 180px;
height: 180px;
float: left;
background: #ccc;
text-align: center;
display: table;
}
.content_wrapper{
display: table-cell;
vertical-align: middle;
}
.myText{
font-weight: bold;
font-size: 20px;
}
CSS
/* This parent can be any width and height */
.block {
text-align: center;
background:#ccc;
margin-bottom:10px;
}
/* The ghost, nudged to maintain perfect centering */
.block:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -0.25em; /* Adjusts for spacing */
}
/* The element to be centered, can
also be of any width and height */
.centered {
display: inline-block;
vertical-align: middle;
width: 300px;
}
HTML
<div class="block" style="height: 300px;">
<div class="centered">
<h1>Some text</h1>
<p>p1</p>
</div>
</div>
<div class="block" style="height: 200px;">
<div class="centered">
<h1>Some text</h1>
<p>p2</p>
</div>
</div>
<div class="block" style="height: 600px;">
<div class="centered">
<h1>Some text</h1>
<p>p3</p>
</div>
</div>
DEMO
Update 1:
DEMO
I know it's a bit late and you probably already figured this out.
I was able to achieve what you were looking for by wrapping the icon and text in a div then adding padding to that.
See the attached pen.
http://codepen.io/ForTheJim/pen/YPxveR
<p data-height="268" data-theme-id="0" data-slug-hash="YPxveR" data-default-tab="result" data-user="ForTheJim" class='codepen'>See the Pen <a href='http://codepen.io/ForTheJim/pen/YPxveR/'>Centering Icon Question</a> by Jim (<a href='http://codepen.io/ForTheJim'>#ForTheJim</a>) on <a href='http://codepen.io'>CodePen</a>.</p>
<script async src="//assets.codepen.io/assets/embed/ei.js"></script>
Short way just add display: grid; place-items: center; to your div and your ready to go.
like this:
<div style="width:180px; height:180px; display: grid; place-items: center;">
<i class="las la-user-circle"></i>
</div>

Resources