How to improve my HTML layout?

Asked

Viewed 154 times

3

Gentlemen(as), I need to make the following rectangles below in html, can instruct me what would be the best option indicated?Painel de metas por pessoa

body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}
body {
    
    background-size: cover;
}
.container {
    width: 380px;
    height: 160px;
    display: grid;
    grid-template-columns: 1fr 1fr;
}
.container div {
    border: 1px solid black;
    display: flex;
    justify-content: center;
    align-items: center;
}
.rel, .acu {
    grid-column: span 2;
    background-color: red;
}
<div id="row1">

    <div class="container">
        <div class="marca">Felipe Cardoso</div> 
        <div class="meta">Meta</div>
        <div class="rel">Realizado</div>
        <div class="acu">100%</div>
    </div>
    
</div>

The closest I could get was this piece of code that I’m using, but want in the format of the image attached, if you can tell me what is the ideal function to use in this case, thank you.

  • Are you using any framework?

  • I am developing from JSP @Joãopedroschmitz

  • I mean the CSS

  • @Joãopedroschmitz, I am not using any Framework as for example Bootstrap, I am doing direct.

  • @Joãopedroschmitz but I have the Bootstrap library all installed with Node.js, etc, but not yet used, you would have some function inside that would fit in this my project?

  • 1

    Gabriel as this layout works linear from left to right and with an item after another I think the flex would be better than the grid, until you notice that the fifth item is centered in the middle of the screen, with Grid vc can not centralize :last-Child this way. This answer will help you understand what I’m saying. https://answall.com/questions/327488/flexbox-css-grid/327518#327518 I’ll see if I do an example of this layout for you. For this layout I still see no advantage in using Bootstrap... unless it was already installed in use in other parts of the system

  • Show @hugocsl, I’ll check out this topic you gave me.

  • @hugocsl if you can forward me an example of flex with my project I thank you.

  • Give a look there in the answer, qq doubt comments there that I help you

Show 4 more comments

1 answer

5


For this particular case, as I mentioned in the comment, I would point out to you the flexbox and not the grid, as you can see in this question the Grid will not give you the possibility to align the last item in the center of the container Flexbox + CSS GRID

Now about the model I assembled, the main thing is you use the flex-grow, so that each of the parts of the .box has its size proportional to another, in case I used values 3, 2, and 1, it means that between the parts there is a proportion between the widths, which can vary depending on the size of the content inside the cell, because the flex is flexible with respect to that.

Already in the label "about" the .box I used a pseudo element ::after in the .p2 and with in the content:" " of him I put the text who needs.

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}
.jumbo {
	background-image: url(https://unsplash.it/600/300);
	background-size: cover;
}
.container {
  width: 90%;
  margin: 0 auto;
  box-sizing: border-box;
  border: 1px solid red;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  padding-top: 1rem;
}
.box {
  width: calc(50% - 2rem);
  height: 2rem;
  margin: 1.5em 1em;
  box-sizing: border-box;
  border: 1px solid black;
  display: flex;
}
.p1, .p2, .p3 {
  display: flex;
  align-items: center;
  justify-content: center;
  color: red;
  font-family: sans-serif;
  font-weight: bold;
  background-color: #ffffff;
}
.p1 {
  flex-grow: 3;
}
.p2 {
  flex-grow: 2;
  background-color: red;
  color: #fff;
  position: relative;
}
.p3 {
  flex-grow: 1;
}
.p2::after {
  content: "texto";
  width: 100%;
  height: 1.5em;
  position: absolute;
  top: -1.5em;
  left: 0;
  background-color: red;
  line-height: 1.5em;
  text-align: center;
  box-shadow: inset 0 0 0.2em rgba(0, 0, 0, 0.5);
}

@media only screen and (max-width: 580px) {
  .box {
    width: calc(100% - 2rem);
  }
}
<div class="jumbo">
	<div class="container">
		<div class="box">
			<div class="p1">
			grow 3
			</div>
			<div class="p2">
			grow 2
			</div>
			<div class="p3">
			grow 1
			</div>
		</div>

		<div class="box">
			<div class="p1">
			texto1
			</div>
			<div class="p2">
			texto2
			</div>
			<div class="p3">
			texto3
			</div>
		</div>

		<div class="box">
			<div class="p1">
			texto1
			</div>
			<div class="p2">
			texto2
			</div>
			<div class="p3">
			texto3
			</div>
		</div>
	</div>
</div>


To do the part Responsive you can use the @media, see how it should be around, on screens smaller than 580px each .box should occupy 100% of the container.

inserir a descrição da imagem aqui

  • That’s basically what I needed, ball show. I will play my project with this foundation that you gave me, in case new questions arise I ask new questions, thank you very much.

  • 2

    @Gabrielpaixãojustino delay, if you have any questions or want some clarification just speak.

  • Do you know how I can add a spacing between them ? For example in my image, the first row of the box has a spacing for the second, I’m trying to space but it’s warping.

  • 1

    @Gabrielpassion Justino works like this, what you add of margin you have to add in calc() of width. Example if you increase the margin between the boxes to 3rem,in the calc you have to put calc(100% - 6rem) - IS 6rem pq is 3rem margin on the right and 3rem on the left. So we have 100% less right and left margins? Qq thing speaks there!

  • could you tell me where I can insert a background image ? I need to insert this background image in my project, and these Divs will be "alive" in my panel, I’m inserting in . container, but the image is not getting correct.

  • @Gabrielpaixon what problem is the image presenting? You’re using it as a <img> inside the container or as background-image container?

  • @hugocls, I’m using as background-image.

  • @hugocls, insert in the first question the image with the problem that is occurring.

  • 1

    @Gabriela Passionno guy I did not understand much that image you posted... it seems that there is an element over the other... I do not know what you got there rss. But I updated the code of the above answer, put another div out of the container, in this div I put a background-image that encompasses the entire container. Look how it turned out.

  • 1

    Excellent, thanks @hugocsl.

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.