I am currently building a E-commerce website for practice and the I have the div set up as follows:
.small-container {
max-width: 1080px;
margin: 5px;
padding-left: 25px;
padding-right: 25px;
}
.col-4 {
flex-basis: 25%;
padding: 10px;
min-width: 200px;
margin-bottom: 50px;
background-color: #87bdd8!important;
border-style: solid;
border-color: #1E90FF;
}
.col-4 img {
width: 100%;
border-style: solid;
}
<div class="small-container">
<h2>Merch by Elute FLP</h2>
<div class="row">
<div class="col-4">
<img src="Pictures/JeansandTee.jpg">
<h5>Black Graphic T-Shirt</h5>
<p class="price">$29.99</p>
<p>Black Shirt w Graphic 100% cotton</p>
<p><button>Add to Cart</button></p>
</div>
<div class="col-4">
<img src="Pictures/JeansandTee.jpg">
<h5>Black Graphic T-Shirt</h5>
<p class="price">$29.99</p>
<p>Black Shirt w Graphic 100% cotton</p>
<p><button>Add to Cart</button></p>
</div>
<div class="col-4">
<img src="Pictures/JeansandTee.jpg">
<h5>Black Graphic T-Shirt</h5>
<p class="price">$29.99</p>
<p>Black Shirt w Graphic 100% cotton</p>
<p><button>Add to Cart</button></p>
</div>
</div>
I'm extremely new to coding and using this platform so I apologize if this looks really bad or if i'm asking a dumb question trying not to rely on tutorials and think for myself but I can't seem to find the answer anywhere. I want the divs to have space and when I add any margin the last div wraps.
Using Atom Framework and unsure why when code run with tool on here shows elements vertical. On Atom when I load the page they are horizontal...
Since you use columns with flex-basis, you have to make the div with class row a flex parent.
I also suggest that you use the columns for grid and style their content separately. In the example below I have created .card elements, which are wrapped inside the columns.
And finally - extremely important: set the box-sizing of the columns to border-box. This means you can set paddings to the columns (instead of margins), which will be counted in the 25% of the column width. This is why it will be better to avoid horizontal margins in this scenario, because this will break the Maths - you want 4 columns with 25% width, but where should the space between them go?
.small-container {
max-width: 1080px;
margin: 5px;
padding-left: 25px;
padding-right: 25px;
}
/* The columns is simplified only to shape the grid */
.col-4 {
flex-basis: 25%;
box-sizing: border-box;
margin-bottom: 50px;
padding: 0 10px;
}
.col-4 img {
width: 100%;
border-style: solid;
}
.row {
display: flex;
flex-wrap: wrap;
}
/* Styling the column content */
.card {
flex-basis: 25%;
padding: 10px;
background-color: #87bdd8 !important;
border-style: solid;
border-color: #1E90FF;
}
<div class="small-container">
<h2>Merch by Elute FLP</h2>
<div class="row">
<div class="col-4">
<div class="card">
<img src="Pictures/JeansandTee.jpg">
<h5>Black Graphic T-Shirt</h5>
<p class="price">$29.99</p>
<p>Black Shirt w Graphic 100% cotton</p>
<p><button>Add to Cart</button></p>
</div>
</div>
<div class="col-4">
<div class="card">
<img src="Pictures/JeansandTee.jpg">
<h5>Black Graphic T-Shirt</h5>
<p class="price">$29.99</p>
<p>Black Shirt w Graphic 100% cotton</p>
<p><button>Add to Cart</button></p>
</div>
</div>
<div class="col-4">
<div class="card">
<img src="Pictures/JeansandTee.jpg">
<h5>Black Graphic T-Shirt</h5>
<p class="price">$29.99</p>
<p>Black Shirt w Graphic 100% cotton</p>
<p><button>Add to Cart</button></p>
</div>
</div>
<div class="col-4">
<div class="card">
<img src="Pictures/JeansandTee.jpg">
<h5>Black Graphic T-Shirt</h5>
<p class="price">$29.99</p>
<p>Black Shirt w Graphic 100% cotton</p>
<p><button>Add to Cart</button></p>
</div>
</div>
<div class="col-4">
<div class="card">
<img src="Pictures/JeansandTee.jpg">
<h5>Black Graphic T-Shirt</h5>
<p class="price">$29.99</p>
<p>Black Shirt w Graphic 100% cotton</p>
<p><button>Add to Cart</button></p>
</div>
</div>
</div>
</div>
Related
enter image description here
when screen size is normal
problem
enter image description here
when resizing the screen
I want the text to stay on the right side of the image all the time and never overlap in desktop and mobile
html
I also used bootstrap
<div id="moreNews" class="row">
<div class="col-lg-4 row rowCard">
<div class="col-lg-4">
<img class="imageSize" src="assets\images\image-retro-pcs.jpg" alt="">
</div>
<div class="col-lg-8 moreNewsCol">
<h2 class="moreNewsH2 ">01</h2>
<h3 class="moreNewsH3 ">Reviving Retro PCs</h3>
<p class="moreNewsP ">What happens when old PCs are given modern upgrades?</p>
</div>
</div>
<div class="col-lg-4 row rowCard">
<div class="col-lg-4 moreNewsCol">
<img class="imageSize" src="assets\images\image-top-laptops.jpg" alt="">
</div>
<div class="col-lg-8 moreNewsCol">
<h2 class="moreNewsH2 ">02</h2>
<h3 class="moreNewsH3 ">Top 10 Laptops of 2022</h3>
<p class="moreNewsP ">Our best picks for various needs and budgets.</p>
</div>
</div>
<div class="col-lg-4 row rowCard">
<div class="col-lg-4">
<img class="imageSize" src="assets\images\image-gaming-growth.jpg" alt="">
</div>
<div class="col-lg-8 moreNewsCol">
<h2 class="moreNewsH2">03</h2>
<h3 class="moreNewsH3">The Growth of Gaming</h3>
<p class="moreNewsP ">How the pandemic has sparked fresh opportunities.</p>
</div>
</div>
</div>
and CSS
body {
text-align: center;
margin: 6% 12% 6% 12%;
}
#moreNews {
margin: 0;
margin-top: 5rem;
}
.imageSize {
width: 6rem;
}
.moreNewsH2{
float: right;
text-align: left;
padding-right: 85%;
color: hsl(233 8% 79%);
}
.moreNewsH3{
text-align: left;
color: black;
font-size: 1.2rem;
}
.moreNewsP{
text-align: left;
color: gray;
font-size: 0.9rem;
}
.moreNewsCol{
text-align: left;
}
.rowCard {
margin-right: 0.7rem;
}
.attribution {
margin-top: 6rem;
}
I spend hours messing with code but I didn't got the solution
I want the text to stay on the right side of the image all the time and never overlap in desktop and mobile
This question already has answers here:
Align an element to bottom with flexbox
(10 answers)
Closed 4 months ago.
I am brand new to coding (thanks for your patience!) and working on a portfolio project for a bootcamp course. I'd like to show headers & copy on the top of my cards with the images aligned underneath. We are using CSS flex. Currently if the text length differs between cards the images end up un-aligned. Here is a screenshot:
Screenshot of uneven card images:
Any suggestions on how I can keep the header + copy at the top but align the images to the bottom of the card?
.card-container {
display: flex;
flex-flow: row wrap;
justify-content: center;
margin: auto auto 60px auto;
max-width: 100vw;
/* 1000px; */
}
.card {
background-color: #f2f2f2;
width: 40%;
margin: 20px;
}
.card a:hover {
text-decoration: none;
}
.card-copy {
padding: 0 20px 20px 20px;
}
<section>
<h2 class="center">Apparel Design</h2>
<div class="card-container">
<!--Card 1-->
<div class="card">
<a href="">
<div class="card-copy">
<h3 class="margin-bottom_five">Design Process</h3>
<p class="margin-top_zero">Copy here about my design process overview</p>
</div>
<img src="https://via.placeholder.com/400">
</a>
</div>
<!--Card 2-->
<div class="card">
<a href="">
<div class="card-copy">
<h3 class="margin-bottom_five">Professional Work</h3>
<p class="margin-top_zero">Copy here about my most recent professional work</p>
</div>
<img src="https://via.placeholder.com/400">
</a>
</div>
<!--Card 3-->
<div class="card">
<a href="">
<div class="card-copy">
<h3 class="margin-bottom_five">Exploratory Projects</h3>
<p class="margin-top_zero">Copy here about my recent stretch projects</p>
</div>
<img src="https://via.placeholder.com/400">
</a>
</div>
</div>
</section>
There are several ways to do this. One is to make your anchors flex containers as well, with direction 'column'. You'd then make them full height and spread their child elements with space-between.
You could also apply flex-fill properties to the paragraph to make it expand to fill available space.
See https://css-tricks.com/snippets/css/a-guide-to-flexbox.
.card-container {
display: flex;
flex-flow: row wrap;
justify-content: center;
margin: auto auto 60px auto;
max-width: 100vw; /* 1000px; */
}
.card {
background-color: #f2f2f2;
width: 40%;
margin: 20px;
}
.card a {
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.card a:hover {
text-decoration: none;
}
.card-copy {
padding: 0 20px 20px 20px;
}
.card img {
max-width: 100%;
}
<section>
<h2 class="center">Apparel Design</h2>
<div class="card-container">
<!--Card 1-->
<div class="card">
<a href="">
<div class="card-copy">
<h3 class="margin-bottom_five">Design Process</h3>
<p class="margin-top_zero">Copy here</p>
</div>
<img src="https://via.placeholder.com/400">
</a>
</div>
<!--Card 2-->
<div class="card">
<a href="">
<div class="card-copy">
<h3 class="margin-bottom_five">Professional Work</h3>
<p class="margin-top_zero">Copy here about my most recent professional work</p>
</div>
<img src="https://via.placeholder.com/400">
</a>
</div>
</div>
</section>
I am trying to adapt the Material Design in my personal website using materializecss.com, however the framework only provide options to exclude otherwise images on top of the CARD design.
I want to achieve something as shown below in the link [2nd row, 2nd column/ last image] where the image is sitting at left beside the main content, wondering if anyone could help me on this and I would really appreciate your help on this. thanks!
Card Material Design Example
#vizFlux
Here is the code which you want
.card-image {
float: left;
width: 40%;
height: 250px;
}
.card-image img {
height: 100%;
}
.right-content {
width: 60%;
float: left;
}
.card-title {
padding-left: 20px;
}
<div class="card">
<div class="card-image">
<img src="images/sample-1.jpg" class="hoverZoomLink">
</div>
<div class="right-content">
<span class="card-title">Card Title</span>
<div class="card-content">
<p>I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively.
</p>
</div>
<div class="card-action">
This is a link
</div>
</div>
</div>
the output should look something like this:
.card-image {
float: left;
width: 40%;
height: 250px;
}
.card-image img {
height: 100%;
}
.right-content {
width: 60%;
float: left;
}
.card-title {
padding-left: 20px;
}
<div class="card">
<div class="card-image">
<img src="http://www.sauna-nj.co.jp/wp-content/uploads/2017/03/topa-zu.jpg" class="hoverZoomLink">
</div>
<div class="right-content">
<span class="card-title">Card Title</span>
<div class="card-content">
<p>岩盤浴で使用されるのは極めて珍しい鉱石です。加熱変色する宝石の代表。またその中でも大変珍しく、加熱や摩擦圧力で帯電し数時間は維持することができます。その後中和状態に戻る際に発する電荷を身体に受けることで肩こりや冷え性の改善、神経性疲労や神経衰弱の回復など様々な症状を改善するといわれています。
</p>
</div>
<div class="card-action">
This is a link
</div>
</div>
</div>
This should help
http://materializecss.com/cards.html
<div class="row">
<div class="col s12 m7">
<div class="card">
<div class="card-image">
<img src="images/sample-1.jpg">
<span class="card-title">Card Title</span>
</div>
<div class="card-content">
<p>I am a very simple card. I am good at containing small bits of information.
I am convenient because I require little markup to use effectively.</p>
</div>
<div class="card-action">
This is a link
</div>
</div>
</div>
</div>
Hi HTML5 and CSS newbie here,
We had to create an interests page for our final project so I used 8 images stacked left to right contained in individual div containers with a caption that only appears when you hover over the photo. It looks fine in Chrome and Firefox, but in IE all the photos are everywhere. Any help would be appreciated:
HTML:
<section>
<div class="interests">
<img src="music.png" alt="Musician" id="musician">
<p class="caption" id="musicP">I love all genres of music.</p>
</div>
<div class="interests">
<img src="movies.png" alt="Popcorn" id="popcorn">
<p class="caption" id="movieP">Favorite romance comedy is Sleepless in Seattle</p>
</div>
<div class="interests">
<img src="reddit.png" alt="Reddit" id="reddit">
<p class="caption" id="redditP">I love Reddit. I spend way too much time there.</p>
</div>
<div class="interests">
<img src="reading.png" alt="Books" id="books">
<p class="caption">I only read fiction books.</p>
</div>
<div class="interests">
<img src="cooking.png" alt="Cooking" id="cooking">
<p class="caption" id="cookingP">Favorite food is sushi</p>
</div>
<div class="interests">
<img src="videogames.png" alt="Video Games" id="games">
<p class="caption">I'm playing Animal Crossing right now.</p>
</div>
<div class="interests">
<img src="football.png" alt="Football Game" id="football">
<p class="caption">My favorite player is Peyton Manning!</p>
</div>
<div class="interests">
<img src="travel.png" alt="Globe" id="travel">
<p class="caption">I'd like to visit Germany soon.</p>
</div>
</section>
CSS:
/*Styles for the Interests Page*/
/*Floats all the photos to the left*/
.interests {
float: left;
}
/*Styles for individual photos*/
#cooking{
height: 180px;
margin-left: 100px;
}
#books{
width: 240px;
height: 169px;
}
#games{
height: 180px;
}
/*Photo Caption Styles*/
.caption{
font-size: 70%;
visibility: hidden;
opacity: 0;
}
.interests:hover .caption{
visibility: visible;
opacity: 1;
}
#cookingP{
margin-left: 100px;
width:200px;
}
Thanks!
instead of
<img src="music.png" alt="Musician" id="musician">
close all your images to have a closing
<img src="music.png" alt="Musician" id="musician"/>
you are missing / in your image tags
Don't use floats. Use display:table on the <section> tag, display:table-cell on all the interest class divs, and wrap a div around the rows with the style display:table-row.
http://www.w3schools.com/cssref/pr_class_display.asp
I wish to have the span tag float left and have the <section> floated left beside it also. But the <section> sits below the span.
I would imagine it has something to do with setting the widths of the elements but I want it to be responsive and flex.
<div class="container">
<div class="row">
<div class="col-md-4">
<h3 class="highlight-sub"><em>Start using your card today</em></h3>
</div>
<div class="col-md-8">
<div class="col-md-4">
<span class="step">1</span>
<section>
<h4 class="highlight-prim">Complete Form</h4>
<p class="highlight-sub">Simply fill in our online form and your account will created.</p>
</section>
</div>
<div class="col-md-4">
<span class="step">2</span>
<section>
<h4 class="highlight-prim">Receive by Post</h4>
<p class="highlight-sub">You will be sent your new card in post.</p>
</section>
</div>
<div class="col-md-4">
<span class="step">3</span>
<section>
<h4 class="highlight-prim">Start Enjoying</h4>
<p class="highlight-sub">Present your new card to any of our partners for al the benifits.</p>
</section>
</div>
</div>
</div>
</div>
#mid-content span.step {
border: 2px solid #A99269;
border-radius: 0.8em;
-moz-border-radius: 0.8em;
-webkit-border-radius: 0.8em;
color: #A99269;
display: inline-block;
font-weight: 300;
line-height: 1.6em;
margin-right: 5px;
text-align: center;
width: 1.6em;
font-size: 32px;
float: left
}
#mid-content section {
display: inline-block;
float:left
}
Float to the left only the .step element, and give to the section a left margin equal to the total width of the .step (with total i mean including borders..)
demo at http://jsfiddle.net/sqD6Q/
(with arbitrary margin since i do not know your currest styles to calculate the margin..)
Yes, probably the content of the section is almost 100% of the row, and it goes to the second row. You can place the span inside the section