Im new to HTML and im trying to make a row of cards but the cards are staying in a column and not going into a row like my flex-direction should tell them to go.Thanks for the help everybody! I hope i can finish this project :)
I want it to look like this
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
but it looks like this
body {
font-family: 'Open Sans', sans-serif;
}
.shell {
flex-direction: row;
border: 1px solid #EF9A9A;
flex-basis: auto;
margin: 5px;
}
.card {
width: 150px;
display: flex;
flex-direction: column;
border: 1px solid #EF9A9A;
border-radius: 4px;
overflow: hidden;
margin: 0px;
}
.card-header {
color: #D32F2F;
text-align: center;
font-size: 12px;
font-weight: 600;
border-bottom: 1px solid #EF9A9A;
background-color: #FFEBEE;
padding: 5px 10px;
}
.card-main {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 15px 0;
}
.material-icons {
font-size: 36px;
color: #D32F2F;
margin-bottom: 5px;
}
.main-description {
color: #D32F2F;
font-size: 12px;
text-align: center;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.header {
overflow: hidden;
background-color: #FFEBEE;
padding: 20px 10px;
border-bottom: 1px solid #EF9A9A;
border-radius: 4px;
}
.header a {
float: left;
color: #D32F2F;
text-align: center;
padding: 12px;
text-decoration: none;
font-size: 18px;
line-height: 25px;
border-radius: 4px;
}
.header a.logo {
font-size: 25px;
font-weight: bold;
}
.header a:hover {
background-color: #dfd5d7;
color: #942626;
}
.header a.active {
background-color: #D32F2F;
color: #FFEBEE;
}
.header-right {
float: right;
}
@media screen and (max-width: 500px) {
.header a {
float: none;
display: block;
text-align: left;
}
.header-right {
float: none;
}
}
<link href="https://fonts.googleapis.com/icon?family=Material Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open Sans:400,600" rel="stylesheet">
<div >
<a href="#home" >Project-LuLo</a>
<div >
<a href="#home">Home</a>
<a href="#games">Games</a>
<a href="#contact">Contact</a>
</div>
</div>
<div >
<div >
<div >Games</div>
<div >
<i >videogame_asset</i>
<div >Web Based Games</div>
</div>
</div>
<div >
<div >Games</div>
<div >
<i >videogame_asset</i>
<div >Web Based Games</div>
</div>
</div>
</div>
CodePudding user response:
On your class .shell
you had styles to dictate what to do with display: flex;
but the shell class itself also needed to have display flex on it.
body {
font-family: 'Open Sans', sans-serif;
}
.shell{
display: flex;
flex-direction:row;
border: 1px solid #EF9A9A;
flex-basis: auto;
margin:5px;
}
.card {
width: 150px;
display: flex;
flex-direction: column;
border: 1px solid #EF9A9A;
border-radius: 4px;
overflow: hidden;
margin: 0px;
}
.card-header {
color: #D32F2F;
text-align: center;
font-size: 12px;
font-weight: 600;
border-bottom: 1px solid #EF9A9A;
background-color: #FFEBEE;
padding: 5px 10px;
}
.card-main {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 15px 0;
}
.material-icons {
font-size: 36px;
color: #D32F2F;
margin-bottom: 5px;
}
.main-description {
color: #D32F2F;
font-size: 12px;
text-align: center;
}
* {box-sizing: border-box;}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.header {
overflow: hidden;
background-color: #FFEBEE;
padding: 20px 10px;
border-bottom: 1px solid #EF9A9A;
border-radius: 4px;
}
.header a {
float: left;
color: #D32F2F;
text-align: center;
padding: 12px;
text-decoration: none;
font-size: 18px;
line-height: 25px;
border-radius: 4px;
}
.header a.logo {
font-size: 25px;
font-weight: bold;
}
.header a:hover {
background-color: #dfd5d7;
color: #942626;
}
.header a.active {
background-color: #D32F2F;
color: #FFEBEE;
}
.header-right {
float: right;
}
@media screen and (max-width: 500px) {
.header a {
float: none;
display: block;
text-align: left;
}
.header-right {
float: none;
}
}
<!DOCTYPE html>
<head>
<meta charset="utf-8"/>
<title>Project-LuLo</title>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
</head>
<body>
<link href="https://fonts.googleapis.com/icon?family=Material Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open Sans:400,600" rel="stylesheet">
<div >
<a href="#home" >Project-LuLo</a>
<div >
<a href="#home">Home</a>
<a href="#games">Games</a>
<a href="#contact">Contact</a>
</div>
</div>
<div >
<div >
<div >Games</div>
<div >
<i >videogame_asset</i>
<div >Web Based Games</div>
</div>
</div>
<div >
<div >Games</div>
<div >
<i >videogame_asset</i>
<div >Web Based Games</div>
</div>
</div>
</div>
</body>
</html>
CodePudding user response:
The answer above is good but here is a more code-clean way to do the same thing.
I moved the css to a dedicated file for it, as ounce you reach over 25 CSS lines, it becomes pretty dirty and it's better to put it in a different file. Then I deleted styles that were later overwritten and some useless properties. Afterwards I tidied up the html so you can keep track of what divs are in what divs and here is the result.
* {box-sizing: border-box;}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.shell{
border: 1px solid #EF9A9A;
margin:5px;
}
.card {
display: inline-block;
width: 150px;
border: 1px solid #EF9A9A;
border-radius: 4px;
margin: 0px;
}
.card-header {
color: #D32F2F;
text-align: center;
font-size: 12px;
font-weight: 600;
border-bottom: 1px solid #EF9A9A;
background-color: #FFEBEE;
padding: 5px 10px;
}
.card-main {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 15px 0;
}
.material-icons {
font-size: 36px;
color: #D32F2F;
margin-bottom: 5px;
}
.main-description {
color: #D32F2F;
font-size: 12px;
text-align: center;
}
.header {
overflow: hidden;
background-color: #FFEBEE;
padding: 20px 10px;
border-bottom: 1px solid #EF9A9A;
border-radius: 4px;
}
.header a {
float: left;
color: #D32F2F;
text-align: center;
padding: 12px;
text-decoration: none;
font-size: 18px;
line-height: 25px;
border-radius: 4px;
}
.header a.logo {
font-size: 25px;
font-weight: bold;
}
.header a:hover {
background-color: #dfd5d7;
color: #942626;
}
.header a.active {
background-color: #D32F2F;
color: #FFEBEE;
}
.header-right {
float: right;
}
@media screen and (max-width: 500px) {
.header a {
float: none;
display: block;
text-align: left;
}
.header-right {
float: none;
}
}
<!DOCTYPE html>
<head>
<meta charset="utf-8"/>
<title>Project-LuLo</title>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<link rel="stylesheet" href="style.css">
</head>
<body>
<link href="https://fonts.googleapis.com/icon?family=Material Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open Sans:400,600" rel="stylesheet">
<div >
<a href="#home" >Project-LuLo</a>
<div >
<a href="#home">Home</a>
<a href="#games">Games</a>
<a href="#contact">Contact</a>
</div>
</div>
<div >
<div >
<div >Games</div>
<div >
<i >videogame_asset</i>
<div >Web Based Games</div>
</div>
</div>
<div >
<div >Games</div>
<div >
<i >videogame_asset</i>
<div >Web Based Games</div>
</div>
</div>
</div>
</body>
</html>
Hope this is helpful!