Responsive content with font-awsome and VueJs 3 - css

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>

Related

How to remove undefine margin and padding css

I made this card to display an image and info but there is a gap I can't remove using css
Here is the style and html
.card-container>* {
width: auto;
height: auto;
margin: 0;
}
.ratings {
display: flex;
align-items: center;
background-color: aqua;
width: auto;
height: fit-content;
}
.card-container img {
width: 240px;
height: 350px;
object-fit: cover;
}
.card-container .stausbg {
background-color: aqua;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" integrity="sha512-MV7K8+y+gLIBoVD59lQIYicR65iaqukzvf/nwasF0nqhPay5w/9lJmVM2hMDcnK1OnMGCdVK+iQrJ7lzPJQd1w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div class="card-container">
<img src='https://dummyimage.com/600x400/000/fff' alt='card' />
<span class="stausbg">Sold Out</span>
<div class="ratings">
<i class="fa-solid fa-star"></i>
<p class="no-star">5</p>
<p class="no-pp">(40)</p>
<i class="fa-solid fa-circle"></i>
<p class="country">Usa</p>
</div>
<h5 class="title">Life lessons with jake</h5>
<h6>From $200 / person</h6>
</div>
Here I have used aqua color as the background color of .ratings class. I want to remove the undefined space (margin padding) and apply my own style
That space is coming from p tag. Just remove the margin.
.ratings p {
margin: 0;
}
If you want to set all the margins of the child items in the card to zero then, instead of using the child combinator (>) just use the descendent combinator.
Quite a lot of developers use 'reset' rules to remove some of the weird, default user agent stylesheet behaviours. Here's a quick video by Kevin Powell on this topic.
.card-container * {
width: auto;
height: auto;
margin: 0;
}
.ratings {
display: flex;
align-items: center;
background-color: aqua;
width: auto;
height: fit-content;
}
.card-container img {
width: 240px;
height: 350px;
object-fit: cover;
}
.card-container .stausbg {
background-color: aqua;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" integrity="sha512-MV7K8+y+gLIBoVD59lQIYicR65iaqukzvf/nwasF0nqhPay5w/9lJmVM2hMDcnK1OnMGCdVK+iQrJ7lzPJQd1w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div class="card-container">
<img src='https://dummyimage.com/600x400/000/fff' alt='card' />
<span class="stausbg">Sold Out</span>
<div class="ratings">
<i class="fa-solid fa-star"></i>
<p class="no-star">5</p>
<p class="no-pp">(40)</p>
<i class="fa-solid fa-circle"></i>
<p class="country">Usa</p>
</div>
<h5 class="title">Life lessons with jake</h5>
<h6>From $200 / person</h6>
</div>

How do I get the Parent container to span the total width of my page

I am using React and this should be a very simple task yet I am stuck. I cannot get the home container to span the width of my page
Here is my Css code, I originally had two Css files one for the Nav and one for the Home section but started playing around trying to figure out where I went wrong. I have basically now stripped my css and code it all the way down still cant figure out why it wont span completely from side to side
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.site-title {
font-size: 2rem;
}
.nav {
background-color: #333;
color: antiquewhite;
display: flex;
justify-content: space-between;
align-items: stretch;
gap: 2rem;
padding: 0 1rem;
}
.nav ul{
display: flex;
gap: 1rem;
padding: 0%;
margin: 0%;
list-style: none;
}
.nav a{
display: flex;
color: inherit;
text-decoration: none;
height: 100%;
align-items: center;
padding: .55rem;
}
.nav li.active {
background-color: #555;
}
.nav li:hover{
background-color: #777;
}
.home-container {
background-color: #111;
}
.home-parent {
display: flex;
align-items: center;
color: aliceblue;
}
My HTML
import Typical from "react-typical";
export default function Home() {
return (
<div className="home-container">
<div className="home-parent">
<div className="profile-details">
<div className="colz">
<div className="colz-icon">
<a href="#">
<i className="fa fa-facebook-square"></i>
</a>
<a href="#">
<i className="fa fa-instagram"></i>
</a>
<a href="#">
<i className="fa fa-youtube-square"></i>
</a>
<a href="#">
<i className="fa fa-twitter"></i>
</a>
</div>
</div>
<div className="Home-details-name">
<span className="primary-text">
{""}
Hello, I'm <span className="highlighted-text">Heather</span>
</span>
</div>
<div className="home-details-role">
<span className="primary-text">
{""}
<h1>
<Typical
loop={Infinity}
steps={[
"Fullstack Dev",
1000,
"Web Design",
1000,
"Data bases",
1000,
"Tech Support",
1000,
]}
/>
</h1>
<span className="home-role-tagline">
Knack for building applications with front and backend
operations
</span>
</span>
</div>
<div className="profile-options">
<button className="btn primary-btn">
{""}
Hire Me{""}
</button>
<a
href="Heather-Christensen.pdf"
download="Heather-Christensen.pdf"
>
<button className="btn highlighted-btn">Get Resume</button>
</a>
</div>
</div>
<div className="profile-picture">
<div className="profile-picture-background"></div>
</div>
</div>
</div>
);
}

Can't add CSS to Div wrapping Anchor tag

Hi I'm trying to add a colored border to my 'dreams-anchor-wrap' div but can't seem to be able to use any CSS on it for some reason and I'm not sure why. Is it not possible to wrap a div around an anchor tag and then add CSS properties to it?
here's the link to my sandbox code:
https://codesandbox.io/s/unruffled-jones-0v0xj?file=/src/App.js
You just misspelled className on 'dreams-anchor-wrap' div.Correct your mistake and should work
You have to write your classes like "class" not className.
Then it will be run correctly.
* {
margin: 0;
border: 0;
padding: 0;
}
.dream-homes-container {
display: flex;
justify-content: center;
}
.dream-home-card {
margin: 0 auto;
padding: 15px;
width: 200px;
height: 100%;
}
.dream-homes-container :last-child {
padding-right: 0;
}
.dream-home-card img {
width: 100%;
height: 70%;
}
.property-info {
width: 100%;
color: black;
padding: 0 0 5px 10px;
}
.dream-home-card a {
text-decoration: none;
width: 100%;
}
.num-specs-margin {
margin-right: 10px;
}
.dream-anchor-wrap {
border:2px solid blue;
}
.dream-homes-wrap {
margin-bottom: 50px;
}
<div class="App">
<div class="dream-home-card">
<a href="#">
<div class="dream-anchor-wrap">
<img src="https://images.pexels.com/photos/2343466/pexels-photo-2343466.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" />
<div class="property-info">
<h4>Pent Suite</h4>
<div class="property-specs">
<i class="fas fa-bed"></i>
<span class="num-beds num-specs-margin">4</span>
<i class="fas fa-shower "></i>
<span class="num-baths num-specs-margin">2</span>
<i class="fas fa-car"></i>
<span class="num-cars ">2</span>
</div>
</div>
</div>
</a>
</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.

Resources