I made this followers Card design but am having a bit of problem when styling it, when I try to add margin-right to align the image to the right side of the container for some reason it doesn't align to the right, It aligns it more to the left and it stretches the container, it also grabs the text even though they're both in separate containers, same for the button. And for some reason instead of using padding on the follow__content, I instead used gave a width but for some reason the image get left out.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: 62.2%;
font-family: Roboto, Arial, Helvetica, sans-serif;
}
.follow__container {
display: grid;
place-items: center;
height: 100vh;
}
.follow__content {
background-color: rgba(206, 194, 178, 0.836);
line-height: 1.2;
padding: 2rem 10rem;
}
.img__container {
width: 35px;
display: inline-block;
margin-right: 2rem;
margin-top: 0.5rem;
}
.img__container img {
width: 35px;
height: 35px;
object-fit: cover;
object-position: center;
border-radius: 5rem;
}
.follow__desc {
display: inline-block;
margin: 0 0 0 0.5rem;
font-size: 0.99rem;
}
.follow__btn {
display: inline-block;
font-size: 1.2rem;
left: 8rem;
position: relative;
top: -1.6rem;
cursor: pointer;
}
.follow__btn a {
text-decoration: none;
padding: 1rem 1.5rem;
background-color: #222095;
color: #ffffff;
border-radius: 1rem;
}
<div class="follow__container">
<div class="follow__content">
<div class="img__container">
<img src="cybercybrog.jpg" alt="">
</div>
<div class="follow__desc">
<h2>Mr Cyborg</h2>
<p>#CyberCity</p>
<p>Most Popular</p>
</div>
<div class="follow__btn">
Follow
</div>
</div>
</div>
I think this is your desired output.I used the padding property in the follow__content class and changed its' values by giving all the sides padding like this. Since you had given padding only for two sides it was applied incorrectly.
.follow__content {
background-color: rgba(206, 194, 178, 0.836);
line-height: 1.2;
padding: 10px 100px 10px 10px;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: 62.2%;
font-family: Roboto, Arial, Helvetica, sans-serif;
}
.follow__container {
display: grid;
place-items: center;
height: 100vh;
}
.follow__content {
background-color: rgba(206, 194, 178, 0.836);
line-height: 1.2;
padding: 20px 100px 20px 10px;
}
.img__container {
width: 35px;
display: inline-block;
margin-right: 0rem;
margin-top: 0.5rem;
}
.img__container img {
width: 35px;
height: 35px;
object-fit: cover;
object-position: center;
border-radius: 5rem;
}
.follow__desc {
display: inline-block;
margin: 0 0 0 0.5rem;
font-size: 0.99rem;
}
.follow__btn {
display: inline-block;
font-size: 1.2rem;
left: 8rem;
position: relative;
top: -1.6rem;
cursor: pointer;
}
.follow__btn a {
text-decoration: none;
padding: 1rem 1.5rem;
background-color: #222095;
color: #ffffff;
border-radius: 1rem;
}
<div class="follow__container">
<div class="follow__content">
<div class="img__container">
<img src="https://www.slashfilm.com/img/gallery/joss-whedon-says-he-cut-cyborgs-justice-league-storyline-because-ray-fisher-is-a-bad-actor/l-intro-1642457019.jpg" alt="Profile Image">
</div>
<div class="follow__desc">
<h2>Mr Cyborg</h2>
<p>#CyberCity</p>
<p>Most Popular</p>
</div>
<div class="follow__btn">
Follow
</div>
</div>
</div>
Related
I'm trying to create a description box for a website in React. The image below is the desired look:
but when I resize the screen to be large, the h1 tag doesn't seem to hold its absolute position anymore. I would like the box to resize like it has with the screen but the "Project 1" title should stay in the same place.
The CSS code to produce the images is:
body {
font-family: sans-serif;
margin: 0 auto;
padding: 25px;
max-width: 800px;
min-width: 400px;
background-color: #e0e0e0;
text-align: center;
}
.card {
position: relative;
padding: 25px 0px;
background-color: #ffffff;
margin: 50px 0;
text-align: left;
}
.top {
height: 100px;
width: 100%;
background-color: #69143a;
position: absolute;
top: 0;
left: 0;
display: flex;
}
h1 {
position: relative;
display: flex;
}
.name {
font-size: 2em;
color: #ffffff;
display: flex;
flex: 1;
margin: 10% 25px 0;
}
.supervisor {
font-size: 1em;
margin: 20px 20px;
color: #353535;
}
.bottom {
margin-top: 100px;
margin-left: 20px;
margin-right: 20px;
margin-bottom: 10px;
color: #353535;
}
.info {
margin: 20px 20px;
}
.subjects {
margin: 20px 20px;
font-style: italic;
}
and the React component is:
function Project(props) {
return (
<div className="card">
<div className="top">
<h2 className="name">{props.title}</h2>
</div>
<div className="bottom">
<h4 className="supervisor">Supervisor: {props.supervisor}</h4>
<p className="info">{props.description}</p>
<p className="subjects">Prerequisites: {props.subjects}</p>
</div>
</div>
)
}
Any help would be greatly appreciated - been banging my head on the wall all day trying to get it to format correctly.
The root of the issue is the dynamic margin you had set on .name. You can remove that and also remove the position: absolute; and exchange it with relative. Then remove the top padding on .card and you are good to go.
body {
font-family: sans-serif;
margin: 0 auto;
padding: 25px;
max-width: 800px;
min-width: 400px;
background-color: #e0e0e0;
text-align: center;
}
.card {
position: relative;
padding: 0px 0px 25px 0px;
background-color: #ffffff;
margin: 50px 0;
text-align: left;
}
.top {
width: 100%;
background-color: #69143a;
position: relative;
top: 0;
left: 0;
text-align: center;
}
h1 {
position: relative;
display: flex;
}
.name {
font-size: 2em;
color: #ffffff;
padding: 30px;
}
.supervisor {
font-size: 1em;
margin: 20px 20px;
color: #353535;
}
.bottom {
margin-top: 100px;
margin-left: 20px;
margin-right: 20px;
margin-bottom: 10px;
color: #353535;
}
.info {
margin: 20px 20px;
}
.subjects {
margin: 20px 20px;
font-style: italic;
}
<div class="card">
<div class="top">
<h2 class="name">{props.title}</h2>
</div>
<div class="bottom">
<h4 class="supervisor">Supervisor: {props.supervisor}</h4>
<p class="info">{props.description}</p>
<p class="subjects">Prerequisites: {props.subjects}</p>
</div>
</div>
I've created a card that is showcasing an article.
For some reason, two of the elements have additonal height that's causing weird behaviour. At first I thought it was the image but giving it a diplay:block hasn't solved the issue.
I've been messing around with it a lot so it's a bit of a mess at this point. SO here's the weird extra height between the white part of the card and the image:
Because it's happening to two elements, I have a feeling that it's something important that I am fundamentally missing.
The two affected elements are:
articleCard_image, a <div>
articleCard_container, a <section>
The issue only occurs for the <secction> when the 'Read Article' anchor is displayed. (I've commmented out the display:none which is changed to block on hover)
I'm using Gulp to compile the scss to css.
Any help would be greatly appreciated. Thank you! Code shown below:
SCSS:
.articleCard_container {
width: 55.7rem;
height: auto;
.articleCard_image {
width: 100%;
height: auto;
box-sizing: border-box;
display: block;
.articleCard_category {
position: relative;
bottom: 4rem;
left: 3rem;
display: flex;
align-items: center;
text-transform: uppercase;
font-size: 1.4rem;
color: var(--white);
width: 100%;
p {
font-weight: 600;
}
.thumbtack {
margin-right: 1rem;
margin-bottom: 1rem;
}
.purpleRose {
width: 100%;
display: block;
}
}
}
.articleCard_textContent {
box-sizing: border-box;
padding: 1rem 3rem 5rem 3rem;
width: 100%;
margin: 0;
background-color: var(--white);
.articleCard_date {
color: var(--articleDate);
text-transform: uppercase;
font-size: 1.2rem;
}
.articleCard_title {
margin-top: 1rem;
font-size: 1.6rem;
width: 100%;
color: var(--articleTitle);
font-weight: 700;
}
}
.articleCard_readMore {
text-transform: uppercase;
color: var(--buttonPrimary);
font-size: 1.2rem;
font-weight: 600;
position: relative;
bottom: 2rem;
left: 3rem;
// display: none;
}
}
.articleCard_container:hover {
.articleCard_readMore {
display: block;
box-sizing: border-box;
text-decoration: none;
}
}
HTML:
<div class="carouselle_container">
<section class="articleCard_container">
<div class="articleCard_image">
<img class="purpleRose" src="./assets/purpleRose.jpg" alt="purple rose">
<div class="articleCard_category">
<img class="thumbtack" src="./assets/thumtack.svg" alt="thumbtack icon">
<p>featured news / category</p>
</div>
</div>
<div class="articleCard_textContent">
<time date="2020-03" class="articleCard_date"> march 20th 20xx</time>
<h3 class="articleCard_title">This is an example of a really long heading that needs to span over multiple lines.</h3>
</div>
<a class="articleCard_readMore" href="/">read article</a>
</section>
</div>
you have to give the .articleCard_image position relative to make sure that the category does not overflow and then give the .articleCard_category absolute position and give a full width and height and display block to the img in order to take the entire space
.articleCard_container {
width: 55.7rem;
height: auto;
.articleCard_image {
width: 100%;
height: auto;
position: relative;
img{
display: block;
height: 100%;
width: 100%;
}
.articleCard_category {
position: absolute;
bottom: 4rem;
left: 3rem;
display: flex;
align-items: center;
text-transform: uppercase;
font-size: 1.4rem;
color: var(--white);
width: 100%;
p {
font-weight: 600;
}
.thumbtack {
margin-right: 1rem;
margin-bottom: 1rem;
}
.purpleRose {
width: 100%;
display: block;
}
}
}
.articleCard_textContent {
box-sizing: border-box;
padding: 1rem 3rem 5rem 3rem;
width: 100%;
margin: 0;
background-color: var(--white);
.articleCard_date {
color: var(--articleDate);
text-transform: uppercase;
font-size: 1.2rem;
}
.articleCard_title {
margin-top: 1rem;
font-size: 1.6rem;
width: 100%;
color: var(--articleTitle);
font-weight: 700;
}
}
.articleCard_readMore {
text-transform: uppercase;
color: var(--buttonPrimary);
font-size: 1.2rem;
font-weight: 600;
position: relative;
bottom: 2rem;
left: 3rem;
// display: none;
}
}
.articleCard_container:hover {
.articleCard_readMore {
display: block;
box-sizing: border-box;
text-decoration: none;
}
}
* {
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
margin: 0px;
}
.we-adopt {
background-color: #8a8484;
color: #ffffff;
padding: 88px 0px;
height: 100px;
}
.we-adopt-list span {
display: inline-block;
vertical-align: top;
padding: 16px 60px 16px 24px;
background-color: #222222;
color: #ffffff;
width: 100%;
}
.we-adopt-list li {
color: #FFFFFF;
font-size: 32px;
font-weight: 500;
letter-spacing: 1.6px;
line-height: 24px;
margin-bottom: 70px;
text-transform: uppercase;
}
.we-adopt-list ul {
display: inline-block;
transform: rotate(-90deg) translateY(-50%);
position: relative;
left: 50%;
}
.we-adopt-list {
position: relative;
}
.we-adopt-list li:last-child {
margin-bottom: 0px;
}
<section class="we-adopt" style="height: 100px;">
</section>
<section class="we-adopt-wrap">
<div class="container">
<div class="we-adopt-list">
<ul>
<li><span>Mental agility</span></li>
<li><span>Emotional agility</span></li>
<li><span>Trust</span></li>
</ul>
</div>
</div>
</section>
Whenever i apply transform- rotate property to my list section its overlap or some time its take space from above content.
Case 1
Case 2
After apply transform- rotate, I want to start list section just from above grey section with no spacing like below image.
Expecting Result
Is there any other way to create this kind of design?
Consider transform-origin and update the transform like below:
* {
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
margin: 0px;
}
.we-adopt {
background-color: #8a8484;
color: #ffffff;
padding: 88px 0px;
height: 100px;
}
.we-adopt-list span {
display: inline-block;
vertical-align: top;
padding: 16px 60px 16px 24px;
background-color: #222222;
color: #ffffff;
width: 100%;
}
.we-adopt-list li {
color: #FFFFFF;
font-size: 32px;
font-weight: 500;
letter-spacing: 1.6px;
line-height: 24px;
margin-bottom: 70px;
text-transform: uppercase;
}
.we-adopt-list ul {
display: inline-block;
transform-origin: top left;
transform: rotate(-90deg) translateX(-100%) translateY(-50%);
position: relative;
margin: 0;
left: 50%;
}
.we-adopt-list {
position: relative;
}
.we-adopt-list li:last-child {
margin-bottom: 0px;
}
<section class="we-adopt" style="height: 100px;">
</section>
<section class="we-adopt-wrap">
<div class="container">
<div class="we-adopt-list">
<ul>
<li><span>Mental agility</span></li>
<li><span>Emotional agility</span></li>
<li><span>Trust</span></li>
</ul>
</div>
</div>
</section>
transform: rotate is a purely visual effect. It doesn't alter the flow of the page. To position it how you want you'd have to use transform: translate or margin or something else.
I want to left align text in a drop-down menu but I'm having some problems. I have this HTML
<nav>
<a>Vote</a>
<a>Search</a>
<a>About</a>
</nav>
and this CSS for the drop down menu
nav {
display: none;
width: 30rem;
padding: 0rem;
background-color: red;
position: absolute;
right: 0%;
top: 100%;
text-align: left;
}
.nav-open {
display: block;
}
nav a {
display: block;
width: 100%;
text-align: left;
padding: 1.4rem 1.6rem;
text-decoration: none;
cursor: pointer;
font-size: 1.2rem;
color: #000;
}
But as you can see, when you click the menu icon the text isn't even visible. Interestingly, when I change:
text-align: left;
to
text-align: center;
I can see the text again, but it is not aligned where i want it. How do I left align my text and keep it visible?
$('.menu-btn').click(function() {
$('nav').toggleClass('nav-open');
});
style* {
margin: 0 auto;
font-family: sans-serif;
}
body {
margin: 0 auto;
font-family: Benton Sans, -apple-system, BlinkMacSystemFont, Roboto, Helvetica Neue, Helvetica, Tahoma, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
}
header {
width: 100%;
background-color: orange;
text-align: center;
position: relative;
}
#pageTitle {
display: flex;
padding: 10px;
}
#pageTitle h2 {
justify-content: center;
/* align horizontal */
align-items: center;
width: 95%;
}
.menu-btn {
position: absolute;
display: inline-block;
cursor: pointer;
}
.menu-btn div {
position: absolute;
left: 100%;
top: 0%;
padding-right: 8px;
margin-top: -0.50em;
line-height: 1.2;
font-weight: 200;
vertical-align: middle;
z-index: 99;
}
.menu-btn span {
display: block;
width: 20px;
height: 2px;
margin: 4px 0;
background: #989da1;
z-index: 99;
}
nav {
display: none;
width: 30rem;
padding: 0rem;
background-color: red;
position: absolute;
right: 0%;
top: 100%;
text-align: left;
}
.nav-open {
display: block;
}
nav a {
display: block;
width: 100%;
text-align: left;
padding: 1.4rem 1.6rem;
text-decoration: none;
cursor: pointer;
font-size: 1.2rem;
color: #000;
}
nav a:hover {
background-color: #111;
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<div id="pageTitle">
<h2>Page Title</h2>
<div class="mobile-nav">
<button class="menu-btn" id="menu-btn">
<div></div>
<span></span>
<span></span>
<span></span>
</button>
<nav>
<a>Vote</a>
<a>Search</a>
<a>About</a>
</nav>
</div>
</div>
</header>
The problem comes from the rem unit you are using when giving width to your nav. You should use vw viewport width. This is relative from the screen width going from 0 to 100 turning the viewport width into a percentage.
Hope this helps
$('.menu-btn').click(function() {
$('nav').toggleClass('nav-open');
});
style* {
margin: 0 auto;
font-family: sans-serif;
}
body {
margin: 0 auto;
font-family: Benton Sans, -apple-system, BlinkMacSystemFont, Roboto, Helvetica Neue, Helvetica, Tahoma, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
}
header {
width: 100%;
background-color: orange;
text-align: center;
position: relative;
}
#pageTitle {
display: flex;
padding: 10px;
}
#pageTitle h2 {
justify-content: center;
/* align horizontal */
align-items: center;
width: 95%;
}
.menu-btn {
position: absolute;
display: inline-block;
cursor: pointer;
}
.menu-btn div {
position: absolute;
left: 100%;
top: 0%;
padding-right: 8px;
margin-top: -0.50em;
line-height: 1.2;
font-weight: 200;
vertical-align: middle;
z-index: 99;
}
.menu-btn span {
display: block;
width: 20px;
height: 2px;
margin: 4px 0;
background: #989da1;
z-index: 99;
}
nav {
display: none;
width: 100vw;
padding: 0rem;
background-color: red;
position: absolute;
right: 0%;
top: 100%;
text-align: left;
}
.nav-open {
display: block;
}
nav a {
display: block;
width: 100%;
text-align: left;
padding: 1.4rem 1.6rem;
text-decoration: none;
cursor: pointer;
font-size: 1.2rem;
color: #000;
}
nav a:hover {
background-color: #111;
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<div id="pageTitle">
<h2>Page Title</h2>
<div class="mobile-nav">
<button class="menu-btn" id="menu-btn">
<div></div>
<span></span>
<span></span>
<span></span>
</button>
<nav>
<a>Vote</a>
<a>Search</a>
<a>About</a>
</nav>
</div>
</div>
</header>
As others have pointed out already, the text is actually aligned left, but your screen size might prevent it from showing up due to the big width of your menu.
Try changing the width of your nav element to something relative to the page width, like 80%:
nav {
display: none;
width: 80%;
padding: 0rem;
background-color: red;
position: absolute;
right: 0%;
top: 100%;
text-align: left;
}
https://jsfiddle.net/1y8n08aq/1/
I'm getting different results on my legend centering across browsers:
Should be like this:
But instead I get different margins on other browsers:
HTML
<div class="teaser-header">
<fieldset class="teaser-fieldset">
<legend class="teaser-legend">We are a very passionate team</legend>
<h1>Who we are</h1>
</fieldset>
</div>
CSS
.teaser-header {
padding-top: 70px;
}
.teaser-fieldset {
border: 1px solid white;
color: white;
text-align: center;
width: 400px;
margin: auto;
}
.teaser-fieldset h1 {
color: white;
text-align: center;
margin: 0;
padding-bottom: 20px;
font-family: "Montserrat";
}
.teaser-legend {
padding: 0 10px;
width: 80%;
margin-left: auto;
margin-right: auto;
color: white;
font-size: 1em;
text-transform: uppercase;
margin-bottom: 0;
}
Any ideas? Thanks!
Setting the margin-left and margin-right explicitly as 10% seems to fix the centering issue. The 10% value is nothing but half of (100% - width).
.teaser-header {
padding-top: 70px;
}
.teaser-fieldset {
border: 1px solid white;
color: white;
text-align: center;
width: 400px;
margin: auto;
}
.teaser-fieldset h1 {
color: white;
text-align: center;
margin: 0;
padding-bottom: 20px;
font-family: "Montserrat";
}
.teaser-legend {
/* padding: 0 10px; remove this */
width: 80%;
margin-left: 10%; /* change this */
margin-right: 10%; /* change this */
color: white;
font-size: 1em;
text-transform: uppercase;
margin-bottom: 0;
text-align: center; /* add this */
}
body {
background: black;
}
<div class="teaser-header">
<fieldset class="teaser-fieldset">
<legend class="teaser-legend">We are a very passionate team</legend>
<h1>Who we are</h1>
</fieldset>
</div>