I'm making 2 cards in CSS and I want the 2nd one to lay below the 1st one. In order to locate the first card in the middle I created a "card-outer" div, but when I click "inspect element" I see that the height of the outer is more than 900px, and therefore, the 2nd card is +900px lower than the 1st card.
Do you guys have any idea of how can I fix this issue?
It looks like this, and I want only a 50px separation between both:
.card-outer {
display: flex;
justify-content: center;
min-height: 100vh;
}
.card {
width: 500px;
height: 250px;
display: flex;
overflow: hidden;
background: rgb(16, 33, 72);
box-shadow: 0 5px 10px #031e23;
border-radius: 30px;
color: white;
font-family: 'Dosis';
margin-top: 50px;
}
.card .img-card {
background: url(parque.png);
width: 40%;
height: 100%;
background-size: cover;
background-position: 60% 0%;
}
.card .content {
width: 60%;
height: 100%;
display: grid;
grid-template-rows: 50px 150px 50px;
padding: 10px 15px;
}
<div class="card-outer">
<div class="card">
<div class="img-card"></div>
<div class="content">
<div class="titulo">
<h3>Parque Metropolitano</h3>
</div>
<div class="text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Commodi consectetur, accusamus repellat architecto veritatis quis vel harum molestiae tempore ea illo ut sapiente magnam voluptate.
</p>
</div>
<div class="btn-container">
<button>Sitio web</button>
</div>
</div>
</div>
</div>
Assuming the .card-outer is the wrapper for the layout, use the gap property on your .card-outer to make your 50px separate and use justify and align to get the cards where you want them within the wrapper.
If .card-outer isn't a wrapper, create one using the same technique.
.card-outer {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
gap: 50px; /*this guy right here */
}
.card {
width: 500px;
height: 250px;
display: flex;
overflow: hidden;
background: rgb(16, 33, 72);
box-shadow: 0 5px 10px #031e23;
border-radius: 30px;
color: white;
font-family: 'Dosis';
margin-top: 50px;
}
.card .img-card {
background: url(parque.png);
width: 40%;
height: 100%;
background-size: cover;
background-position: 60% 0%;
}
.card .content {
width: 60%;
height: 100%;
display: grid;
grid-template-rows: 50px 150px 50px;
padding: 10px 15px;
}
<div class="card-outer">
<div class="card">
<div class="img-card"></div>
<div class="content">
<div class="titulo">
<h3>Parque Metropolitano</h3>
</div>
<div class="text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Commodi consectetur, accusamus repellat architecto veritatis quis vel harum molestiae tempore ea illo ut sapiente magnam voluptate.
</p>
</div>
<div class="btn-container">
<button>Sitio web</button>
</div>
</div>
</div>
<div class="card">
<div class="img-card"></div>
<div class="content">
<div class="titulo">
<h3>Parque Metropolitano</h3>
</div>
<div class="text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Commodi consectetur, accusamus repellat architecto veritatis quis vel harum molestiae tempore ea illo ut sapiente magnam voluptate.
</p>
</div>
<div class="btn-container">
<button>Sitio web</button>
</div>
</div>
</div>
</div>
Related
[Tree with all its leaves off the brancges[1]
[1]: https://i.stack.imgur.com/hfQGM.png
Im trying to make the image fit to the bottom left and top of the inside border, but not the right i just want it to fit in that certain space.
This is what i have so far...
<section class="winter">
<div class="outside-border">
<div class="section-heading">
<h2>Winter</h2>
</div>
<div class="inside-border">
<div class="winter-image">
<a href="winter.html">
<img src="assets/images/winter.jpg" alt="Winter Image">
</a>
</div>
<div class="section-content">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Impedit dolore enim sequi dignissimos vel fugit
reiciendis minus voluptatem nostrum, at repellat odio libero cum eveniet officiis, cumque veritatis, qui
eaque.</p>
</div>
</div>
</div>
css
.outside-border{
border: 2px solid var(--winter-primary);
margin: auto;
max-width: 1000px;
background-color: white;
padding: 20px;
margin-bottom: 20px;
}
.section-heading{
width: 100%;
background-color: var(--winter-primary);
text-align: center;
}
.section-heading>h2 {
margin: 0;
}
.inside-border{
border: 2px solid var(--winter-primary);
display: flex;
align-items: center;
background-color: var(--winter-light);
}
.section-content{
background-color: var(--winter-light);
}
.winter-image{
display: inline-flex;
background-size: cover;
}
p{
margin-left: 1em;
text-align: center;
padding: 10px;
}
Now im just saying the same thing over and over again because im a stupid newbe coder that is having trouble with this problem. Stack overflow says i need to add more words because all i have is code right now.
try to put margin and padding 0.
hope this helps
.winter-image{
display: inline-flex;
background-size: cover;
margin: 0;
padding: 0;
}
im using a flip box with a front and back content when i hover (rotateY(180deg)) . that worked for simple container (only text) but didn't work when the background was an image this is my first time using nth-child element so any advises are welcome^^.
(its a small screen version for now)
and thanks in advance.
/*
===============
SERVICES
===============
*/
.title-service {
margin-top: 100px;
text-align: center;
}
.title-service p {
margin-top: -30px;
}
.container-service {
width: 70vh;
height: 50vh;
margin-left: 30px;
background: grey;
margin-bottom: 10px;
align-items: center;
text-align: center;
padding-top: 25%;
transform-style: preserve-3d;
transition: 0.3s ease all;
}
.container-service:hover {
transform: rotateY(180deg);
}
.front-card {
backface-visibility: hidden;
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
}
.back-card {
backface-visibility: hidden;
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
transform: rotateY(180deg);
}
.container-service h3 {
color: black;
font-size: 26px;
font-weight: 700;
}
.container-service i {
font-size: 40px;
color: black;
}
.container-service:nth-child(3) {
background-image: url(../Responsive\ Website/img-2.jpg);
background-size: cover;
position: relative;
}
.container-service:nth-child(3) .front-card::after {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: -1;
}
.dev h3 {
color: whitesmoke;
}
.dev i {
color: whitesmoke;
}
<!-- START SERVICES -->
<section class="service">
<div class="info-service">
<div class="title-service">
<h1>SERVICES</h1>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit.</p>
</div>
<div class="container-service web">
<div class="front-card">
<span><i class="fas fa-palette"></i></span>
<h3>Web Design</h3>
</div>
<div class="back-card">
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Libero
maxime, reiciendis, ut earum amet architecto, cum magni cumque eum
repudiandae a minus sunt! Sed porro expedita, fuga aspernatur
molestiae iste ab cupiditate repudiandae cumque officia ea.
Tenetur amet ullam voluptatum?
</p>
</div>
</div>
<div class="container-service f-e">
<div class="dev">
<div class="front-card">
<span><i class="fas fa-laptop-code"></i></span>
<h3>Front Dev</h3>
</div>
<div class="back-card">
<h3>Front Dev</h3>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit
optio, eum esse doloremque molestias aspernatur.
</p>
</div>
</div>
</div>
<div class="container-service branding">
<div class="front-card">
<span><i class="fas fa-building"></i></span>
<h3>Branding</h3>
</div>
<div class="back-card">
<h3>Branding</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Consequuntur, error.
</p>
</div>
</div>
</div>
</section>
<!-- END SERVICES -->
The front and back are stacked above the parent wrapper and have inherited the parent background color, try applying the image to the front card of the third child.
Below i write the code, in this code i want to make responsive 'rectangle' and 'square' and i also want to make resopnsive text in the p tag.
#rectangle
{
display: flex;
width: 500px;
height: 150px;
background-color: brown;
}
#square
{
width: 300px;
height: 130px;
background-color: chocolate;
margin: 10px;
}
<div id="rectangle">
<div id="square">
</div>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aut, iusto. Sapiente fugiat illo
dolorum assumenda commodi!
</p>
</div>
For the widths and heights, use % instead of px. For the text, add an id or class that defines a font using the vw unit. For example:
<div id="rectangle">
<div id="square">
</div>
<p id='text'>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aut, iusto. Sapiente
fugiat illo dolorum assumenda commodi!
</p>
</div>
#rectangle
{
background-color: brown;
display: flex;
height: 8%;
position: relative;
width: 10%;
}
#square
{
background-color: chocolate;
height: 8%;
margin: 10px;
position: relative;
width: 10%;
}
#text
{
font-size: 2vw;
}
Here you go. If you want responsiveness, use % or vh / vw
#rectangle
{
display: flex;
width: 70vw;
height: 40vh;
background-color: brown;
font-size: 2.3vw;
}
#square
{
width: 100%;
height: 100%;
background-color: chocolate;
margin-right: 3%;
display: flex;
align-items: center;
justify-content: center;
}
.arrow-up {
display: flex;
align-items: center;
justify-content: center;
width: 0;
height: 0;
border-left: 10vw solid transparent;
border-right: 10vw solid transparent;
border-bottom: 10vw solid black;
}
<div id="rectangle">
<div id="square">
<div class="arrow-up"></div>
</div>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aut, iusto. Sapiente fugiat illo
dolorum assumenda commodi!
</p>
</div>
Can someone please help me?!
I'm trying to code a PSD file to HTML and CSS, but I'm struggling with one of the sections. Here's an image of what I want to do:
Click Here
The problem is I don't know how to put the image in the timeline line. I tried to add the image in the ::after psuedo, but I don't think this is the right way of doing that.
This is my HTML Code :
<section class="about">
<div class="wrapper">
<h3>About Us</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
<div class="container left">
<div class="content">
<h5>JULY 2010<br> Our Humble Beginnings</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
</div>
<div class="container right">
<div class="content">
<h5>January 2011<br> Facing Startups Battles</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
</div>
</div>
</section>
This is my CSS code:
.about .wrapper{
padding: 80px 10%;
text-align: center;
position: relative;
}
.about .wrapper::after{
content: '';
position: absolute;
top: 200px;
bottom: 0;
width: 6px;
background: red;
}
.about h5{
line-height: 1.5;
font-size: 1em;
padding-bottom: .5em;
}
.about .container{
position: relative;
width: 50%;
top: 60px;
margin: 0 0 60px 0;
}
.about .container::after{
content: 'How Can I Add an Image Here in this circle?';
position: absolute;
width: 200px;
height: 200px;
border-radius: 50%;
top: 20px;
right: -104px;
background-color: blue; /* Just because there is no image */
background-image: url(assets/img/about-1.png);
background-repeat: no-repeat;
background-size: cover;
z-index: 2;
}
.left{
text-align: right;
}
.right{
text-align: right;
}
.content{
padding: 30px 0px 80px 0px;
}
.left .content{
padding-right: 140px;
}
.right .content{
padding-left: 140px
}
.right{
text-align: left;
left: 50%;
}
.right:after {
left: -104px;
}
I think this is called a timeline, there is a lot of tutorials talking about how to do something like this, but I don't know how to make the images in the timeline line. Can you please help me do this?
Thanks
To build this, you could use css grid layout (guide: https://css-tricks.com/snippets/css/complete-guide-grid/)
Treat each of the content+image as a row in the layout. And each row as a container for a grid.
You can visually break every row down to 3 columns. One column for left-side content, the second one for the image and the third one for right-side content.
Example css grid for a layout like this:
.grid-container {
display: grid;
grid-template-columns: 1fr 10em 1fr;
grid-template-rows: 1fr;
grid-template-areas: "content-left image content-right";
text-align: center;
}
.content-left { grid-area: content-left; background: lightblue; }
.image { grid-area: image; background: lightgreen; }
.content-right { grid-area: content-right; background: lightblue; }
<div class="grid-container">
<div class="content-left">Left content</div>
<div class="image">Image</div>
<div class="content-right">Right content</div>
</div>
(grid generated with: https://grid.layoutit.com/)
To alternate between content on the left and on the right, you can use css even/odd selectors (How can I style even and odd elements?) to set which grid area is used for the element.
Example:
I've built an example of a timeline layout for this answer which you can find at https://codepen.io/hendrysadrak/pen/VwLEraz
Try this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="main.css" />
<title></title>
</head>
<body>
<section class="about">
<div class="wrapper">
<div>
<h3>About Us</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</div>
<div id="container">
<div class="row">
<div id="col1" class="col right">
<h5>JULY 2010<br> Our Humble Beginnings</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
<div id="col2" class="col"><img class="img" src="assets/img/about-1.png"/></div>
</div>
<div class="row2" >
<div id="col3" class="col"><img class="img" src="assets/img/about-1.png"/></div>
<div id="col4" class="col left">
<h5>JULY 2010<br> Our Humble Beginnings</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
in main.css file:
.about .wrapper{
padding: 80px 10%;
text-align: center;
}
.about h5{
line-height: 1.5;
font-size: 1em;
padding-bottom: .5em;
}
.row {
width: 59%;
margin-right: 41%;
display: flex;
}
.row2 {
width: 59%;
display: flex;
margin-left: 41%;
}
.col {
flex:1;
}
.col.left {
text-align: left;
}
.col.right {
text-align: right;
}
#col2 {
flex-basis: 30%;
}
#col1 {
flex-basis: 70%;
}
#col3 {
flex-basis: 30%;
}
#col4 {
flex-basis: 70%;
}
.img {
margin: 10% 5%;
width: 90%;
border-radius: 50%;
}
#container {
background-image: linear-gradient(lightgrey,lightgrey);
background-size: 2px 100%;
background-repeat: no-repeat;
background-position: center center;
}
put this in assets/img/about-1.png
I'm trying to:
center a container div which contains 2 inline elements: Another div, and a title.
The title can be any length.
The elements must be next to each other.
The text must be left aligned.
The div must be vertically aligned to the center of text.
This is the aim:
This is what I have so far.
HTML
<div class="container">
<div class="container">
<div class="box"></div>
<h2>This is my title</h2>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officiis ipsum reprehenderit ipsam hic adipisci ex obcaecati asperiores ab rerum, incidunt eius eligendi ea, odit, maiores fugit cumque modi, facere laudantium.</p>
<div class="container">
<div class="box"></div>
<h2>This is another title. It could be any length. Any length at all.</h2>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officiis ipsum reprehenderit ipsam hic adipisci ex obcaecati asperiores ab rerum, incidunt eius eligendi ea, odit, maiores fugit cumque modi, facere laudantium.</p>
</div>
CSS
.container{
width: 80%;
height: auto;
margin: 0 auto;
background-color: rgba(150,100,200,0.8);
text-align: center;
padding: 1em;
p{
text-align: left;
}
}
.box{
display: inline-block;
width: 3em;
height: 3em;
background-color: lightblue;
vertical-align: middle;
}
h2{
display: inline-block;
width: calc(100% - 4em);
margin: 0 auto;
text-align: left;
}
And here it is in a codepen
Help much appreciated.
Here is a solution with display: table.
Edit - Improved
Have a fiddle!
HTML
<div class="container">
<div class="heading">
<div class="box">
<div></div>
</div>
<h2>This is my title</h2>
</div>
<p>Content</p>
</div>
CSS
* {
margin: 0;
padding: 0;
}
.box {
display: table-cell;
vertical-align: middle;
}
.box div {
width: 3em;
height: 3em;
background-color: lightblue;
}
h2 {
display: table-cell;
vertical-align: middle;
padding: 0 0 0 10px;
text-align: center;
max-width: 400px;
}
.heading {
display: table;
margin: 0 auto;
}
p {
text-align: center;
}
Like this?
http://codepen.io/anon/pen/pfbvH?editors=110
I created a class "title-box" and made the square and h2 inside table cells. The light blue square scales with the height of the header:
.title-box {
background-color: rgba(150,100,200,0.8);
margin: 0 auto;
padding: 1em;
display: table;
}
.box{
width: 3em;
height: 3em;
background-color: lightblue;
display: table-cell;
}
h2{
margin: 0 auto;
text-align: left;
display: table-cell;
padding: 10px;
}