I have a CSS layout problem. In the Portfolio section of my site # 763px breakpoint I want 3 rows with 2 columns in each of them. I have that.
[.col] [.col]
[.col] [.col]
[.col] [.col]
But from 926px - 978px my columns break up and then i get 4 rows like this:
[.col] [.col]
[.col]
[.col] [.col]
[.col]
Why is this happening? And what is the solution? Thank you.
main {
margin: 55px 0px -30px 0px;
background: linear-gradient(transparent, rgba(102, 194, 255, 0.4) 10%, transparent 99%);
padding-bottom: 5rem;
}
h2 {
text-align: center;
margin: 5rem 0;
font-size: 1.6rem;
}
h3 {
color: #353535;
font-size: 1.3rem;
margin: 1.2rem 0;
}
.col {
width: 100%;
text-align: center;
margin-bottom: 15px;
}
.col p {
width: 90%;
margin: 0 auto;
}
.col img {
width: 95%;
}
/*====== 768px ==== */
#media (min-width: 768px) {
.wrapper { padding: 10px 20px 0px 20px; }
main {
width: 100%;
}
.col {
float: left;
width: 47%;
margin-left: 1.5%;
margin-right: 1.5%;
display: inline-block;
text-align: center;
vertical-align: top;
}
.col h3 {
font-size: 1.5rem;
}
drag to resize
<main>
<h2 id="portfolio">Portfolio</h2>
<!-- first row -->
<div class="row-content clearfix">
<div class="col">
<img src="images/portfolio-1.png">
<h3>Marketing Page</h3>
<p>This project shows the front page of a marketing webiste meant for a specific business I'm interested in.</p>
</div>
<div class="col">
<img src="images/portfolio-2.png">
<h3>Search Page</h3>
<p>This project searches through a specific database to find information that the user is trying to lookup.</p>
</div>
<div class="col">
<img src="images/portfolio-3.png">
<h3>Travel App</h3>
<p>This project compares travel times based on different transportation methods and tells you the best.</p>
</div>
<!-- second row -->
<div class="col">
<img src="images/portfolio-4.png">
<h3>Map of Favorite Sports</h3>
<p>This project uses mapping apps to plot points for my favorite spots in the city for a do-it-yourself walking tour.</p>
</div>
<div class="col">
<img src="images/portfolio-5.png">
<h3>Photo Gallery</h3>
<p>This project shows pictures from a recent trip to the viewer and allos them to easily navigate through photos.</p>
</div>
<div class="col">
<img src="images/portfolio-6.png">
<h3>Calculator</h3>
<p>Somone can enter in the numbers they want and press the big blue button and get the result.</p>
</div>
</div>
</main>
drag to resize
Your problem is that one of the divs is higher than the other, then, the float logic will place the third div to the left of the first div.
If you'll add borders, you'll see it more clearly. Since the first div is higher than the second, the third div still a place to be float to the first div.
If you'll give them fixed height it will solve the problem.
BUT, I suggest using a different layout. Flex for example:
Add to container:
.row-content{
display: flex;
flex-wrap: wrap;
}
and for each col :
flex-grow: 1;
flex-basis: 47%;
flex-shrink: 0;
main {
margin: 55px 0px -30px 0px;
background: linear-gradient(transparent, rgba(102, 194, 255, 0.4) 10%, transparent 99%);
padding-bottom: 5rem;
}
h2 {
text-align: center;
margin: 5rem 0;
font-size: 1.6rem;
}
h3 {
color: #353535;
font-size: 1.3rem;
margin: 1.2rem 0;
}
.row-content{
display: flex;
flex-wrap: wrap;
}
.col {
flex-grow: 1;
flex-basis: 47%;
flex-shrink: 0;
text-align: center;
margin-bottom: 15px;
}
.col p {
width: 90%;
margin: 0 auto;
}
.col img {
width: 95%;
}
/*====== 768px ==== */
#media (min-width: 768px) {
.wrapper { padding: 10px 20px 0px 20px; }
main {
width: 100%;
}
.col {
float: left;
width: 47%;
margin-left: 1.5%;
margin-right: 1.5%;
display: inline-block;
text-align: center;
vertical-align: top;
}
.col h3 {
font-size: 1.5rem;
}
drag to resize
<main>
<h2 id="portfolio">Portfolio</h2>
<!-- first row -->
<div class="row-content clearfix">
<div class="col">
<img src="images/portfolio-1.png">
<h3>Marketing Page</h3>
<p>This project shows the front page of a marketing webiste meant for a specific business I'm interested in.</p>
</div>
<div class="col">
<img src="images/portfolio-2.png">
<h3>Search Page</h3>
<p>This project searches through a specific database to find information that the user is trying to lookup.</p>
</div>
<div class="col">
<img src="images/portfolio-3.png">
<h3>Travel App</h3>
<p>This project compares travel times based on different transportation methods and tells you the best.</p>
</div>
<!-- second row -->
<div class="col">
<img src="images/portfolio-4.png">
<h3>Map of Favorite Sports</h3>
<p>This project uses mapping apps to plot points for my favorite spots in the city for a do-it-yourself walking tour.</p>
</div>
<div class="col">
<img src="images/portfolio-5.png">
<h3>Photo Gallery</h3>
<p>This project shows pictures from a recent trip to the viewer and allos them to easily navigate through photos.</p>
</div>
<div class="col">
<img src="images/portfolio-6.png">
<h3>Calculator</h3>
<p>Somone can enter in the numbers they want and press the big blue button and get the result.</p>
</div>
</div>
</main>
drag to resize
I couldn't repro this error between the given resolution but my best hunch is due to the difference in the text content. Try doing the same with the same text content for the description and it should be alright. If that's the case, you have to add a min-height to the inconsistent text-content.
.col p {
width: 90%;
margin: 0 auto;
min-height: 100px;
}
Related
Hobbyist who really sucks at css.
I have the following three divs:
The problem is, when I click on the middle one, the box grows, and so do the other two boxes:
How do I make boxes start off and stay the same size even after click. The reason the box is growing is do to adding the "arrow-icon"
Code looks like this:
HTML
<section class='modes-flex__options'>
<div class='options'>
<h2 class='options__title'>Options</h2>
<div class='options__item-container'id='1v1' onClick="selectedGameOption(this.id)">
<h3 class='options__item'>Player vs AI (1 v 1) </h3>
<div class='arrow-icon__div'>
<i></i>
</div>
</div>
<div class='options__item-container' id='1v1-tourny' onClick="selectedGameOption(this.id)">
<h3 class='options__item'>Player vs AI (Tournament)</h3>
<div class='arrow-icon__div'>
<i></i>
</div>
</div>
<div class='options__item-container' id='ai-v-ai-tourny' onClick="selectedGameOption(this.id)">
<h3 class='options__item' >AI vs AI (Tournament)</h3>
<div class='arrow-icon__div'>
<i></i>
</div>
</div>
</div>
</section>
CSS
.modes-flex{
display: flex;
margin-top: 3rem;
&__options{
flex:1;
display: flex;
justify-content: end;
}
&__description{
flex:1;
display: flex;
flex-direction: column;
}
}
.options{
margin-right: 5rem;
&__title{
font-size: 1.2rem;
padding-bottom:2rem;
}
&__item{
flex: 1;
padding-right: 5rem;
}
}
.description{
&__title{
font-size: 1.2rem;
padding-bottom:2rem;
}
}
.options__item-container {
padding: 1.5rem 1rem 1.5rem 1rem;
margin-bottom: 2rem;
box-shadow: 0 0 10px lightgrey;
border: 1px solid lightgrey;
display: flex;
align-items: center;
&:hover{
cursor: pointer;
}
}
.arrow-icon__div{
text-align: right;
}
.active-option{
background-color: $dark-navy;
color: white;
}
Tried to set min and max width and was still growing , just want them to stay even width after adding the icon.
You said it: The reason the box is growing is do to adding the "arrow-icon".
In my experience, in these situations, I always added to the default size of the boxes so that when another element (i.e. arrow-icon) is added, it doesn't change the size. (Because there is enough space in the box for arrow-icon to be added). With doing so, all the boxes remain the same through any actions.
I make it for web is good but i need to make it responsive for phones too.
.features-container, .authentication-container {
margin-left: auto;
margin-right: auto;
text-align: center !important;
justify-content: center !important;
}
.features-container {
max-width: 900px;
border: 1px solid rebeccapurple;
}
.authentication-container {
align-items: center !important;
display: flex !important;
color: rgba(255,255,255,0.65);
}
.authentication {
max-width: 314px;
border-style: none;
text-align: right !important;
}
.authentication-title {
0;
0;
color: white !important;
}
.authentication-title, .authentication-sub {
text-align: left !important;
}
#media (min-width: 768px) {
.item {
width: 33.3333333333%;
text-align: right !important;
padding: 32px !important;
flex: 1 1 auto !important;
}
}
<div class="container text-center features-container app-screenshot">
<div class="feature-items">
<div class="authentication-container">
<div class="item item-right">
<img class="authentication" src="https://desktop.github.com/images/upgrade/co-authoring.png" alt="Authentication">
</div>
<div class="item item-left">
<h4 class="authentication-title">Attribute commits with collaborators easily</h4>
<p class="authentication-sub">Quickly add co-authors to your commit. Great for pairing and excellent for sending a little love/credit to that special someone who helped fix that gnarly bug of yours. See the attribution on the history page, undo an accidental attribution, and see the co-authors on github.com</p>
</div>
</div>
</div>
</div>
i want to make like a Github.
Original template: https://desktop.github.com
My Error: https://imgur.com/a/oCbcd50
Using flex-wrap: wrap is WORKING
.authentication-container {
•••
flex-wrap: wrap;
}
I'm working on a project where I have to create an online bookstore webpage using only HTML and CSS . I want to display "about us" information for the shop using a style like in the image below :
Basically I want to put an image and a text in the way displayed above . Using flexbox however I have trouble syncing the image and the text I have because I have difficulties setting the image width to cover half the flex container and the part of my text the other half .
This is my code :
.flex-container {
display: flex;
justify-content: flex-start;
flex-direction: row;
background-color: orange;
opacity: 0.7;
}
.flex-container>div {
margin: 0;
width: 100%;
height: auto;
}
#fleximg>img {
width: 60%;
height: auto;
}
#about {
width: 50%;
margin-right: 300px;
height: auto;
}
<div class="flex-container">
<div id="fleximg"><img src="https://placehold.it/400x400" alt=d esk/></div>
<div id="about">
<!-- text i want to place next to image -->
<h1> ABOUT US </h1>
<p>
In these rough times we experience right now being forced to stay at home staring at nothing does actually nothing.This is why we have created this online book delivery website to provide the company of a book to those who can't go outside to buy or read
a book at a local bookshop .
</p>
</div>
</div>
When i run my page I get the picture below where the image and the text are not next to each other and I have trouble readjusting their sizes
I would appreciate your help with guiding me to solve my problem
First, if the image height is taller than the right-col content - even simple width: 100%; height: auto for the image could work.
div{
border: 2px solid black;
}
#fleximg img{
width: 100%;
height: auto;
vertical-align: middle;
}
.flex-container {
display: flex;
background-color: orange;
}
#fleximg{
flex-basis: 40%;
}
#about {
flex-basis: 60%;
display: flex;
align-items: center; /* align v */
}
<div class="flex-container">
<div id="fleximg" class="col">
tall image
<img src="https://placehold.it/400x700" alt=d esk/>
</div>
<div id="about" class="col">
<!-- text i want to place next to image -->
<div>
<h1> ABOUT US </h1>
</div>
</div>
</div>
But the idea above it less useful for dynamic sites.
More responsive approaches:
By background image
For the "left-col" Use background-image and background-size: cover.
div{
border: 2px solid black;a
}
.flex-container {
display: flex;
background-color: orange;
}
#fleximg{
flex-basis: 40%;
background-image: url("https://picsum.photos/1111/1300");
background-repeat: no-repeat;
background-size: cover
}
#about {
flex-basis: 60%;
padding: 100px 10px;
display: flex;
align-items: center; /* align v */
}
<div class="flex-container">
<div id="fleximg" class="col">
</div>
<div id="about" class="col">
<!-- text i want to place next to image -->
<div>
<h1> ABOUT US </h1>
<p>
In these rough times we experience right now being forced to stay at home staring at nothing does actually nothing.This is why we have created this online book delivery website to provide the company of a book to those who can't go outside to buy or read
a book at a local bookshop .
</p>
</div>
</div>
</div>
By image element
Without using background-image for the left-col this idea is more "tricky".
For img element - One idea/solution is to use this "trick":
https://css-tricks.com/aspect-ratio-boxes/
Set image col "parent" position to relative and put inside an absolute image (100% width/height + object-fit: cover).
div{
border: 2px solid black;
}
.flex-container {
display: flex;
background-color: orange;
}
#fleximg{
flex-basis: 40%;
top-padding: 100%;
position: relative;
}
#fleximg > img {
width: 100%;
height: 100%;
position: absolute;
object-fit: cover ;
}
#about {
flex-basis: 60%;
padding: 100px 10px;
display: flex;
align-items: center; /* align v */
}
<div class="flex-container">
<div id="fleximg" class="col">
<img src="https://placehold.it/400x400" alt=d esk/>
</div>
<div id="about" class="col">
<!-- text i want to place next to image -->
<div>
<h1> ABOUT US </h1>
<p>
In these rough times we experience right now being forced to stay at home staring at nothing does actually nothing.This is why we have created this online book delivery website to provide the company of a book to those who can't go outside to buy or read
a book at a local bookshop .
</p>
</div>
</div>
</div>
Important: From the design aspect - There is no magic solution to suit all situations. It also depends on the amount of content (text/images and so on) you place in the right "content" column and the width of the screen (min-width/height/padding/margin and Media query useful her).
You should set css class flex-container is width: 100% and #fleximg is width:50%, #about is width:50% and use the background in css instead for img tag.
Example:
.flex-container {
display: flex;
justify-content: flex-start;
flex-direction: row;
background-color: orange;
opacity: 0.7;
width: 100%;
height: auto;
};
#fleximg {
width: 50%;
height: auto;
background: url('') center no-repeat;
background-size: cover;
};
#about {
width: 50%;
margin-right: 0;
height: auto;
};
I know how to wrap items (in theory) but I must be doing something wrong. These are refusing.
I just want two profiles, side by side, that stack into a column when the window width shrinks. At the moment, they sort of squish together and overlap.
#profile-container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-content: center;
padding-bottom: 5%;
}
.profile-desc {
width: 35%;
margin: 5% 5%;
text-align: center;
}
#profileM {
height: 230px;
width: 219px;
}
#profileF {
height: 230px;
width: 219px;
}
<div id="profile-container">
<div class="profile-desc" style="float:left;width:35%;padding: 5px;">
<img src="images/male.jpg" id="profileM">
<h3 style="color:white;background-color:rgb(244,212,69);">
Name
</h3>
<h4 style="color: rgb(244,212,69);">
Occupation
</h4>
<p>
Description
</p>
</div>
<div class="profile-desc" style="float:right;width:35%; padding: 5px;">
<img src="images/female.jpg" id="profileF">
<h3 style="color:white;background-color:rgb(244,212,69);">
Name
</h3>
<h4 style="color: rgb(244,212,69);">
Occupation
</h4>
<p>
Description
</p>
</div>
</div>
What you are looking for is CSS media queries, it allows you to apply CSS when some conditions about the device (width or orientation for example) are met.
I tweaked your code adding a media query line (also I removed some not needed flex properties and removed some redundant inline styling on .profile-desc)
#profile-container {
padding-bottom: 5%;
}
.profile-desc {
float: left;
width: 35%;
margin: 5% 5%;
text-align: center;
}
#profileM {
height: 230px;
width: 219px;
}
#profileF {
height: 230px;
width: 219px;
}
#media(max-width: 580px) {
.profile-desc {
width: 100%;
margin: 0;
}
}
<div id="profile-container">
<div class="profile-desc">
<img src="images/male.jpg" id="profileM">
<h3 style="color:white;background-color:rgb(244,212,69);">
Name
</h3>
<h4 style="color: rgb(244,212,69);">
Occupation
</h4>
<p>
Description
</p>
</div>
<div class="profile-desc">
<img src="images/female.jpg" id="profileF">
<h3 style="color:white;background-color:rgb(244,212,69);">
Name
</h3>
<h4 style="color: rgb(244,212,69);">
Occupation
</h4>
<p>
Description
</p>
</div>
</div>
You could avoid the media query and rely on flexbox adaptability by telling it the size of the content. flex-basis: content achieves the same result but it is not widely supported.
The relevant change is:
.profile-desc {
flex-basis: 35%;
}
Okay using flex to align the image (purple) and the content (yellow) side by side. However I am getting extra space between and is throwing off the image to the right.
See here: http://imgur.com/a/nl0ZJ
It's supposed to be:
image should be inside the blue div next to the yellow div
the yellow div should be 60% width (These are flex items)
I've checked padding and margin, however it hasn't worked for me. Any ideas?
Here is the html
<div class="sec-1">
<h2>Introducing 'Keeva' world's smartest assistant.</h2>
<div class="flex-box">
<div>
<p class="sales-copy">Keeva smartphone app helps you organize your work schedule, meetings, project deadlines and much more.</p>
<!-- Download Buttons -->
<img class="download-btns" src="img/playstore-1.png">
<img class="download-btns" src="img/iphone-1.png">
</div>
<!-- Phone 0 image -->
<img class="phone-img" src="img/iphone-cut.png" alt="phone image">
</div>
</div>
CSS
#media screen and (min-width: 599px) {
.sec-1 h2 {
font-size: 1.2em;
background-color: green;
}
.sec-1 p {
font-size: 1.1em;
width: 50%;
background-color: yellow;
}
.sec-1 .phone-img {
position: relative;
top: 10%;
left: 30%;
background-color: purple;
}
.download-btns {
position: relative;
right: 25%;
background-color: orange;
}
.sec-1 .sales-copy {
width: 50%;
}
.flex-box {
display: flex;
justify-content: flex-end;
}
}
Since display: flex makes its immediate descendants flex items, it is only the div that wraps the the p/img that becomes one.
So to make this work, and since img doesn't behave normal when being flex items, move that div wrapper to the img and it will flow as intended.
I also changed width: 50% to flex-basis: 60% so the yellow element becomes 60%, and added flex-grow: 1 to the div wrapper, so it takes the remaining space.
Updated based on a comment
Changed to an outer and an inner Flexbox wrapper, so the buttons are located below the yellow element and the image to the right
.sec-1 h2 {
font-size: 1.2em;
background-color: green;
}
.sec-1 p {
margin: 0;
font-size: 1.1em;
background-color: yellow;
}
.sec-1 .phone-img {
position: relative;
top: 10%;
left: 30%;
background-color: purple;
}
.flex-box-outer {
display: flex;
}
.flex-box-outer > div {
flex-grow: 1;
}
.flex-box-inner {
flex-basis: 60%;
display: flex;
flex-direction: column;
align-items: center;
}
<div class="sec-1">
<h2>Introducing 'Keeva' world's smartest assistant.</h2>
<div class="flex-box-outer">
<div class="flex-box-inner">
<p class="sales-copy">Keeva smartphone app helps you organize your work schedule, meetings, project deadlines and much more.</p>
<!-- Download Buttons -->
<div>
<img class="download-btns" src="http://placehold.it/100x50/?text=playstore">
<img class="download-btns" src="http://placehold.it/100x50/?text=iphone">
</div>
</div>
<!-- Phone 0 image -->
<div>
<img class="phone-img" src="http://placehold.it/100x50/?text=iphone cut" alt="phone image">
</div>
</div>
</div>