I have a really weird bug about inheriting in css. p element that is not inside "a" elements block, inheriting "a" element's properties and turning an "a" element strangely.
// !! IMPORTANT README:
// You may add additional external JS and CSS as needed to complete the project, however the current external resource MUST remain in place for the tests to work. BABEL must also be left in place.
/***********
INSTRUCTIONS:
- Select the project you would
like to complete from the dropdown
menu.
- Click the "RUN TESTS" button to
run the tests against the blank
pen.
- Click the "TESTS" button to see
the individual test cases.
(should all be failing at first)
- Start coding! As you fulfill each
test case, you will see them go
from red to green.
- As you start to build out your
project, when tests are failing,
you should get helpful errors
along the way!
************/
// PLEASE NOTE: Adding global style rules using the * selector, or by adding rules to body {..} or html {..}, or to all elements within body or html, i.e. h1 {..}, has the potential to pollute the test suite's CSS. Try adding: * { color: red }, for a quick example!
// Once you have read the above messages, you can delete all comments.
#import url("https://fonts.googleapis.com/css?family=Lato|Roboto");
body {
margin: 0;
}
#navbar {
min-height: 90px;
position: fixed;
top: 0;
left: 0;
right: 0;
display: flex;
justify-content: flex-end;
align-items: center;
background: #303841;
}
#navbar a {
padding: 0 6vw;
text-decoration: none;
font: bold calc(20px + 1vw) "Lato";
color: #f6c90e;
letter-spacing: 2px;
text-shadow: 0 2px 0 black;
}
.container #welcome-section {
background: #303841;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.container #welcome-section header {
font-size: calc(20px + 2vw);
font-weight: bold;
font-family: 'Lato';
color: #f6c90e;
letter-spacing: 4px;
text-shadow: 0 2px 0 black;
text-align: center;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.container #welcome-section header p {
margin-top: 0;
color: #eeeeee;
}
.container #welcome-section header h1 {
margin-bottom: 10px;
}
.container #projects {
min-height: 100vh;
display: flex;
align-items: baseline;
justify-content: space-evenly;
flex-wrap: wrap;
background: #3a4750;
}
.container #projects h2 {
flex-basis: 100%;
text-align: center;
font-size: calc(20px + 3vw);
font-weight: bold;
font-family: 'Lato';
color: #eeeeee;
text-decoration: underline;
text-shadow: 0 2px 0 black;
}
.container #projects figure {
width: 35vw;
}
.container #projects figure img {
display: block;
max-width: 100%;
border-radius: 2%;
}
.container #projects figure a {
text-decoration: none;
display: block;
}
.container #projects figure figcaption {
text-align: center;
text-shadow: 0 2px 0 black;
font: bold calc(15px + 1vw) "Roboto";
color: #f6c90e;
}
#media (max-width: 768px) {
#navbar {
justify-content: space-between;
}
#projects > * {
flex-basis: 100%;
padding-bottom: 10px;
}
#projects a {
width: 75%;
margin: 0 auto;
}
}
#media (max-width: 768px) and (max-width: 576px) {
#navbar {
flex-direction: column;
justify-content: space-evenly;
align-items: center;
}
}
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<!-- Navigation bar -->
<nav id="navbar">
About
Work
Contact
</nav>
<!-- Main content -->
<main class="container">
<section id="welcome-section">
<header>
<h1>Anıl Emek Türkeli</h1>
<p>Frontend Developer</p>
</header>
</section>
<section id="projects">
<h2>All Works I've Done So Far </h2>
<figure class="project-tile">
<img src="https://cdn1.imggmi.com/uploads/2019/3/12/f3614255ab87606e66bf5d449e194599-full.png"
<figcaption>Sass Technical Documentation Page</figcaption>
</figure>
<figure class="project-tile">
<img src="https://cdn1.imggmi.com/uploads/2019/3/12/99066cf68f33649bc17562c4925c3afa-full.png"
<figcaption>Repedo Landing Page</figcaption>
</figure>
<figure class="project-tile">
<img src="https://cdn1.imggmi.com/uploads/2019/3/12/626217cf51607a559f6a47fad499f355-full.png"
<figcaption>Repedo Survey Form</figcaption>
</figure>
<figure class="project-tile">
<img src="https://cdn1.imggmi.com/uploads/2019/3/12/1dbdcffbefc68964500597ec04e48e05-full.png"
<figcaption>Mustafa Kemal Atatürk's Tribute Page</figcaption>
</figure>
</section>
<section id="contact">
<p>Deneme</p>
</section>
</main>
https://codepen.io/anilemek/pen/PLjpQm
Can anybody explain why this issue occured?
Thank you.
If it is about the <p> with textDeneme at the bottom of the site, the issue is in the img tags before. You have to close them. So eg,<img src="https://cdn1.imggmi.com/uploads/2019/3/12/626217cf51607a559f6a47fad499f355-full.png"/>
Related
enter image description here
i am trying to align all the .features items in the center but for some reason only the first one is doing it. I do not find the reason, please help.
<section>
<div class="features">
<div><i class="fa-solid fa-fire"></i></div>
<div>
<h2>Premium Materials</h2>
<p class="p-description">
Our guitars are built with the best amazonian wood
</p>
</div>
</div>
<div class="features">
<div>
<i class="fa-solid fa-truck-fast"></i>
</div>
<div>
<h2>Shipping</h2>
<p class="p-description">
We make sure you recieve your trombone as soon as we have finished
making it. We also provide free returns if you are not satisfied.
</p>
</div>
</div>
<div class="features">
<div><i class="fa-solid fa-user-check"></i></div>
<div>
<h2>Satisfaction</h2>
<p class="p-description">
For every purchase you make, we will ensure there are no damages or
faults and we will check and test the quality of your instrument.
</p>
</div>
</div>
</section>
css
body {
background-color: #eff1ed;
font-family: "Roboto", sans-serif;
}
/* Header and nav bar */
header {
display: flex;
}
.logo-guitar {
padding: 2% 1% 3% 2%;
}
.luthier-name {
width: 100%;
padding: 1.5% 0 0 1%;
}
#nav-bar {
display: flex;
text-align: center;
justify-content: space-between;
flex-direction: row;
}
.nav-link {
width: 94px;
text-align: center;
margin: 2px auto;
padding-top: 15%;
color: #131b23;
text-decoration: none;
font-weight: bold;
}
h1 {
font-family: "Satisfy", cursive;
font-size: 3rem;
}
/* email form */
.email-form {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
}
#email {
height: 25px;
width: 100%;
}
#submit {
width: 80%;
margin-top: 5%;
background-color: #ffe121;
border: 0;
font-weight: bold;
height: 35px;
font-family: inherit;
font-size: large;
}
/* Features */
.fa-solid {
color: #e3170a;
font-size: 50px;
}
.features {
display: flex;
align-items: center;
justify-content: center;
text-align: left;
}
.p-description {
width: 80%;
}
section {
padding-top: 10%;
}
If all them have the same class i do not understan why this is happening. I was trying to uso console to find the reason but i'm stuck.
It seems that the .p-description has a width based on its content (it is set in percentage, but its container also does not have a defined width), therefore it gets wider with more text inside, which result in unexpected different looks.
You can define width of .p-description with a value independent to its content and it should make them have same width, such as in px, em, vw, or vh.
Example:
.p-description {
max-width: 350px;
}
Or the layout of its container and parent container can be adjusted to properly contain various length of content in .p-description, but it does take a bit more of refactoring.
Hope that it helps!
I have noticed the problem of certain letters overflowing their container on the left side, but I haven't seen anyone actually bringing up the problem.
I've tried between a few different font-families, but they all seem to have the same problem.
JSFIDDLE: https://jsfiddle.net/3h5poynt/
HTML (angular)
<div class="personal-profile container-column">
<mat-card class="header">
<section class="cover-section"></section>
<section class="intro-section">
<div class="intro-header">
<div class="profile-photo-wrapper">
<img src="/assets/img/profile-picture-placeholder.png" alt="" class="profile-photo" />
</div>
<div class="badges-container">
<ul class="badges-list">
<li>
<img
src="/assets/badges/business-plans-180x180.png"
alt="Business plan"
matTooltip="Something"
matTooltipClass="badge-tooltip"
matTooltipPosition="above"
/>
</li>
<li><img src="/assets/badges/calling-customers-180x180.png" alt="Calling customers" /></li>
<li><img src="/assets/badges/finance-180x180.png" alt="Finance" /></li>
<li>
<img src="/assets/badges/selling-to-customers-180x180.png" alt="Selling to customers" />
</li>
<li><img src="/assets/badges/social-media-180x180.png" alt="Social media" /></li>
</ul>
</div>
</div>
<div class="info-container">
<div class="personal-info">
<div class="name-text">{{ profile ? profile.name : '' }}</div>
<div class="description">{{ profile ? profile.personal_description : '' }}</div>
</div>
<div class="additional-info"></div>
</div>
</section>
</mat-card>
SCSS
#import '../../../variables';
.mat-card {
padding: 0;
overflow: hidden;
section {
padding: 20px;
}
}
.badge-tooltip {
background: #3f51b5;
color: white;
font-family: $font-open-sans;
}
.personal-profile {
margin-top: 50px;
.header {
min-height: 500px;
width: 100%;
.cover-section {
background: url('/assets/img/coverpicture.png') center/cover;
height: 225px;
}
.intro-section {
.intro-header {
size: auto;
.profile-photo-wrapper {
position: relative;
margin-top: -87px;
display: inline-block;
.profile-photo {
width: 150px;
height: 150px;
border: 4px solid white;
border-radius: 10px;
box-shadow: inset 0 1.5px 3px 0 rgba(0, 0, 0, 0.15), 0 1.5px 3px 0 rgba(0, 0, 0, 0.15);
background-color: #fff;
}
}
.badges-container {
vertical-align: middle;
display: inline-block;
margin-top: -87px;
.badges-list {
list-style: none;
li {
float: left;
padding: 0 10px 0 10px;
img {
width: 40px;
height: 40px;
}
}
}
}
}
.info-container {
padding-top: 15px;
display: grid;
grid-template-columns: 1fr 1fr;
font-family: $font-open-sans;
.personal-info,
.additional-info {
display: flex;
flex-direction: column;
}
.personal-info {
.name-text {
font-size: 1.3em;
}
}
}
}
}
}
Main SCSS
/* You can add global styles to this file, and also import other style files */
#import '~#angular/material/prebuilt-themes/indigo-pink.css';
#import '_variables.scss';
* {
margin: 0;
padding: 0;
font-family: $font-open-sans;
}
html {
font-family: 'Roboto', sans-serif;
}
html,
body {
height: 100%;
width: 100%;
background-color: #e9ebee;
}
.container-column {
display: flex;
flex-direction: column;
width: 80%;
margin: auto;
}
.container-row {
display: flex;
flex-direction: row;
width: 80%;
margin: auto;
}
Is there something very essential that I am missing, or is this something that has to be hacked?
Jonas,
Some fonts are "just like that".
You will find that (especially with some of the more amateurish free fonts available nowadays) that some fonts' descenders, ascenders, ornaments, etc just overlap the borders that we (programmers, readers) expect them to conform to.
If you really want to use a font like this in this specific context, then you have to program around the font's limitations.
In your fiddle, I merely added padding-left to the name-text style:
.name-text{
font-size: 1.3em;
font-family: "Open Sans", sans-serif;
background: red;
padding-left:15px; /* voila! */
}
Give it a try in the fiddle.
If the left bearing is radically different on initial characters across the font, then you maybe able to set up various styles with padding that changes according to the substring value of the first character. Sounds like a bit of a living hell to program that, but if you really want it, there you go.
Or you could just pick a different font.
Hi there I am new to css and to stackoverflow and need some help. I am trying to create something like this with css:
image
But I really don't get these results, can someone help me? thanks
I created a snippet which looks like the image you were trying to re-create. Hope it helps.
Useful links -
::after / ::before, flexbox
.hr-sect {
display: flex;
flex-basis: 100%;
align-items: center;
margin: 8px 0px;
}
.hr-sect::before,
.hr-sect::after {
content: "";
flex-grow: 1;
height: 2px;
font-size: 0px;
line-height: 0px;
margin: 0px 20px;
}
.hr-sect,
span {
color: blue;
}
.hr-sect::before,
.hr-sect::after {
background-color: blue;
}
hr {
border: 1px solid blue;
}
.title {
text-align: center;
}
.big {
font-size: 25px;
}
<div class="title">
<div class="hr-sect"><span>HOW TO GET</span></div>
<span class="big">GALAXY SKIN FORTNITE</span>
<hr>
</div>
I have used Bootstrap 4 and some custom CSS to make a hero section with all its items but one centered horizontally and vertically.
The exception is one item I want to align at the bottom of the page and still keep it centered horizontally.
html,
body {
padding: 0;
margin: 0;
height: 100%;
}
.page-wrapper {
min-height: 100%;
}
a.inherit {
color: inherit;
}
a.nounderline, a.nounderlie:hover {
text-decoration: none;
}
.page-wrapper {
min-height: 100%;
}
.hero {
height: 100vh;
overflow-y: hidden;
padding-top: 3rem;
padding-bottom: 3rem;
justify-content: center;
align-items: center;
}
.hero img {
width: 100%;
}
.hero.type-text h1 {
color: #000;
}
.hero.hero-short {
max-height: 768px;
}
section.type-text h3 {
font-weight: bold;
font-size: 2rem;
margin-bottom: 0;
}
section.type-text h4 {
font-size: 14px;
font-weight: bold;
margin-bottom: 0;
margin-top: 1.5rem;
}
section.type-text p {
font-weight: 500;
}
.allcases {
text-align: center;
font-weight: 700;
margin-top: auto;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="page-wrapper">
<section class="container d-flex hero type-text">
<div>
<h4 class="text-center m-0">Next item</h4>
<h1 class="display-1 text-center">
<a class="inherit nounderlie" href="#">Lorem</a>
</h1>
</div>
<p class="allcases">
<a class="inherit" href="#">See all items</a>
</p>
</section>
</div>
"See all items" does stay to the bottom (thanks to margin-top: auto), but it is not centered. Changing the flex-direction from row to column messes the whole layout so it is not the way to go.
What is viable solution?
You should be using flex-direction: column for this. This is an ideal use-case for it. Using row layout to achieve what you want, i.e. have the items horizontally centered is not viable. You'd be better off not using flex at all, and using margins instead. If you really wish to use flex-direction: row then the only solution I can think of is either to use position: absolute or a negative margin. Wouldn't recommend it though, since what you want can so easily be accomplished just by using flex-direction: column.
Here is the result I achieved just by changing 2 properties.
Update styling to
// Only added flex-direction: column to this
.hero {
height: 100vh;
overflow-y: hidden;
padding-top: 3rem;
padding-bottom: 3rem;
justify-content: center;
align-items: center;
flex-direction: column;
}
// This is to target the first div, i.e. the div that contains next item and Lorem, since the div doesn't have a class.
.hero > div {
margin-top: auto;
}
The answer is rather simple. Change the flex-flow of your container to column.
flex-flow:column;
Now you have two flex-items: The div, containing your Title and the other links and the footer-p. The first trick is to make your div grow, while the p-tag stays the same. So assign
flex: 1 auto;
to your div and
flex: 0 auto;
to your p-tag.
After doing so you have to add
display: flex;
justify-content: center;
flex-flow: column;
to your div, too. Making it a flex-box itself.
Your p-tag doesnt require more attention, you can also remove the unnecessary margins.
This should do the trick.
You need to allow wrapping and set a width to the div suppose to stand at top
to allow wrapping, use a class
<section class="container d-flex hero type-text flex-wrap">
for the di, you can do :
.hero>div {
width:100%;
}
html,
body {
padding: 0;
margin: 0;
height: 100%;
}
.page-wrapper {
min-height: 100%;
}
a.inherit {
color: inherit;
}
a.nounderline, a.nounderlie:hover {
text-decoration: none;
}
.hero {
height: 100vh;
overflow-y: hidden;
padding-top: 3rem;
padding-bottom: 3rem;
justify-content: center;
align-items: center;
}
.hero>div {
width:100%;
}
.hero img {
width: 100%;
}
.hero.type-text h1 {
color: #000;
}
.hero.hero-short {
max-height: 768px;
}
section.type-text h3 {
font-weight: bold;
font-size: 2rem;
margin-bottom: 0;
}
section.type-text h4 {
font-size: 14px;
font-weight: bold;
margin-bottom: 0;
margin-top: 1.5rem;
}
section.type-text p {
font-weight: 500;
}
.allcases {
text-align: center;
font-weight: 700;
margin: auto auto 0 auto;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="page-wrapper">
<section class="container d-flex hero type-text flex-wrap">
<div>
<h4 class="text-center m-0">Next item</h4>
<h1 class="display-1 text-center">
<a class="inherit nounderlie" href="#">Lorem</a>
</h1>
</div>
<p class="allcases">
<a class="inherit" href="#">See all items</a>
</p>
</section>
</div>
Another option is to use the flex-column class
html,
body {
padding: 0;
margin: 0;
height: 100%;
}
.page-wrapper {
min-height: 100%;
}
a.inherit {
color: inherit;
}
a.nounderline, a.nounderlie:hover {
text-decoration: none;
}
.hero {
height: 100vh;
overflow-y: hidden;
padding-top: 3rem;
padding-bottom: 3rem;
justify-content: center;
align-items: center;
}
.hero img {
width: 100%;
}
.hero.type-text h1 {
color: #000;
}
.hero.hero-short {
max-height: 768px;
}
section.type-text h3 {
font-weight: bold;
font-size: 2rem;
margin-bottom: 0;
}
section.type-text h4 {
font-size: 14px;
font-weight: bold;
margin-bottom: 0;
margin-top: 1.5rem;
}
section.type-text p {
font-weight: 500;
}
.allcases {
text-align: center;
font-weight: 700;
margin: auto auto 0 auto;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="page-wrapper">
<section class="container d-flex flex-column hero type-text ">
<div>
<h4 class="text-center m-0">Next item</h4>
<h1 class="display-1 text-center">
<a class="inherit nounderlie" href="#">Lorem</a>
</h1>
</div>
<p class="allcases">
<a class="inherit" href="#">See all items</a>
</p>
</section>
</div>
in both example, margin of allcases is reset to :
margin: auto auto 0 auto;
to stick it at bottom of container, no matter the flex-direction.
I have the following simple html code for a simple template:
<!DOCTYPE html>
<html>
<head>
<title>My new website</title>
<meta name="description" content="Simple website styled using flex box layout">
<meta http-equiv="refresh" content="60">
<link rel="stylesheet" type="text/css" href="style1.css">
</head>
<body>
<div class="mainContainer">
<nav class="mainMenu">
<ol>
<li>
Home
</li>
<li>
About
</li>
<li>
Contact Us
</li>
</ol>
</nav>
<div class="mainArea">
<aside class="leftBar">
<h3>Navigation side bar</h3>
<p>Still need to think better what I will implement here.</p>
</aside>
<article class="mainContent">
<h1>Welcome!</h1>
<p>Nice to meet you...</p>
</article>
<aside class="rightBar">
<h3>News</h3>
<p>No news for now.</p>
</aside>
</div>
<footer class="mainFooter">
<p>Copyright ©
someone
</p>
</footer>
</div>
</body>
</html>
But the layout broke after I added <!DOCTYPE html> at the beginning of the html code. Now it looks like this:
But it should look like this:
Not only the margins broke, for example also the navigation bar is not exactly how it should be. I searched around for a solution, and there are some problems related, but I simply cannot understand why there this problem.
Here you have the CSS code:
html, body{
height: 100%;
width:auto;
font: 14px Arial;
color:white;
background: #444;
}
/* links */
a{
text-decoration: none;
color: #00aefb;
}
a:visited{
color:#008efb;
}
a:hover{
color: #999;
}
/* flex elements */
.mainContainer, .mainFooter, .mainArea, .mainMenu, .mainMenu ol{
display: flex;
display: -webkit-flex;
display: -moz-flex;
}
/* Main container */
.mainContainer{
font-family: Georgia;
flex-direction: column;
-webkit-flex-direction: column;
-moz-flex-direction: column;
}
/* mainMenu and footer */
.mainMenu, .mainFooter{
background: #555;
border: 1px solid white;
border-radius: 2px;
padding: 10px;
}
/* Just footer */
.mainFooter {
text-align: center;
font: 15px Arial;
min-height: 60px;
justify-content: center;
-webkit-justify-content: center;
-moz-justify-content: center;
align-items: center;
-webkit-align-items: center;
-moz-align-items: center;
}
/* Main area of contents */
.mainArea{
color: white;
border: 1px solid white;
border-radius: 2px;
margin: 20 0 20 0;
min-height:800px;
}
/* Main area of the main area */
.mainContent{
background: #eee;
color: black;
padding:20px;
flex: 2 2 50%;
-webkit-flex: 2 2 50%;
-moz-flex: 2 2 50%;
}
/* Left and right side bars */
.leftBar, .rightBar{
padding: 10px;
flex: 1 1 15%;
-webkit-flex: 1 1 15%;
-moz-flex: 1 1 15%;
}
/* mainMenu bar at the top */
.mainMenu {
font: 16px Arial;
justify-content: center;
-webkit-justify-content: center;
-moz-justify-content: center;
padding: 0;
}
.mainMenu ol {
list-style: none;
padding: 0; /* Removes annoying indentation */
margin: 0;
text-align: center;
}
.mainMenu ol li{
display: inline;
padding: 20px;
margin: 0 30 0 30;
}
li:hover, li.active{
background: #222;
color: #999;
border-radius: 5px;
}
#media all and(max-width: 640px){
.mainArea{
flex-direction: column;
-webkit-flex-direction: column;
-moz-flex-direction: column;
}
.mainMenu {
font: 18px Arial;
flex-direction: column;
-webkit-flex-direction: column;
-moz-flex-direction: column;
}
.mainMenu ol {
flex-direction: column;
-webkit-flex-direction: column;
-moz-flex-direction: column;
align-items:stretch;
-webkit-align-items:stretch;
-moz-align-items:stretch;
}
.mainMenu ol li {
margin: 0;
padding: 10px;
}
.mainContainer .mainArea {
border: 0;
border-radius: 0;
}
.mainContent{
order: -1;
-webkit-order: -1;
-moz-order: -1;
margin: 0 0 20 0;
border: 1px solid white;
border-radius: 2px;
}
.leftBar {
margin: 0 0 20 0;
border: 1px solid white;
border-radius: 2px;
}
.rightBar{
border: 1px solid white;
border-radius: 2px;
}
}
I wouldn't say that adding <!DOCTYPE html> breaks out the layout. The doctype tells the browser how to interpret the HTML and CSS, if you don't specify one, then the browser goes in quirk mode, and the display is different from a strict mode.
By adding the <!doctype html>, some of your CSS styles become incorrect and the browser does interpret them the best way that it can. For example, one of the issues that you have is that there are some non-zero numeric values without specifying the unit (e.g.: margin: 20 0 20 0;).
You are missing .mainMenu { margin-bottom: 10px; }
Or alternatively, if you want to use <!DOCTYPE html> then fix this .mainArea { margin: 20px 0 20px 0; }, you did not mention any units.
CSS Units
CSS has several different units for expressing a length.
Many CSS properties take "length" values, such as width, margin,
padding, font-size, border-width, etc.
Length is a number followed by a length unit, such as 10px, 2em, etc.
A whitespace cannot appear between the number and the unit. However,
if the value is 0, the unit can be omitted.
For some CSS properties, negative lengths are allowed.
There are two types of length units: relative and absolute.
Reference