Display elements in a inline-block depend on section width - html

I have tried for some time to do something like on the image.
Elements (.element) goes down but they are not centered but stick left.
My code now is:
Html:
<div id="_technology_page" class="region">
<div class="actions_container">
<div class="actions">
{{#each actions}}
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
{{text}}
</p>
</a>
</div>
{{/each}}
</div>
</div>
</div>
Css: (scss):
#_technology_page {
.actions_container {
max-width: 100%;
position: relative;
text-align: center;
display: flex;
.actions {
position: relative;
.action {
float: left;
position: relative;
position: relative;
margin: 10px 40px;
text-align: center;
float: left;
height: 300px;
width: 250px;
display: flex;
img {
margin: auto;
width: 120px
}
.action_text {
width: 100%;
color: black;
position: absolute;
bottom: 0;
}
}
}
}
}
I have tried many things, search examples, bot nothing works as I want it to works.
Also, I have tried to do it on Bootstrap grid system, but those elements are still stuck to the left side of the container.
Please provide some examples how to do it, I have no idea how to do it anymore.

using flexbox here is a way simpler code from yours
body {
margin: 0
}
.region {
border: solid;
padding: 50px 0
}
.actions {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
border: red solid;
padding: 10px;
}
.action {
flex: 0 140px;
height: 140px;
border: orange solid;
margin: 5px;
}
<div id="_technology_page" class="region">
<div class="actions_container">
<div class="actions">
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
</p>
</a>
</div>
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
</p>
</a>
</div>
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
</p>
</a>
</div>
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
</p>
</a>
</div>
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
</p>
</a>
</div>
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
</p>
</a>
</div>
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
</p>
</a>
</div>
</div>
</div>
</div>

Related

How to create this css grid

I want to acheive this design any next category will automatically adjust to the previous div. Every category have not specific product but need to just after the previous product like we use float left or display-flex But don't want to create multiple css for responsive. Because it has more than 25 categories. `
.offerpage .product-box {
margin: 0 5px;
}
.categoryProductsWrap{
width: 100%;
}
.product-img{
width: 100%;
}
.categoryProductsWrap .categoryProducts {
display: flex;
flex-wrap: wrap;
width: 100%;
}
.categoryProductsWrap .categoryProducts .product-box {
margin-bottom: 10px;
float: left;
}
.offerpage .categoryName {
color: #161719;
font-size: 24px;
font-weight: bold;
margin-bottom: 0.5em;
border-bottom: solid 1px #dddddd;
padding-bottom: 0.125em;
}
.img-box{
position: relative;
padding-top: 124%;
display: inline-block;
width: 100%;
vertical-align: top;
}
.product-box .product-img{
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
}
.img-responsive {
display: block;
max-width: 100%;
height: auto;
}
.txt-content {
overflow: hidden;
position: relative;
}
.img-box{
position: relative;
padding-top: 124%;
display: inline-block;
width: 100%;
vertical-align: top;
}
.offerpage{
display: flex;
flex-wrap: wrap;
}
.categoryProductsWrap .categoryProducts .product-box{
width: 33.333%
}
#media (min-width: 1200px){
.categoryProductsWrap.cooling_fan {
width: 50%;
}
.categoryProductsWrap.accessories {
width: 50%;
}
}
#media (min-width: 1440px){
.categoryProductsWrap.accessories .categoryProducts .product-box,
.categoryProductsWrap.cooling_fan .categoryProducts .product-box {
width: calc(50% - 10px);
}
}
<div class="offerpage">
<div class="categoryProductsWrap accessories">
<div class="categoryName">Accessories</div>
<div class="categoryProducts clearfix offerzone-slider products-wrapper">
<div class="product-box">
<div class="product-inner-box">
<div class="txt-content">
<div class="img-box">
<a href="#" class="product-thumbnail">
<img class="product-img img-responsive" src="https://picsum.photos/400">
</a>
</div>
</div>
</div>
</div>
<div class="product-box">
<div class="product-inner-box">
<div class="txt-content">
<div class="img-box">
<a href="#" class="product-thumbnail">
<img class="product-img img-responsive" src="https://picsum.photos/400">
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="categoryProductsWrap cooling_fan">
<div class="categoryName">Cooling Fan</div>
<div class="categoryProducts clearfix offerzone-slider products-wrapper">
<div class="product-box">
<div class="product-inner-box">
<div class="txt-content">
<div class="img-box">
<a href="#" class="product-thumbnail">
<img class="product-img img-responsive" src="https://picsum.photos/400">
</a>
</div>
</div>
</div>
</div>
<div class="product-box">
<div class="product-inner-box">
<div class="txt-content">
<div class="img-box">
<a href="#" class="product-thumbnail">
<img class="product-img img-responsive" src="https://picsum.photos/400">
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="categoryProductsWrap asus">
<div class="categoryName">Asus</div>
<div class="categoryProducts clearfix offerzone-slider products-wrapper">
<div class="product-box">
<div class="product-inner-box">
<div class="txt-content">
<div class="img-box">
<a href="#" class="product-thumbnail">
<img class="product-img img-responsive" src="https://picsum.photos/400">
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="categoryProductsWrap audio">
<div class="categoryName">Audio Device</div>
<div class="categoryProducts clearfix offerzone-slider products-wrapper">
<div class="product-box">
<div class="product-inner-box">
<div class="txt-content">
<div class="img-box">
<a href="#" class="product-thumbnail">
<img class="product-img img-responsive" src="https://picsum.photos/400">
</a>
</div>
</div>
</div>
</div>
<div class="product-box">
<div class="product-inner-box">
<div class="txt-content">
<div class="img-box">
<a href="#" class="product-thumbnail">
<img class="product-img img-responsive" src="https://picsum.photos/400">
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
`
If you want to use CSS grid, there no big difficulties simply check the documentation to understand the main CSS properties you need to add.
Also check this guide on CSS grid to undertand more and see examples.
Quick help
If I understand correctly you want 3 items max per row, to do that you will need to set:
grid-template-columns: repeat(3, 1fr);
The equivalent to flex-direction: row; is grid-auto-flow: row;
You will I presume also need a gap (spacing between items), something like that:
gap: 10px;
So a good starting point will be:
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-auto-flow: row;
gap: 10px;
I leave you do the rest according to your needs.

Item moving around when window resized

See Umbrella image in images:
Full-size window:
.
Reduced (ideal placement):
I would like to have my umbrella image in the centre of the screen no matter the size of the window.
It works from the point where the window shrinks and works in mobile view too.
I've tried various methods but it doesn't seem to be working, any tips would be greatly appreciated.
Here is my code:
HTML
<div class="wrapper">
<div class="page2">
<h2>Blog</h2>
<div class="wrap">
<div class="card">
<a href="welcome.html">
<img class="card-img" src="str3.jpg">
</a>
<div class="card-text">
<h3>Welcome</h3>
<p>Website Launch and my First Project</p>
</div>
</div>
<div class="card">
<a href="blog.html">
<img class="card-img" src="steve_roe_kyoto.jpg">
</a>
<div class="card-text">
<h3> Kyoto</h3>
<p>My Recent Trip</p>
</div>
</div>
<div class="card">
<a href="best.html">
<img class="card-img" src="str4.jpg">
</a>
<div class="card-text">
<h3>Best of 2018</h3>
<p>Neon Goodness from Last Year</p>
</div>
</div>
</div>
<div class="page3">
<footer>
<div class="umbrella_icon">
<img src="umbrella-02.png">
</div>
<div class="logo_footer">Steve Roe</div>
<div class="footer_menu">
<ul class="ul_footer">
<li>Work With Me</li>
<li>
Contact</li>
</ul>
</div>
</footer>
</div>
</div>
</div>
CSS
.page2{
width: 100%;
margin: 0 auto;
margin-top: 20px;
height: 100%;
}
//cards
.wrap{
width:960px;
margin:auto;
margin-top: 100px;
}
.card{
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.15);
transition: 0.4s;
width: 300px;
text-align: center;
font-size: 16px;
float:left;
margin:10px;
text-decoration: none;
}
.page3{
margin: 20px;
margin-top: 20px;
height: 30%;
}
.umbrella_icon {
text-align: center;
}
.footer {
z-index: 1000;
width: 960px;
margin: 0 auto;
}
Use dispaly:flex to .wrap
See working code
.page2{
width: 100%;
margin: 0 auto;
margin-top: 20px;
height: 100%;
}
.wrap{
margin: auto;
margin-top: 100px;
display: flex;
}
.card{
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.15);
transition: 0.4s;
width: 300px;
text-align: center;
font-size: 16px;
float:left;
margin:10px;
text-decoration: none;
}
.page3{
margin: 20px;
margin-top: 20px;
height: 30%;
}
.umbrella_icon {
text-align: center;
}
.footer {
z-index: 1000;
width: 960px;
margin: 0 auto;
}
<div class="wrapper">
<div class="page2">
<h2>Blog</h2>
<div class="wrap">
<div class="card">
<a href="welcome.html">
<img class="card-img" src="str3.jpg">
</a>
<div class="card-text">
<h3>Welcome</h3>
<p>Website Launch and my First Project</p>
</div>
</div>
<div class="card">
<a href="blog.html">
<img class="card-img" src="steve_roe_kyoto.jpg">
</a>
<div class="card-text">
<h3> Kyoto</h3>
<p>My Recent Trip</p>
</div>
</div>
<div class="card">
<a href="best.html">
<img class="card-img" src="str4.jpg">
</a>
<div class="card-text">
<h3>Best of 2018</h3>
<p>Neon Goodness from Last Year</p>
</div>
</div>
</div>
<div class="page3">
<footer>
<div class="umbrella_icon">
<img src="umbrella-02.png" alt="umbrella">
</div>
<div class="logo_footer">Steve Roe</div>
<div class="footer_menu">
<ul class="ul_footer">
<li>Work With Me</li>
<li>
Contact</li>
</ul>
</div>
</footer>
</div>
</div>
</div>
End The page 2 div before starting page 3 div.
Change the page3 css to
.page3{
margin: 50vh 50vw;
}
<h2>Blog</h2>
<div class="wrap">
<div class="card">
<a href="welcome.html">
<img class="card-img" src="str3.jpg">
</a>
<div class="card-text">
<h3>Welcome</h3>
<p>Website Launch and my First Project</p>
</div>
</div>
<div class="card">
<a href="blog.html">
<img class="card-img" src="steve_roe_kyoto.jpg">
</a>
<div class="card-text">
<h3> Kyoto</h3>
<p>My Recent Trip</p>
</div>
</div>
<div class="card">
<a href="best.html">
<img class="card-img" src="str4.jpg">
</a>
<div class="card-text">
<h3>Best of 2018</h3>
<p>Neon Goodness from Last Year</p>
</div>
</div>
</div>
</div>
<div class="page3">
<footer>
<div class="umbrella_icon">
<img src="umbrella-02.png" alt="umbrella Here">
</div>
<div class="logo_footer">Steve Roe</div>
<div class="footer_menu">
<ul class="ul_footer">
<li>Work With Me</li>
<li>
Contact</li>
</ul>
</div>
</footer>
</div>
Use flex for .wrap like this :
.wrap{
width:960px;
margin:auto;
margin-top: 100px;
display: flex;
justify-content: center;
}
this code make image in center horizontally.

How to get the horizontal-card-footer div right below other div and not at right

I want to have a structure like this:
But its not working, the image, date, title and subtitle are ok, but then do you know how to put the Image title right below the image and the view and save links below the other texts with the same margin-left of 1rem?
I have here the Example: http://jsfiddle.net/tyyj57gs/6/, the issue should be because the horizontal-card div have display flex but Im not having sucess solving that issue.
Html:
<div class="container pb-4">
<div class="row">
<div class="col-lg-3">
<div class="horizontal-card">
<img src="http://via.placeholder.com/200x100"/>
<div class="horizontal-card-body">
<span class="card-text">Date</span>
<h4 class="card-title">Title</h4>
<span class="card-text">Subtitle</span>
</div>
<div class="horizontal-card-footer">
<span>Image Title</span>
<a class="card-text status">#View</a>
<a class="card-text status">#Save</a>
</div>
</div>
</div>
CSS
.horizontal-card{
display: flex;
border:1px solid gray;
margin-bottom:1rem;
img{
width: 200px;
height: 100px;
border-bottom: 2px solid red;
}
.horizontal-card-body{
display: flex;
flex-direction: column;
margin-left:1rem;
}
}
I did this by using display:inline-block instead of the flex box you had. The sections are broken into two rows. Add style as you wish.
HTML:
<div class="card">
<div class="row">
<div class="innerLeft">
<img src="http://via.placeholder.com/200x100"/>
</div>
<div class="innerRight">
<div class="horizontal-card-footer">
<span class="card-text">Date</span>
<h4 class="card-title">Title</h4>
<span class="card-text">Subtitle</span>
</div>
</div>
</div>
<div class="row">
<div class="innerLeft">
<p>Image Title</p>
</div>
<div class="innerRight">
<a class="card-text status">#View</a>
<a class="card-text status">#Save</a>
</div>
</div>
</div>
CSS:
.card {
display:block;
width:100%;
max-width:800px;
}
img {
width: 100%;
height: auto;
border-bottom: 2px solid orange;
}
.innerLeft {
display:inline-block;
margin-right:-4px;
vertical-align:top;
width:30%;
text-align:center;
padding:5px;
}
.innerRight {
display:inline-block;
vertical-align:top;
width:70%;
text-align:left;
padding:5px;
}
.card-text {
display:inline-block;
}
FIDDLE : http://jsfiddle.net/tyyj57gs/9/
You can create the layout you want using flexbox.
In the snippet below I have restructured your .horizontal-card into .card-left and .card-right.
.horizontal-card {
display: flex;
border: 1px solid gray;
margin-bottom: 1rem;
}
.card-left,
.card-right {
display: flex;
flex-direction: column;
}
.card-right {
width: 100%;
}
.card-left span {
background: orange;
flex: 1;
display: flex;
justify-content: center;
align-items: center;
}
.horizontal-card-body,
.horizontal-card-footer {
padding-left: 1em;
}
img {
width: 200px;
height: 100px;
}
.horizontal-card-footer {
/* Add to ensure the footer is pinned to the bottom of the card */
margin-top: auto;
border-top: 1px solid grey;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet">
<div class="container pb-4">
<div class="row">
<div class="col-lg-3">
<div class="horizontal-card">
<div class="card-left">
<img src="http://via.placeholder.com/200x100" />
<span>Image Title</span>
</div>
<div class="card-right">
<div class="horizontal-card-body">
<span class="card-text">Date</span>
<h4 class="card-title">Title</h4>
<span class="card-text">Subtitle</span>
</div>
<div class="horizontal-card-footer">
<a class="card-text status">#View</a>
<a class="card-text status">#Save</a>
</div>
</div>
</div>
</div>
<div class="container pb-4">
<div class="row">
<div class="col-lg-3">
<div class="horizontal-card">
<div class="card-left">
<img src="http://via.placeholder.com/200x100" />
<span>Image Title</span>
</div>
<div class="card-right">
<div class="horizontal-card-body">
<span class="card-text">Date</span>
<h4 class="card-title">Title</h4>
<span class="card-text">I am a card with a longer subtitle. I am a card with a longer subtitle. I am a card with a longer subtitle. I am a card with a longer subtitle. </span>
</div>
<div class="horizontal-card-footer">
<a class="card-text status">#View</a>
<a class="card-text status">#Save</a>
</div>
</div>
</div>
</div>
<div class="container pb-4">
<div class="row">
<div class="col-lg-3">
<div class="horizontal-card">
<div class="card-left">
<img src="http://via.placeholder.com/200x100" />
<span>Image Title</span>
</div>
<div class="card-right">
<div class="horizontal-card-body">
<span class="card-text">Date</span>
<h4 class="card-title">Title</h4>
<span class="card-text"></span>
</div>
<div class="horizontal-card-footer">
<a class="card-text status">#View</a>
<a class="card-text status">#Save</a>
</div>
</div>
</div>
</div>
Here is my version of the image. Let me know if there are any issues, I have used position absolute for the footer's position.
For the SCSS version of the CSS refer the fiddle, else refer the snippet below!
JSFiddle Demo
.horizontal-card {
position: relative;
display: flex;
border: 1px solid gray;
margin-bottom: 1rem;
}
.horizontal-card img {
width: 200px;
height: 130px;
border-bottom: 30px solid orange;
}
.horizontal-card .horizontal-card-body {
display: flex;
flex-direction: column;
margin-left: 1rem;
}
.horizontal-card .horizontal-card-footer {
position: absolute;
left: 0px;
right: 0px;
bottom: 0px;
height: 30px;
display: flex;
align-items: center;
}
.horizontal-card .horizontal-card-footer span {
width: 200px;
display: inline-block;
}
.horizontal-card .horizontal-card-footer a {
margin-left: 10px;
}
<div class="container pb-4">
<div class="row">
<div class="col-lg-3">
<div class="horizontal-card">
<img src="http://via.placeholder.com/200x100" />
<div class="horizontal-card-body">
<span class="card-text">Date</span>
<h4 class="card-title">Title</h4>
<span class="card-text">Subtitle</span>
</div>
<div class="horizontal-card-footer">
<span>Image Title</span>
<a class="card-text status">#View</a>
<a class="card-text status">#Save</a>
</div>
</div>
</div>

I don't see why my :last-child selector isn't working as it should be [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
In my CSS I've used wrapped divs class to call last-child to remove the right margin, but for some reason I can't find the problem.
.user-panel {
border-bottom-color: #8F8F8F;
background-color: #FCFCFC;
border-style: solid;
border-width: 1px;
border-color: #D9D9D9;
float: left;
width: 257px;
margin-top: 40px;
border-bottom-color: #8F8F8F;
margin-right: 5px;
}
.user-panel-wrap:last-child {
margin-right: 0px;
}
.user-panel:hover {
background-color: #B2D195;
}
.user-panel-image {
margin: 5px auto;
display: block;
}
.user-panel-header {
font-size: 26px;
text-align: center;
margin: 0;
color: black;
}
.user-panel-paragraph {
color: #A0A09E;
margin: 0;
text-align: center;
font-size: 19px;
}
<div class="user-panel-wrap">
<a class="user-panel-link" href="#">
<div class="user-panel">
<img class="user-panel-image" src="pictures/tockici.jpg">
<p class="user-panel-header">SERVICES</p>
<p class="user-panel-paragraph">It's what we do!</p>
</div>
</a>
<a class="user-panel-link" href="#">
<div class="user-panel">
<img src="pictures/cart.png" alt="" class="user-panel-image">
<p class="user-panel-header">ORDER</p>
<p class="user-panel-paragraph">Start the process!</p>
</div>
</a>
<a class="user-panel-link" href="#">
<div class="user-panel">
<img src="pictures/faq.png" alt="" class="user-panel-image">
<p class="user-panel-header">FAQ</p>
<p class="user-panel-paragraph">Find some answers</p>
</div>
</a>
<a class="user-panel-link" href="#">
<div class="user-panel">
<img src="pictures/login.jpg" alt="" class="user-panel-image">
<p class="user-panel-header">LOG IN</p>
<p class="user-panel-paragraph">Current clients</p>
</div>
</a>
</div>
The :last-child pseudo selector is applied on your wrapping div here. As a result you select the wrapper that is the last child of its parent. And because you only created one wrapper, you just select the only one you have.
I suspect that you want to select the last child of this wrapper. To do this, you need to do .user-panel-wrap > :last-child.
And because I also suspect that you want to set the margin not of the <a> tag but on the .user-panel, you should actually do .user-panel-wrap > :last-child .user-panel.
.user-panel {
border-bottom-color: #8F8F8F;
background-color: #FCFCFC;
border-style: solid;
border-width: 1px;
border-color: #D9D9D9;
float: left;
width: 257px;
margin-top: 40px;
border-bottom-color: #8F8F8F;
margin-right: 5px;
}
.user-panel-wrap > :last-child .user-panel {
margin-right: 0px;
}
.user-panel:hover {
background-color: #B2D195;
}
.user-panel-image {
margin: 5px auto;
display: block;
}
.user-panel-header {
font-size: 26px;
text-align: center;
margin: 0;
color: black;
}
.user-panel-paragraph {
color: #A0A09E;
margin: 0;
text-align: center;
font-size: 19px;
}
<div class="user-panel-wrap">
<a class="user-panel-link" href="#">
<div class="user-panel">
<img class="user-panel-image" src="pictures/tockici.jpg">
<p class="user-panel-header">SERVICES</p>
<p class="user-panel-paragraph">It's what we do!</p>
</div>
</a>
<a class="user-panel-link" href="#">
<div class="user-panel">
<img src="pictures/cart.png" alt="" class="user-panel-image">
<p class="user-panel-header">ORDER</p>
<p class="user-panel-paragraph">Start the process!</p>
</div>
</a>
<a class="user-panel-link" href="#">
<div class="user-panel">
<img src="pictures/faq.png" alt="" class="user-panel-image">
<p class="user-panel-header">FAQ</p>
<p class="user-panel-paragraph">Find some answers</p>
</div>
</a>
<a class="user-panel-link" href="#">
<div class="user-panel">
<img src="pictures/login.jpg" alt="" class="user-panel-image">
<p class="user-panel-header">LOG IN</p>
<p class="user-panel-paragraph">Current clients</p>
</div>
</a>
</div>
.user-panel-link:last-child .user-panel {
margin-right: 0px;
}
Hope this solution works for you ☝️
.user-panel {
border-bottom-color: #8F8F8F;
background-color: #FCFCFC;
border-style: solid;
border-width: 1px;
border-color: #D9D9D9;
float: left;
width: 257px;
margin-top: 40px;
border-bottom-color: #8F8F8F;
margin-right: 5px;
}
.user-panel:hover {
background-color: #B2D195;
}
.user-panel-image {
margin: 5px auto;
display: block;
}
.user-panel-header {
font-size: 26px;
text-align: center;
margin: 0;
color: black;
}
.user-panel-paragraph {
color: #A0A09E;
margin: 0;
text-align: center;
font-size: 19px;
}
.user-panel-link:last-child .user-panel {
margin-right: 0px;
}
<div class="user-panel-wrap">
<a class="user-panel-link" href="#">
<div class="user-panel">
<img class="user-panel-image" src="pictures/tockici.jpg">
<p class="user-panel-header">SERVICES</p>
<p class="user-panel-paragraph">It's what we do!</p>
</div>
</a>
<a class="user-panel-link" href="#">
<div class="user-panel">
<img src="pictures/cart.png" alt="" class="user-panel-image">
<p class="user-panel-header">ORDER</p>
<p class="user-panel-paragraph">Start the process!</p>
</div>
</a>
<a class="user-panel-link" href="#">
<div class="user-panel">
<img src="pictures/faq.png" alt="" class="user-panel-image">
<p class="user-panel-header">FAQ</p>
<p class="user-panel-paragraph">Find some answers</p>
</div>
</a>
<a class="user-panel-link" href="#">
<div class="user-panel">
<img src="pictures/login.jpg" alt="" class="user-panel-image">
<p class="user-panel-header">LOG IN</p>
<p class="user-panel-paragraph">Current clients</p>
</div>
</a>
</div>
:last-child is not working because .user-panel-wrap is the wrapper not the child selector. :last-child needs to be on the child, like this:
.parent-wrapper .child-name:last-child {
margin-right: 0px;
}
However, since you have .user-panel wrapped in a.user-panel-link, that will not work either. Try something like this:
<div class="user-panel-wrap">
<div class="user-panel">
<a class="user-panel-link" href="#">
<img class="user-panel-image" src="pictures/tockici.jpg">
<p class="user-panel-header">SERVICES</p>
<p class="user-panel-paragraph">It's what we do!</p>
</a>
</div>
<div class="user-panel">
<a class="user-panel-link" href="#">
<img src="pictures/cart.png" alt="" class="user-panel-image">
<p class="user-panel-header">ORDER</p>
<p class="user-panel-paragraph">Start the process!</p>
</a>
</div>
<div class="user-panel">
<a class="user-panel-link" href="#">
<img src="pictures/faq.png" alt="" class="user-panel-image">
<p class="user-panel-header">FAQ</p>
<p class="user-panel-paragraph">Find some answers</p>
</a>
</div>
<div class="user-panel">
<a class="user-panel-link" href="#">
<img src="pictures/login.jpg" alt="" class="user-panel-image">
<p class="user-panel-header">LOG IN</p>
<p class="user-panel-paragraph">Current clients</p>
</a>
</div>
</div>
With this CSS:
.user-panel-wrap .user-panel:last-child {
margin-right: 0px;
}

HTML/CSS Stretch anchor in div

I have the following code and want the anchor everywhere in the box not only at the image:
HTML:
<p style="clear:left" />
<div class="reference_container">
<div class="reference_box reference_box_geraete">
<a href="google.de">
<img src="http://www.hanselman.com/blog/content/binary/WindowsLiveWriter/Hans.NETMVCJeffAtwoodandhistechnicalteam_1349C/stackoverflow-logo-250_3.png"/>
</a>
</div>
<div class="reference_box reference_box_geraete">
<a href="google.de">
<img src="http://www.johndscomputers.com/wp-content/uploads/2014/02/200px-Apple_logo_black.svg_.png"/>
</a>
</div>
<div class="reference_box reference_box_geraete">
<a href="google.de">
<img src="http://www.johndscomputers.com/wp-content/uploads/2014/02/200px-Apple_logo_black.svg_.png"/>
</a>
</div>
<div class="reference_box reference_box_geraete">
<a href="google.de">
<img src="http://www.hanselman.com/blog/content/binary/WindowsLiveWriter/Hans.NETMVCJeffAtwoodandhistechnicalteam_1349C/stackoverflow-logo-250_3.png"/>
</a>
</div>
</div>
<p style="clear:left" />
CSS:
.reference_container {
display: flex;
}
.reference_box {
border: 1px solid #ddd;
border-radius: 5px;
margin: 1%;
position:relative;
overflow: hidden;
padding: 15px;
white-space: nowrap;
display:inline-block;
}
.reference_box_geraete {
width: 22%;
/*box-sizing: border-box;*/
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
.reference_box_geraete img {
vertical-align: middle;
max-width: 100%;
max-height: 100%;
}
The problem is that I don't get the anchor to stretch to the whole surrounding div.
I tried to remove the div and make the anchor as block-element, but then the images are not stretched correctly (doesn't keep aspect-ratio) when resizing the browser window.
How can I achieve this.
set width , height and display:block for element a
check this:
<p style="clear:left" />
<div class="reference_container">
<a class="reference_box reference_box_geraete" href="google.de">
<img src="http://www.hanselman.com/blog/content/binary/WindowsLiveWriter/Hans.NETMVCJeffAtwoodandhistechnicalteam_1349C/stackoverflow-logo-250_3.png"/>
</a>
<a href="google.de" class="reference_box reference_box_geraete">
<img src="http://www.johndscomputers.com/wp-content/uploads/2014/02/200px-Apple_logo_black.svg_.png"/>
</a>
<a href="google.de" class="reference_box reference_box_geraete">
<img src="http://www.johndscomputers.com/wp-content/uploads/2014/02/200px-Apple_logo_black.svg_.png"/>
</a>
<a href="google.de" class="reference_box reference_box_geraete">
<img src="http://www.hanselman.com/blog/content/binary/WindowsLiveWriter/Hans.NETMVCJeffAtwoodandhistechnicalteam_1349C/stackoverflow-logo-250_3.png"/>
</a>
</div>
<p style="clear:left" />
Demo: http://www.cssdesk.com/p5Cqd