Problems with buttons / grid in HTML/CSS - html

i have problems with the setup of the buttons. I'm unsure if i need a grid system or not?
I want it to look like this example:
No code yet as i am unsure of where to start, and what to start with.
If somebody can help then hanks in advanced!

You can use with flex, justify-content, align-items like example below:
.wrapped {
display: flex;
flex-direction: column;
align-items: center;
width: 500px;
}
.avatar {
width: 50px;
height: auto;
}
button {
width: 200px;
}
.div1 {
display: flex;
justify-content: center;
padding: 10px;
}
.div2 {
display: flex;
flex-direction: column;
padding: 10px;
}
.div2 button{
width: 200px;
margin: 6px;
padding: 5px;
}
.div3 {
display: flex;
padding: 10px;
margin-left: 0px;
align-items: center;
}
.div3 button {
width: 40px;
height: 30px;
margin-left: 160px;
}
.bell {
width: 30px;
padding: 10px;
flex-basis: 1000px;
}
<section class="wrapped">
<div class="div1">
<button>At campus</button>
<img class="avatar" src="https://media.istockphoto.com/vectors/user-icon-flat-isolated-on-white-background-user-symbol-vector-vector-id1300845620?k=20&m=1300845620&s=612x612&w=0&h=f4XTZDAv7NPuZbG0habSpU0sNgECM0X7nbKzTUta3n8=" />
</div>
<div class="div2">
<button>Q & A</button>
<button>Klasser</button>
<button>Grupper</button>
<button>Chat</button>
</div>
<div class="div3">
<img class="bell" src="https://www.iconpacks.net/icons/1/free-bell-icon-860-thumb.png"/>
<button>Help</button>
</div>
</section>

for sure a grid would perfectly work for your design. However,you don't explicitly need a grid to obtain that result. Css flexbox display (display:flex) would also work and maybe fit your needs. Even display: block would work.
If you need a web layout that only consists of rows or columns, then Flexbox is the best model to use. However, if you have a complex, multi-row and multi-column layout, then you'll want to use CSS Grid.
Have a look for more details: https://www.webdesignerdepot.com/2018/09/grid-vs-flexbox-which-should-you-choose/
Here is a simple set-up for your design with flexbox in mind:
Suppose your first component (logo and user profile) are inside one div. You can use display:flex and flex-direction: row to display them in one line, and justify-content: space-between so the elements fill the entire row.
Then you have 4 buttons. You can use another div and set the flex-direction to column. Change the width of the div and of the buttons as you need.
Basically, the last div would be similar to the first one.
For each div you can specify different width or height.

Related

How can I make this layout responsive?

<div class="parentdiv">
<div><img src="img/noimage.png"></div>
<div class="bottom">
<p class="text1">Text1</p>
<div class="btn_area">
Text2
Text3
</div>
</div>
</div>
I've barely managed to make this layout with bunch of floats, margins, tops and lefts but the layout breaks at practically any other screen ratios.
I feel that I shouldn't be spamming float and margins when creating a layout. Are there any better options to build such layout that does not break catastrophically on ratio change?
I've tried googling but what I've found was mostly making asingle div or image responsive which I've succeeded, but can't apply it to my layout.
Try this out and see if you understand whats going on. I will also add a Tutorial for CSS-Flex as a link at the bottom. Make sure that you always post the code you have, that means HTML and CSS for a CSS Question etc. Im just answering directly here cause your Question implies, that you just tried floats. This solution here probably requires you to change some things to perfectly fit, so you can practice a bit with it:
body {
width: 100vw;
height: 100vh;
/*We need a fixed height and width of the parent-Element to make % values work in the child elements*/
}
.parentdiv {
width: 100%;
/*Careful, when your Content inside of this gets close to the maximum width and height of this div you need to change width: 100% or the layout will overflow*/
padding: 25px;
height: 50%;
/*This makes the Element a Flexbox-Element*/
display: flex;
/*sets the direction and the behaviour*/
flex-flow: row nowrap;
}
.left-area {
width: 40%;
display: flex;
flex-flow: row nowrap;
/*the following 2 attributes define where the content is positioned inside the Flexbox-element*/
justify-content: start;
align-items: start;
}
.left-area img {
width: 6rem;
height: 6rem;
/*I used the border to make the Img Look like yours cause i dont have the file*/
border: 1px solid grey;
border-radius: 50%;
}
.text1 {
font-size: 1.5rem;
color: grey;
font-weight: bold;
}
.right-area {
width: 15%;
height: 50%;
display: flex;
/*Column-Reverse means that you have a column but you start at the bottom of it, like it is standing on its head*/
flex-flow: column-reverse nowrap;
}
.btn_area{
width: 100%;
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
}
.text2 {
font-size: 1.2rem;
color: #7ad0bc;
font-weight: bold;
}
.text3 {
font-size: 1.2rem;
color: #d96060;
font-weight: bold;
}
<div class="parentdiv">
<div class="left-area">
<img src="img/noimage.png" alt="no image available">
<p class="text1">Text1</p>
</div>
<div class="right-area">
<div class="btn_area">
Text2
Text3
</div>
</div>
</div>
Tutorials for CSS-Flex: Tutorial Help-sheet

How can I add a partition that looks wavy without using an image?

So I am trying to make a front page. But first I would like to partition the page into 2 sections, but in reality 3. SO one would be, say color A, and the div would have an animation in it. The second would just blend the two pages together, eg below. Third div would be color B, with an animation.
Here is an example I have made on paint:
Now here is what I currently have:
Perhaps it would be a good idea to include some code with this question. I am using handlebars so I will only add the part that determines the sizing of the three divs.
HTML:
<head>
<link rel="stylesheet" href="../../public/css/frontpage_section_1.css">
</head>
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
CSS:
.first {
height: 100%;
width: 40%;
display: flex;
flex-flow: column;
padding: 5px;
float: left;
}
.second {
height: 100%;
width: 20%;
display: flex;
flex-flow: column;
padding: 5px;
float: left;
overflow: hidden;
}
.third {
height: 100%;
width: 40%;
display: flex;
flex-flow: column;
padding: 5px;
float: left;
background-color: #161717
}
I have tried using images, SVGs, and with those options it's been hard to get them to stretch to the full size of the div at all times. That and I would like to go with something more pure css and html rather than files. I would love to get some advice on what I should look into to make the partition look good (or well to even exist).

How to center multiple images at the center of a page in HTML?

I want to center 4 boxes at the center of a page, i.e., they should be vertically centered and horizontally, one box should be at extreme left, one at extreme right and the left ones should be placed horizontally between the extreme ones.
I know that such a question have been asked before, but I am not getting the exact logic of the solution. Can someone please give a proper explanation for the same? Thanks a lot.
Here's the HTML code-
.cards div{
height: 200px;
width: 200px;
float: left;
text-align: center;
margin-left: 100px;
}
.card_1{
background-color: green;
}
.card_2{
background-color: blue;
}
.card_3{
background-color: yellow;
}
.card_4{
background-color: red;
}
<html>
<head>
<link rel="stylesheet" href="second.css">
</head>
<body>
<div class="cards">
<div class="card_1">
</div>
<div class="card_2">
</div>
<div class="card_3">
</div>
<div class="card_4">
</div>
</div>
</body>
</html>
Here is a solution using flexbox:
html, body {
height: 100%;
padding: 0;
margin: 0;
}
.cards {
width: 100%;
height: 100%;
align-items: center;
display: flex;
flex-direction: row;
justify-content: space-between;
}
.cards div {
height: 200px;
width: 200px;
}
.card_1 {
background-color: green;
}
.card_2 {
background-color: blue;
}
.card_3 {
background-color: yellow;
}
.card_4 {
background-color: red;
}
More information about flexbox:
A Guide To Flexbox
Flexbox Froggy
JSFiddle
Edit
The secret to this solution is
align-items: center;
display: flex;
flex-direction: row;
justify-content: space-between;
display: flex; instructs the browser to use a flexbox layout when rendering your container element. flex-direction: row; renders all children of the container in a row. align-items: center; vertically centers the children of the container. And finally justify-content: space-between; spaces each child of the container with equal space in between each.
Flexbox is a powerful layout system. I would recommend learning more about it through SO or the provided links.
Keep in mind that flexbox is supported across all major browsers but IE 11 has limited support due to several bugs.

Fix display value changing on child of flexbox. Inline-block being overridden

I've recently starting using flexbox and this is the first problem I've run into. I want my .wrp class below to remain display: inline-block; but one line seems to disable this value. That line is: flex-direction: column. When I remove that line my .wrp class starts behaving like an inline-block element again but then of course it loses it's flex-direction value. Is there a simple solution that doesn't require restructuring my HTML too much to keep the flex-direction behavior of flexbox but also keep the inline-block behavior on .wrp?
.contr {
display: flex;
flex-direction: column; /* this line seems to be breakig my display on .wrp */
justify-content: center;
height: 10rem;
background-color: #eee;
}
.wrp {
display: inline-block;
height: 5rem;
background-color: #ddd;
}
p {
width: 100%;
background-color: #ccc;
}
<div class="contr">
<div class="wrp">
<p>I want this paragraph to stretch to fit it's content. Not full width.</p>
</div>
</div>
You can't have an inline-block element within a flex. It looks like you may be looking for display: inline-table:
.contr {
display: flex;
flex-direction: column; /* this line seems to be breakig my display on .wrp */
justify-content: center;
height: 10rem;
background-color: #eee;
}
.wrp {
display: inline-table;
height: 5rem;
background-color: #ddd;
}
p {
width: 100%;
background-color: #ccc;
}
<div class="contr">
<div class="wrp">
<p>I want this paragraph to stretch to fit it's content. Not full width.</p>
</div>
</div>
Hope this helps! :)

Flexbox wrap - different alignment for last row

I'm using flex box to align two items to left and right of the container, while vertically centre-aligning them. Here's a very simple example of what I'm trying to achieve.
HTML:
<div class="container">
<div class="first"></div>
<div class="second"></div>
</div>
CSS:
.container {
width:100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
.first {
background-color: yellow;
width: 200px;
height: 100px;
}
.second {
background-color: blue;
width: 200px;
height: 100px;
}
Here's the jsfiddle of the example.
This works perfectly well if the screen is wide enough to fit both internal divs on one row. However when the screen size is small (e.g. a mobile phone) and the divs wrap onto the second line, the second one also becomes aligned to the left side (i.e. flex-start). How can I force the second div to always be aligned against the right border, regardless of whether it's on the first row or wrapped onto the second one?
EDIT: In the example, I assigned fixed width to the two child elements - this is for simplicity only. In the real life application, all widths are dynamically changing based on the content read from the database at run-time. Hence, any solution that's based on fixed sizes will not work.
You can try adding some left margin to push your .second element to the right:
.second {
margin-left: auto;
}
.container {
width:100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
.first {
background-color: yellow;
width: 200px;
height: 100px;
}
.second {
background-color: blue;
width: 200px;
height: 100px;
margin-left: auto;
}
<div class="container">
<div class="first"></div>
<div class="second"></div>
</div>
Or, similarly, justify all elements to the right but push .first element to the left:
.container {
justify-content: flex-end;
}
.first {
margin-right: auto;
}
.container {
width:100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-end;
align-items: center;
}
.first {
background-color: yellow;
width: 200px;
height: 100px;
margin-right: auto;
}
.second {
background-color: blue;
width: 200px;
height: 100px;
}
<div class="container">
<div class="first"></div>
<div class="second"></div>
</div>
I found a solution but it is rather "hacky" in nature (see demo here, explanation later), in the sense that it requires you to explicitly know the width of the parent container which will trigger a layout change based on #media.
The reason why your code is not working is because of the confusion over how align-self works. In the flexbox model, "align" refers to alignment along the cross-axis (i.e. in a conventional sense of a "row" layout direction, that will refer to vertical alignment), while "justify" refers to alignment along the main axis (i.e. the row). To better explain my point, I hereby attach an image made by Chris Coyier from his flexbox guide:
Therefore, align-self: flex-start means telling the .first to align to the top of the container, and align-self: flex-end means telling .second to align to the bottom of the container. In this case, since you have not declared an explicit height for the parent, the parent will take on the height of its tallest child. Since both .first and .second are 100px tall, the parent will also have a computed height of 100px, therefore making no difference in the alignment (because both with be flush with the start and end of the cross axis).
A hack would be switching the flex-direction to row, with the following restrictions: You know how wide your container will be, or the explicit widths of its children. In this case the breakpoint will be at 400px, where .first and .second will intersect each other.
.container {
width:100%;
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: space-between;
height: 100px;
}
.first {
background-color: yellow;
width: 200px;
height: 100px;
align-self: flex-start;
}
.second {
background-color: blue;
width: 200px;
height: 100px;
align-self: flex-end;
}
#media screen and (max-width: 400px) {
.container {
height: 200px;
}
}
Then again, here is a proof-of-concept fiddle, modified from your original one: http://jsfiddle.net/teddyrised/cncozfem/2/