still keeping some vertical space while list-style: none is defined.
https://product-landing-page.freecodecamp.rocks/#how-it-works
If you check this project and scroll to pricing labels there is defined exactly like mine and it behave differently.
My price label:
Project's label
MY CSS:
/* ========== PRICE ======= */
#cost {
display: flex;
flex-direction: row;
justify-content: center;
}
.price-box {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
width: calc(100% / 3);
margin: 10px;
border: 1px solid #000;
border-radius: 3px;
}
.lvl {
background-color: #dddddd;
text-align: center;
font-size: 1.4em;
color: rgb(65, 65, 65);
padding: 5px;
width: 100%;
}
#cost ol li {
padding: 5px 0;
margin: 0;
}
li {
list-style: none;
}
Project's CSS:
#pricing {
margin-top: 60px;
display: flex;
flex-direction: row;
justify-content: center;
}
.product {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
width: calc(100% / 3);
margin: 10px;
border: 1px solid #000;
border-radius: 3px;
}
.product > .level {
background-color: #ddd;
color: black;
padding: 15px 0;
width: 100%;
text-transform: uppercase;
font-weight: 700;
}
.product > h2 {
margin-top: 15px;
}
.product > ol {
margin: 15px 0;
}
.product > ol > li {
padding: 5px 0;
}
Maybe someone can explain it to me so i can understand what is happening here
If you look at all the CSS that is being applied to that ol element you'll notice that there is a setting of everything (*) which includes padding: 0;
This overrides the browser's default settings for padding related to ol elements.
You may or may not want to set padding: 0 for everything at the start. It depends on your precise use case.
As in the case of the site you reference, something like this can be seen at the top of some stylesheets - meaning the author will add any padding and margin settings themselves rather than relying on default browser settings.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
[The box-sizing setting means e.g. padding and border dimensions are included in the dimensions of the element].
If you don't want such a global approach to unsetting padding then put the padding: 0 in the style setting for the ol element itself. For example: [I can't tell exactly what this should be as I don't know your HTML stucture]
#cost ol {
padding: 0;
}
Just add padding: 0
ul, ol {
list-style:none;
padding:0;
}
Related
Code pasted below. I'm trying to get the two castle images to stick to the bottom of the page, specifically the bottom of their container div. I tried using display:flex on the image container div, with align-items: baseline, but it didn't do anything. I tried playing around with various justify and align values, as well as position:relative and absolute, but that just gave a lot of unexpected (to me, at least) results e.g. one of the two images disappearing off-screen.
Any suggestions for fixes greatly appreciated!
Cheers
#import url('https://fonts.googleapis.com/css2?family=Liu+Jian+Mao+Cao&family=MedievalSharp&family=Roboto+Condensed:wght#300&display=swap');
body {
margin: 0 auto;
background-color: #1D1D1D;
cursor: url('snake-moving.png'), pointer;
font-family: 'MedievalSharp', cursive;
}
header nav {
margin: 0 auto;
display: flex;
justify-content: space-around;
align-items: center;
padding: 20 px;
height: 88px;
width: auto;
border-style: double;
border-top: 15px;
border-color: white;
}
header nav * {
font-size: 30px;
color:antiquewhite;
text-decoration: none;
font-weight: 800;
}
header nav form, a::after {
content: url('pie-logo.png');
position: relative;
top: 10px;
left: 20px;
}
.game {
border: #1D1D1D solid 40px;
width: auto;
background-color: #F4F186;
}
.image-container {
width: auto;
height: 800px;
margin: 0 auto;
position: relative;
}
.image-container img {
position: absolute;
bottom: 0;
}
.game h1 {
color: midnightblue;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
Improve this question
I have some mystery Margin popping up at the end of my .container_main in my Inspect on Google Chrome. My margin is set to 0 but there is still some margin that is preventing me from flex-ending my content. Please let me know what you think!
Here is my code and I will also attach an image of my inspect panel.
/* Box Model Hack */
* {
box-sizing: border-box;
font-family: 'Lato', sans-serif;
}
/* Clear fix hack */
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.clear {
clear: both;
}
/******************************************
/* MAIN LAYOUT
/*******************************************/
/******************************************
/* NAVBAR
/*******************************************/
nav{
height: 65px;
background-color: rgba(245,249,252,255)
}
.container_nav{
max-width: 1750px;
background-color: rgba(245,249,252,255)
}
nav .container_nav{
display: flex;
justify-content: space-between;
align-items: center;
margin: 0 auto;
}
a{
text-decoration: none;
}
.container_nav a{
padding: 0 0 0 2rem;
}
button{
width: 80px;
height: 30px;
background-color: rgb(47, 70, 88);
border: none;
color: white;
}
/******************************************
/* MAIN
/*******************************************/
main{
height: 1000px;
background-color: aqua;
}
.left{
display: flex;
width: 30%;
height: 35rem;
background-color: blueviolet;
padding: 2rem;
flex-direction: column;
justify-content: center;
}
.left span{
color: rgba(150,167,183,255);
}
.right{
display: flex;
background-color: orange;
}
.container_main{
max-width: 1750px;
margin: 0%;
}
main .container_main{
display: flex;
justify-content: flex-end;
}
/******************************************
/* GENERAL STYLES
/*******************************************/
li{
list-style: none;
display: inline-block;
}
.container_nav .first{
padding: 0;
}
ul{
padding: 0;
}
Margin even though there isn't any.
I figured it out thanks to the help of niorad.
It was my max-width. When I removed it solved my problem and everything worked just fine!
I have almost finished my web dashboard which can be seen here. Here is the source code. The last few bits I would like to improve are the mobile adaptation of the navbar and the footer. I'm I struggling to position elements properly, and on some devices, it looks worse than on others. I'm not the best when it comes to CSS yet, so I need a little bit of help here.
Few issues I have is the title not being positioned correctly:
.
I would like it to be positioned so the distance between the top and bottom is equal. And I want it to be at the same distance from the left as the burger button is from the right.
Same problem with the footer. it doesn't look very well organized:
or even worse:
I want these elements to be on an equal distance between top and bottom and never overlap, preferably all in one line. I'm sure there is a number of solutions here, but any solution that is simple and makes it looks more organized will be appraciated.
One thing I need to mention is that HTML elements are defined in Python code in Plotly Dash environment, but I'm pretty sure it makes no difference.
I'm attaching some of the Plotly HTML and CSS code here, but the full code is here:
HTML Code of the navbar:
app.layout = html.Div([
html.Nav([
html.Div("Covid-19 global data Dashboard", className="dashboard-title"),
html.A(
id="toggle-button",
children=[
html.Span(className="bar"),
html.Span(className="bar"),
html.Span(className="bar"),
],
href="#",
className="toggle-button"),
html.Div(
id="navbar-links",
children=html.Ul(
children=[
html.Li(html.A("Home", href=homeURL)),
html.Li(html.A('Source Code', href=sourceCodeURL)),
html.Li(html.A("CSV Data", href=sourceDataURL))]),
className="navbar-links active"
)]
HTML Code of the footer:
html.Footer([
html.Div("created by Sebastian Meckovski", id='footer-text'),
html.Div([
html.P(['Find Me On:'], id='find-me-on'),
html.A([html.Img(src=app.get_asset_url('linkedInLogo.png'), style={'height': '2rem'})],
href=linkedInURL),
html.A([html.Img(src=app.get_asset_url('facebookLogo.png'), style={'height': '2rem'})],
href=facebookURL)
], id='footer-links')
CSS Desktop view:
body {
background-color: var(--LightBlue);
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
}
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
background-color: var(--DarkBlue);
color: white;
}
.container {
position: relative;
min-height: 100% ;
}
.dashboard-title{
font-size: 1.2rem;
margin: .5rem;
}
.navbar-links ul{
margin: 0;
padding: 0;
display: flex;
}
.navbar-links li {
list-style: none;
}
.navbar-links li a{
text-decoration: none;
color: white;
padding: 1.5rem;
display: block;
}
.navbar-links li a:hover{
background-color: var(--DarkBlueHover);
}
.toggle-button{
position: absolute;
top: .8rem;
right: 1rem;
display: none;
flex-direction: column;
justify-content: space-between;
width: 30px;
height: 21px;
}
.toggle-button .bar{
height: 3px;
width: 100%;
background-color: white;
border-radius: 10px;
}
#footer {
position: absolute;
display: flex;
justify-content: space-between;
align-items: center;
bottom: 0;
width: 100%;
background: var(--DarkBlue);
color: white;
height: 3.5rem;
}
#footer-links{
display: flex;
}
#find-me-on{
padding-right: 20px;
font-size: .8rem;
}
#footer-text {
margin: .5rem;
font-size: .8rem;
}
Mobile View:
#media only screen and (max-width: 500px) {
.dashboard-title {
font-size: 1rem;
padding-right: 80px;
}
.toggle-button {
display: flex;
}
.navbar-links {
display: flex;
width: 100%;
}
.navbar{
align-items: center;
flex-direction: column;
min-height:45px;
}
.navbar-links ul {
width: 100%;
flex-direction: column;
}
.navbar-links li{
text-align: center;
}
.navbar-links li a{
padding: .5rem 1rem;
}
.navbar-links.active {
display: none;
}
H2{
font-size: 15px;
}
#footer-text {
margin: .5rem;
font-size: .8rem;
}
#find-me-on{
padding-right: 15px;
}
}
For .navbar class set justify-content property to center, because if you set flex-direction to column, it "rotates" view object, so align-items starts working horizontally.
so:
.navbar{
justify-content: center;
flex-direction: column;
min-height: 45px;
}
And now for navbar horizontal centering: because you set .toggle-button to be absolute, it is set 1rem from right side, while .dashboard-title is centered inside of its parent. To fix this you can simply change margin inside of .navbar class to 1rem, it's now at 0.5rem; Also make sure that .navbar is not centered horizontally by its parent.
After these corrections navbar looks like this:
And for the footer it's also flexbox case. Your images are inside of a element, so you have to vertically center a content.
Image below is only in preview debugging purposes, set your CSS where you previously did.
a{
display: flex;
align-items: center; // Now all <a> element children are centered vertically.
}
I would like to have an element that grow and reduce to the dimension of its content only with css rules.
Here an example:
ul {
list-style: none;
padding: 1rem 1rem 1rem 0;
background-color: lightblue;
max-height: 300px;
display: inline-flex;
flex-flow: column wrap;
align-items: flex-start;
width: 238px;
}
ul li {
width: 100px;
border: 1px solid red;
margin-left: 1rem;
}
/* HTML */
<ul>
<li>item</li> // repeated n times
</ul>
https://codepen.io/mt_dt/pen/GRJYaNj?editors=1100
It should be something like that:
https://ibb.co/6wmYkGX
If you want to have each element on the list to be as wider as the ul element, you need to remove hardcoded height and flex properties (they have no use) from the ul element and set width: 100%; on the lis:
ul {
list-style: none;
padding: 1rem 1rem 1rem 0;
background-color: lightblue;
width: 235px;
}
ul li {
width: 100%;
border: 1px solid red;
margin-left: 1rem;
}
Have a look to this codepen. Hope it helps!
How do I make this ul take up the whole width on the web page, no matter what width the window is?
http://jsfiddle.net/32hp1w5p/
ul {
grid-column: 1/13;
list-style-type: none;
display: table;
margin: 0 auto;
}
li {
float: left;
border: 1px solid red;
}
li a {
font-family: 'Montserrat', sans-serif;
font-size: 20px;
color: black;
text-align: center;
padding: 14px 14px;
text-decoration: none;
display: inline-block;
}
<ul>
<li><a>ONE</a></li>
<li><a>TWO</a></li>
<li><a>THREE</a></li>
</ul>
In this jsfiddle there is three li. I'd like every li in this case take up 33% of the total width, and together they fill out the whole width of the web browser window
you made a typo and added margin (makes element shrinks and centers) aside wrong display choices:
That's a lot mistakes and wrong approach ... welcome to the fun of CSS, added a few comments.
body {
/* added the parent grid CSS system */
display: grid;
grid-template-columns: repeat(13, 1fr);
}
ul {
grid-column: 1 / span 13;
/* span is: the typo / missing */
list-style-type: none;
display: flex;
/* lets make it a flexbox,
a grid will do too ,
so would a table at width:100%
if table-layout is set to fixed
and li displayed as table-cell */
margin: 0;/* none or 0, but not auto */
padding: 0;/* might be usefull here ;) */
}
li {
flex: 1;
/* share evenly avalaible space */
border: 1px solid red;
}
li a {
font-family: 'Montserrat', sans-serif;
font-size: 20px;
color: black;
text-align: center;
padding: 14px 14px;
text-decoration: none;
display: /*inline-*/block;/* to fill parent's width */
}
<ul>
<li><a>ONE</a></li>
<li><a>TWO</a></li>
<li><a>THREE</a></li>
</ul>
You can use width: 100vw for your ul, that means, that the element with this rule should take the width of the screen. If you also want to exclude the width of margins or other elements, you can use something like this: width: calc(100vw - widthToExclude);.
Here is a live example (I use calc(33.3vw - 2px);, because lis also have border-left: 1px and border-right: 1px):
body {
margin: 0;
}
ul {
list-style-type: none;
display: table;
margin: 0;
padding: 0;
}
li {
float: left;
border: 1px solid red;
width: calc(33.3vw - 2px);
}
li a {
font-family: 'Montserrat', sans-serif;
font-size: 20px;
color: black;
text-align: center;
padding: 14px 14px;
text-decoration: none;
display: inline-block;
}
<ul>
<li><a>ONE</a></li>
<li><a>TWO</a></li>
<li><a>THREE</a></li>
</ul>