still learning flexbox. I can´t find the reason about how the items on the nav element are not vertically aligned with the h1 text. Would love some help! Link for the codepen at the end.
The expected result should be both the nav and the h1, inside the .main-header, vertically aligned.
HTML:
<div class="container">
<header class="main-header clearfix">
<h1>📘 The Code Magazine</h1>
<nav>
<!-- <strong>This is the navigation</strong> -->
Blog
Challenges
Flexbox
CSS Grid
</nav>
</header>
</div>
CCS:
* {
/* border-top: 10px solid #1098ad; */
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
color: #444;
font-family: sans-serif;
border-top: 10px solid #1098ad;
position: relative;
}
.main-header {
background-color: #f7f7f7;
/* padding: 20px;
padding-left: 40px;
padding-right: 40px; */
padding: 20px 40px;
margin-bottom: 60px;
/* height: 80px; */
}
nav {
font-size: 18px;
/* text-align: center; */
}
h1,
h2,
h3 {
color: #1098ad;
}
h1 {
font-size: 26px;
text-transform: uppercase;
font-style: italic;
}
a:link {
color: #1098ad;
text-decoration: none;
}
a:visited {
/* color: #777; */
color: #1098ad;
}
a:hover {
color: orangered;
font-weight: bold;
text-decoration: underline orangered;
}
a:active {
background-color: black;
font-style: italic;
}
nav a:link {
/* background-color: orangered;
margin: 20px;
padding: 20px;
display: block; */
margin-right: 30px;
display: inline-block;
}
.main-header {
display: flex;
align-items: center;
}
Here is the link for the codepen:
https://codepen.io/Swanbe/pen/OJzpjor
Thanks in advance!
For past 10 minutes, I have been debugging your code.
Wrote another code like this to see if the problem persists. But that was vertically aligned.
So I dug deeper and tried changing and tags. Nothing Great.
....
Until I just removed that blue rubber(Emoji or whatever you call that ) and added a property in nav.
nav {
height: 100px;
display: flex;
flex-direction: row;
align-items: center;}
and that's it.
Try removing that emoji and see if it helps.
Related
There is initial space before the list. And the list is scrollable.
The space from the beginning needs to be removed while scrolling. Is it possible to do so using css?
I initially added padding before the list. But the padding is always maintaining it's space.
JSX:
<div class="pt-filter-container">
<div
v-for="(item, index) in items"
:key="index"
class="item"
>
{{ item.label }}
</div>
</div>
CSS:
.filter-container {
display: flex;
width: 30em;
overflow-x: auto;
white-space: nowrap;
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
.item {
font-size: 14px;
font-weight: 500;
letter-spacing: 0;
line-height: 16px;
color: #5A6872;
margin-right: 8px;
padding: 8px 12px;
border: 1px solid #chip-grey;
border-radius: 4px;
background-color: #FAFAFA;
position: relative;
}
.active {
background-color: #red;
color: #white;
}
}
It's just i need to add margin before the 1st element instead of container that is containing it.
So the actual code will be -
.pt-filter-container {
display: flex;
width: 30em;
overflow-x: auto;
white-space: nowrap;
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
.pt-item {
font-size: 14px;
font-weight: 500;
letter-spacing: 0;
line-height: 16px;
color: #5A6872;
margin-right: 8px;
padding: 8px 12px;
border: 1px solid #pt-chip-grey;
border-radius: 4px;
background-color: #FAFAFA;
position: relative;
&:first-child {
margin-left: 18px;
}
}
.active {
background-color: #pt-red;
color: #pt-white;
}
}
I don't know the exact dom and css structure of your project. But can't you use something like this?
overflow-x: hidden
or
ul > li: first-child {
padding-left: 0;
}
So it's the first time I use CSS (been looking through some documentation) and I have this problem.
I created a navigation menu, a horizontal one on the right side, and I want to have the website title on the left side, inline with it. I tried a few things, but it either gets it up and moves the menu lower, or places it under the menu.
Last thing I tried worked but it seems that I can't use the padding-top property anymore (however, I can use padding-left). I would be grateful if any of you could help me with this last thing. Thank you!
The CSS code: (it's messy, I know, as I said, my first one :) )
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
position: relative;
padding-top: 10px;
padding-right: 50px;
}
li {
float: right;
font-family: 'Raleway';
font-size: 20px;
}
a {
display: block;
padding: 20px;
background-color: transparent;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
a:hover {
color: orangered;
}
/* Logo */
#logo {
float: left;
display: inline-block;
position: relative;
padding-left: 200px;
padding-top: -250px;
font-family: 'Raleway';
font-size: 30px;
}
/* Fonts */
#font-face {
font-family: Raleway;
src: url(/css/fonts/raleway.ttf);
}
First, you can't put a <p> inside a <ul>.
You can achieve what you want by putting the logo inside a <li> and use float:left;.
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
position: relative;
padding-top: 10px;
padding-right: 50px;
}
li {
float: right;
font-family: 'Raleway';
font-size: 20px;
}
a {
display: block;
padding: 20px;
background-color: transparent;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
a:hover {
color: orangered;
}
/* Logo */
#logo {
float: left;
font-size: 30px;
}
/* Fonts */
#font-face {
font-family: Raleway;
src: url(/css/fonts/raleway.ttf);
}
<ul>
<li id="logo">Cluj</li>
<li>CONTACT</li>
<li>IMAGINI</li>
<li>STIRI</li>
<li>EVENIMENTE</li>
<li>ACASA</li>
</ul>
Hi SO I have what one day might be used on my web page that is a block of tabs (very basic currently) and I want them to be aligned in such a way that there is 5 blocks on the first line and 4 blocks on the second but they both align horizontally to end at the same point (so it doesn't look like one is missing)
here is a link to what I have currently http://jsfiddle.net/xs8d6zuh/2/
html -
<span>twenty letters long</span>
<span>twelve lette</span>
<span>eight123</span>
<span>ten letter</span><br></br>
<span>twenty letters long!</span>
<span>sixteen letters!</span>
<span>1seven</span>
<span>sixsix</span>
CSS -
a {
text-decoration: none;
color: #000000;
border: 2px;
background-color: #f6f0e0;
font-family: Arial;
font-size: 14px;
padding: 6px;
border: 1px solid;
border-color: #d5c898;
display: inline;
width: 123px;
text-align: center;
}
a:hover {
background-color: #000000;
color: #f6f0e0;
}
<div class="container">
Bavaria
twenty letters long
twelve lette
eight123
ten letter
twenty letters long!
sixteen letters!
1seven
sixsix
</div>
CSS
.container {
font-size: 0px;
}
a {
text-decoration: none;
text-align: center;
color: #000000;
background-color: #f6f0e0;
font-family: Arial;
font-size: 14px;
padding: 6px;
border: 1px solid #d5c898;
display: inline-block;
}
a.five {
width: calc(20% - 14px);
}
a.four {
width: calc(25% - 14px);
}
a:hover {
background-color: #000000;
color: #f6f0e0;
}
https://jsfiddle.net/xs8d6zuh/2/
use calc() function
"for first 4 use width:calc(100% / 4);
for remaining 3 use width:calc(100% / 3);"
if u have 7 span elements
Flexbox can do that:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
display: flex;
flex-wrap: wrap;
}
span {
flex: 1 0 20%;
display: block;
text-align: center;
}
a {
display: block;
text-decoration: none;
color: #000000;
border: 2px;
padding: 6px;
background-color: #f6f0e0;
font-family: Arial;
font-size: 14px;
border: 1px solid;
border-color: #d5c898;
}
a:hover {
background-color: #000000;
color: #f6f0e0;
}
<div class="container">
<span>Bavaria</span>
<span>twenty letters long</span>
<span>twelve lette</span>
<span>eight123</span>
<span>ten letter</span>
<span>twenty letters long!</span>
<span>sixteen letters!</span>
<span>1seven</span>
<span>sixsix</span>
</div>
JSfiddle Demo
I have built a Ruby on Rails site based off the RailsTutorial. I'm trying to change a few colors, but I can't figure it out.
I would like to change the background color [body of page] and the color of the menu text. Where can I do this?
my current custom.css.scss:
#import "bootstrap";
/* mixins, variables, etc. */
$grayMediumLight: #eaeaea;
#mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
/* universal */
html {
overflow-y: scroll;
}
body {
padding-top: 60px;
}
section {
overflow: auto;
}
textarea {
resize: vertical;
}
.center {
text-align: center;
h1 {
margin-bottom: 10px;
}
}
table td {
padding:0px 25px 0px 0px;
}
table th {
text-align: left;
padding:0px 25px 0px 0px;
}
/* bootstrap */
.navbar-inner {
background-color: white; /* background color will be black for all browsers */
background-image: none;
background-repeat: no-repeat;
filter: none;
}
/* typography */
h1, h2, h3, h4, h5, h6 {
line-height: 1;
}
h1 {
font-size: 3em;
letter-spacing: -2px;
margin-bottom: 30px;
text-align: center;
}
h2 {
font-size: 1.2em;
letter-spacing: -1px;
margin-bottom: 30px;
text-align: center;
font-weight: normal;
color: $grayLight;
}
p {
font-size: 1.1em;
line-height: 1.7em;
}
p2 {
font-size: 1.1em;
line-height:1.7em;
font-weight: bold;
}
/* header */
#logo {
float: left;
margin-right: 10px;
font-size: 1.7em;
color: black;
letter-spacing: -1px;
padding-top: 9px;
font-weight: bold;
line-height: 1;
&:hover {
color: white;
text-decoration: none;
background-color: black;
}
}
...
thanks
Bootstrap has a lot of customization by default. You can find all the options here http://getbootstrap.com/customize/
Just use sass variables instead of less.
$body-bg: #fff;
$navbar-default-color: #000;
$navbar-default-link-color: #000;
and so on… You will get what you want
to change color of navbar
.navbar {
background-color: red;
}
to change navbar nav links color
.navbar-nav > li > a {
color: blue;
}
try
div.navbar{
background: red;
color:#fff
}
Change the colors to your needs.
I'm using a navigation bar for a project I'm working on. I've always had trouble with horizontal navigation bars, and I've looked everywhere for the right solution, without success. The navigation bar was shifted to the left, so I put in some padding in my css, and now it's centered, however the text is not centered in it, and the hover effect for the first link doesn't cover the whole 'box' the text is in.
CSS:
/* Entire Document CSS */
html{
height: 100%;
}
/* Header CSS */
.headers{
color: #FFFFFF;
text-align: center;
padding: 30px;
margin-bottom: 0px;
margin-top: 0px;
background-color: #63B8FF;
}
.headers2{
color: #FFD89A;
text-align: center;
padding: 10px;
}
/* Body CSS */
.body{
background-color: #61B329;
height: 50%;
color: #FFFFFF;
}
.container{
margin-left: auto;
margin-right: auto;
width: 50em;
text-align: center;
padding-bottom: 500px;
height: 50%;
}
/* Navigation CSS */
.nav{
display: inline-block;
background-color: #00B2EE;
border: 1px solid #000000;
border-width: 1px 0px;
margin: 0px 0px 0px 0px;
}
.nav li{
display: inline-block;
}
.nav a{
display: inline-block;
padding: 10px 110px 10px 0.80px;
text-align: center;
}
/* Footer CSS */
#footer {
clear: both;
position: relative;
z-index: 10;
height: 3em;
margin-top: -3em;
}
#content {
padding-bottom: 3em;
}
/* Link CSS */
a:link{
color: #FFFFFF;
text-decoration: none;
}
a:visited{
color: #FFFFFF;
text-decoration: none;
}
a:hover{
background-color: #028482;
color: #FFFFFF;
text-decoration: overline;
}
a:active{
background-color: #FF9C00;
color: #FFFFFF;
text-decoration: underline;
}
.Links A:hover{
color: #028482;
background-color: transparent;
text-decoration: underline overline;
}
HTML5 (Index Page)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Play - Learn - Grow</title>
<link rel="stylesheet" href="main.css">
</head>
<body class="body">
<h1 class="headers">Welcome to KUBE Toy Library!</h1>
<nav>
<ul class="nav">
<li>Home</li>
<li>About Us</li>
<li>Contact Us</li>
<li>Become a Member</li>
<li>Borrow Toys</li>
<li>Our Policies</li>
<li>Site Map</li>
</ul>
</nav>
<h2 class="headers2">Welcome to the Home Page!</h2>
<div class="container">
Our aim is to provide the children of the community with an ever-changing variety of educational and fun toys to enhance
their cognitive, social, emotional and physical development in the important first six years of their lives.
<br><br><span class="Links">Be sure to check out our Wikispace site with more information here!</span>
</div>
<div id="content"></div>
<div id="footer">
Copyright © 2013
</div>
</body>
</html>
Note that I'm quite new compared to the others here on this forum, so please take it easy on me! :) Also this is a fictional company, etc. for an assignment I was given. Thanks!
Hi your page in my browser was displayed like below
I changed your css to make it browser resolution independent. As a UI developer I felt that overline was not looking good so I removed that. Use my code
/* Body CSS */
.body {
background-color: #61B329;
color: #FFFFFF;
}
/* Header CSS */
.headers {
color: #FFFFFF;
text-align: center;
padding: 30px;
margin: 0;
background-color: #63B8FF;
}
.headers2 {
color: #FFD89A;
text-align: center;
padding: 10px;
}
.container {
margin: 0 auto;
width: 50em;
text-align: center;
padding-bottom: 500px;
}
/* Navigation CSS */
.nav {
display: inline-block;
background-color: #00B2EE;
border: 1px solid #000000;
border-width: 1px 0px;
margin: 0;
padding: 0;
min-width: 1000px;
width: 100%;
}
.nav li {
list-style-type: none;
width: 14.28%;
float: left;
}
.nav a {
display: inline-block;
padding: 10px 0;
width: 100%;
text-align: center;
}
/* Footer CSS */
#footer {
clear: both;
position: relative;
z-index: 10;
height: 3em;
margin-top: -3em;
}
#content {
padding-bottom: 3em;
}
/* Link CSS */
a:link,
a:visited,
a:hover {
color: #FFFFFF;
text-decoration: none;
}
a:hover {
background-color: #028482;
}
a:active {
background-color: #FF9C00;
color: #FFFFFF;
text-decoration: underline;
}
.Links A:hover {
color: #028482;
background-color: transparent;
text-decoration: underline overline;
}
Demo:
http://jsfiddle.net/NphBK/
This is a common problem. But to fix this you need to make the parent text-align: center and give the children display: inline-block;
If you want to have it completely equalizing you'll need to switch to display: table and display: table-cell.