Positioning divs (left-right) with CSS [duplicate] - html

This question already has answers here:
CSS Float: Floating an image to the left of the text
(7 answers)
Align image to left of text on same line - Twitter Bootstrap3
(6 answers)
Wrap text around an image on bootstrap 3
(6 answers)
Closed 3 years ago.
I'm designing people cards and I need to positionate the image on the left side and the text on the right side but I'm having issues doing it.
.row {
display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;
}
.col-lg-3 {
position: relative;
width: 100%;
padding-right: 15px;
padding-left: 15px;
}
.media {
margin: 20px 0;
padding: 10px;
vertical-align: middle;
display: inline-block;
width: 100%;
overflow-wrap: break-word;
word-wrap: break-word;
}
<div class="row">
<div class="col-lg-3">
<div class="media">
<div id="left_div">
<img src="/web/image/hr.employee/7/image">
</div>
<div id="right_div">
<span class="label label-default">Marc Demo
<hr style="margin: 0em; border-width: 2px;">
</span>
<span class="label label-default"> HIPOACUSICOS
<hr style="margin: 0em; border-width: 2px;">
</span>
<span class="label label-default">mark.brown23#example.com
<hr style="margin: 0em; border-width: 2px; display: none;">
</span>
</div>
</div>
</div>
I'm trying to use position, width and another properties on "left_div" and "right_div" but I'm not able to format it.
Any suggestion?
Edit: Using display: flex and align-items: center this is the result of it:
Maybe the problem are the inherited styles of other parent divs?
Thanks for reading!

Use display: flex on .media, then use display: block on span elements
You could also avoid to use a presentational tag (<hr>) and use a border-bottom.
Note that if the horizontal space is not enough due to a narrow container you need to wrap the content as in my second example.
.media {
display: flex;
flex-flow: row wrap;
align-items: center; /* optional */
margin: 20px 0;
padding: 10px;
width: 100%;
background: #e8e8e8; }
.media > div {
padding: 10px; }
.media img {
vertical-align: middle;
max-width: 100%;
width: 200px; }
#left_div {
text-align: center;
flex: 1 0 25%; }
#right_div {
flex: 3 0 60%; }
.media span {
display: block;
padding: 5px 0;
word-break: break-all;
word-break: break-word;
border-bottom: 1px #ccc solid; }
<div class="media">
<div id="left_div">
<img src="https://i.stack.imgur.com/UJ3pb.jpg">
</div>
<div id="right_div">
<span class="label label-default">Marc Demo</span>
<span class="label label-default"> HIPOACUSICOS </span>
<span class="label label-default">mark.brown23#example.com </span>
</div>
</div>
<!-- example with narrow parent -->
<div style="width: 200px;">
<div class="media">
<div id="left_div">
<img src="https://i.stack.imgur.com/UJ3pb.jpg">
</div>
<div id="right_div">
<span class="label label-default">Marc Demo</span>
<span class="label label-default"> HIPOACUSICOS </span>
<span class="label label-default">mark.brown23#example.com </span>
</div>
</div>
</div>

Easiest way to do this is to use flexbox.
Make the parent, .media, a flex container, and align-items: center replacing vertical-align: middle
EDIT
I've edited my answer to show 2 "profile cards" side by side. In doing so, I've changed left_div and right_div into classes instead of id, and gave left_div a 40% width.
.row {
display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;
}
.col-lg-3 {
position: relative;
width: 100%;
padding-right: 15px;
padding-left: 15px;
display: flex;
}
.media {
margin: 20px 0;
padding: 10px;
display: flex;
align-items: center;
width: 100%;
overflow-wrap: break-word;
word-wrap: break-word;
background-color: #ddd;
margin-right: 15px;
}
.left_div {
width: 40%;
margin-right: 15px;
}
.right_div {
width: 60%;
}
img {
width: 100%;
height: auto;
}
<div class="row">
<div class="col-lg-3">
<div class="media">
<div class="left_div">
<img src="https://i.stack.imgur.com/UJ3pb.jpg">
</div>
<div class="right_div">
<span class="label label-default">Marc Demo
<hr style="margin: 0em; border-width: 2px;">
</span>
<span class="label label-default"> HIPOACUSICOS
<hr style="margin: 0em; border-width: 2px;">
</span>
<span class="label label-default">mark.brown23#example.com
<hr style="margin: 0em; border-width: 2px; display: none;">
</span>
</div>
</div>
<div class="media">
<div class="left_div">
<img src="https://i.stack.imgur.com/UJ3pb.jpg">
</div>
<div class="right_div">
<span class="label label-default">Some one
<hr style="margin: 0em; border-width: 2px;">
</span>
<span class="label label-default"> Barbar
<hr style="margin: 0em; border-width: 2px;">
</span>
<span class="label label-default">fubar#example.com
<hr style="margin: 0em; border-width: 2px; display: none;">
</span>
</div>
</div>
</div>
</div>

You could use flexbox for doing this stuff. Also, I would recommend using classes instead if id's because of css specificity
.row {
display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;
}
.col-lg-3 {
position: relative;
width: 100%;
padding-right: 15px;
padding-left: 15px;
}
.media {
margin: 20px 0;
padding: 10px;
display: flex;
}
.media > div{
display: flex;
justify-content: center;
flex-direction: column;
}
.media .right_div{
padding: 10px;
}
<div class="row">
<div class="col-lg-3">
<div class="media">
<div class="left_div">
<img src="https://placehold.it/200x200">
</div>
<div class="right_div">
<span class="label label-default">Marc Demo
<hr style="margin: 0em; border-width: 2px;">
</span>
<span class="label label-default"> HIPOACUSICOS
<hr style="margin: 0em; border-width: 2px;">
</span>
<span class="label label-default">mark.brown23#example.com
<hr style="margin: 0em; border-width: 2px; display: none;">
</span>
</div>
</div>
</div>

You could try a few things here - difficult to get the exact styles right without the design, but you could simply add "display: flex;" to the .media rules.
.row {
display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;
}
.col-lg-3 {
position: relative;
width: 100%;
padding-right: 15px;
padding-left: 15px;
}
.media {
margin: 20px 0;
padding: 10px;
vertical-align: middle;
display: inline-block;
width: 100%;
overflow-wrap: break-word;
word-wrap: break-word;
display: flex;
flex-flow: row nowrap;
}
/* You can customise the flex items here to adjust the spacing/styles etc. */
.media .left_div {
flex: 1;
}
.media .right_div {
flex: 1;
}
<div class="row">
<div class="col-lg-3">
<div class="media">
<div class="left_div">
<img src="/web/image/hr.employee/7/image">
</div>
<div class="right_div">
<span class="label label-default">Marc Demo
<hr style="margin: 0em; border-width: 2px;">
</span>
<span class="label label-default"> HIPOACUSICOS
<hr style="margin: 0em; border-width: 2px;">
</span>
<span class="label label-default">mark.brown23#example.com
<hr style="margin: 0em; border-width: 2px; display: none;">
</span>
</div>
</div>
</div>
I've also changed your HTML to use classes instead of IDs for left_div and right_div, as really an ID should not be used more than once on a page.

You can use display: flex to .media like this:
.media {
display: flex;
align-items: center;
margin: 20px 0;
padding: 10px;
vertical-align: middle;
display: inline-block;
width: 100%;
overflow-wrap: break-word;
word-wrap: break-word;
}
Also as I can see data getting out of container. You can use overflow-x: auto; or changing col-lg-3 to some larger classes

Add flex to media class as below
.media {
display: flex;
}

Related

Want Image and text in horizontal align and align same in the grid

<div>
<button style=" padding: 10px 16px 10px 16px;
vertical-align: middle;
margin: auto;
width: 32%;">
<img style=" width: 22px;
height: 22px;
vertical-align: middle; " src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/HTML5_logo_and_wordmark.svg/512px-HTML5_logo_and_wordmark.svg.png" alt="Text" />
<span>Click to Stage</span>
</button>
<button style=" padding: 10px 16px 10px 16px;
vertical-align: middle;
margin: auto;
width: 32%;">
<img style=" width: 22px;
height: 22px;
vertical-align: middle; " src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/HTML5_logo_and_wordmark.svg/512px-HTML5_logo_and_wordmark.svg.png" alt="Text" />
<span>Howzaat</span>
</button>
<button style=" padding: 10px 16px 10px 16px;
vertical-align: middle;
margin: auto;
width: 32%;">
<img style=" width: 22px;
height: 22px;
vertical-align: middle; " src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/HTML5_logo_and_wordmark.svg/512px-HTML5_logo_and_wordmark.svg.png" alt="Text" />
<span>Hurrey with the mission</span>
</button>
</div>
<div>
<button style=" padding: 10px 16px 10px 16px;
vertical-align: middle;
margin: auto;
width: 32%;">
<img style=" width: 22px;
height: 22px;
vertical-align: middle; " src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/HTML5_logo_and_wordmark.svg/512px-HTML5_logo_and_wordmark.svg.png" alt="Text" />
<span>Stage</span>
</button>
<button style=" padding: 10px 16px 10px 16px;
vertical-align: middle;
margin: auto;
width: 32%;">
<img style=" width: 22px;
height: 22px;
vertical-align: middle; " src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/HTML5_logo_and_wordmark.svg/512px-HTML5_logo_and_wordmark.svg.png" alt="Text" />
<span>catch me if you can</span>
</button>
<button style=" padding: 10px 16px 10px 16px;
vertical-align: middle;
margin: auto;
width: 32%;">
<img style=" width: 22px;
height: 22px;
vertical-align: middle; " src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/HTML5_logo_and_wordmark.svg/512px-HTML5_logo_and_wordmark.svg.png" alt="Text" />
<span>jungle mission</span>
</button>
</div>
Above is the code am trying. here all images positions are moving here and there w.r.t text. But i need it to be fixed in one position in all buttons and make it identical. I need all images to be aligned in both rows and text as well.
Images position should be fixed and text starting position should be same in all buttons and should be middle of the button.
Some ref here.. here images are aligned and text should also be aligned
enter image description here
in button style, add the following styles
display: flex;
align-items: center;
You could use flex to set up your desired grid (pick whichever sizing suits you, I set mine to 700px in width. If you delete the btn-wrapper class, it'll lose that property and go to 100% width.
You can mess around with how you want the image and text to be placed in the button by using justify-content: center, justify-content: flex-start, justify-content: flex-end, justify-content: space-between, justify-content: space-evenly, justify-content: space-around.
View Snippet in full screen for best visualization!
Example as Snippet:
:root {
--bs-gutter-x: 1.5rem;
--bs-gutter-y: 1.5rem;
}
.flex {
display: flex;
}
.row {
flex-direction: row;
margin-top: calc(var(--bs-gutter-y) * -1);
margin-right: calc(var(--bs-gutter-x) * -.5);
margin-left: calc(var(--bs-gutter-x) * -.5);
}
.row > * {
flex-shrink: 0;
max-width: 100%;
padding-right: calc(var(--bs-gutter-x) * .5);
padding-left: calc(var(--bs-gutter-x) * .5);
margin-top: var(--bs-gutter-y);
}
.col-3 {
flex: 0 0 auto;
width: 25%;
max-width: 25%
}
.full-width {
flex: 0 0 100%;
max-width: 100%;
}
.wrap {
flex-wrap: wrap;
}
.btn {
display: flex;
justify-content: flex-start;
align-items: center;
width: 100%;
font-weight: 400;
line-height: 1.5;
text-align: center;
text-decoration: none;
vertical-align: middle;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
padding: .375rem .75rem;
font-size: 1rem;
border-radius: .25rem;
transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
background-color: #6c757d;
border-color: #6c757d;
}
.btn-txt {
color: #fff;
}
.img {
width: 22px;
height: 22px;
vertical-align: middle;
content:url("https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/HTML5_logo_and_wordmark.svg/512px-HTML5_logo_and_wordmark.svg.png");
}
.btn-wrapper {
width: 700px;
}
<div class="btn-wrapper flex row full-width wrap">
<div class="flex col-3">
<button class="btn">
<img class="img" alt="Text" />
<span class="btn-txt">Text for btn one</span>
</button>
</div>
<div class="btn-container flex col-3">
<button class="btn">
<img class="img" alt="Text" />
<span class="btn-txt">Text for btn two</span>
</button>
</div>
<div class="btn-container flex col-3">
<button class="btn">
<img class="img" alt="Text" />
<span class="btn-txt">Text for btn three</span>
</button>
</div>
<div class="btn-container flex col-3">
<button class="btn">
<img class="img" alt="Text" />
<span class="btn-txt">Text for btn four</span>
</button>
</div>
<div class="btn-container flex col-3">
<button class="btn">
<img class="img" alt="Text" />
<span class="btn-txt">Text for btn five</span>
</button>
</div>
<div class="btn-container flex col-3">
<button class="btn">
<img class="img" alt="Text" />
<span class="btn-txt">Text for btn six</span>
</button>
</div>
</div>

Remove space between span-s

I want to remove this space to make <span>-s closer, but there is no any margin or padding that could add more space between them.
<!-- HTML -->
<div class="service-container" id="logo-title-service-container">
<span class="logo-text" id="logo-title">company name</span><br>
<span class="logo-text" id="logo-subtitle">This is a subtitle</span>
</div>
Sass
// Sass
#logo-title-service-container
text-align: left
padding-left: 10px
#logo-title
font-size: 18px
#logo-subtitle
padding-top: -5px
font-size: 12px
How can I remove the space between them?
You should remove the 'br' element first.
then make the display of title and subtitle block or as i did here make the parent display flex and flex-direction to column to make it work.
#logo-service-container {
width: 100%;
text-align: center;
padding-top: 15px;
display: flex;
align-items: center;
justify-content: center;
}
#logo-main {
width: 26px;
height: 26px;
}
#logo-title-service-container {
display: flex;
flex-direction: column;
text-align: left;
padding-left: 10px;
}
#logo-title {
font-size: 18px;
}
#logo-subtitle {
font-size: 12px;
}
<div class="sidebar" id="left-sidebar">
<div class="service-container" id="logo-service-container">
<img id="logo-main" src="resources/images/icons/logo.svg" alt="logo">
<div class="service-container" id="logo-title-service-container">
<span class="logo-text" id="logo-title">company name</span>
<span class="logo-text" id="logo-subtitle">This is a subtitle</span>
</div>
</div>
</div>
You should try to avoid <br>
replace the span with div
<div class="sidebar" id="left-sidebar">
<div class="service-container" id="logo-service-container">
<img id="logo-main" src="resources/images/icons/logo.svg" alt="logo">
<div class="service-container" id="logo-title-service-container">
<div class="logo-text" id="logo-title">company name</div>
<div class="logo-text" id="logo-subtitle">This is a subtitle</div>
</div>
</div>
</div>
SASS:
#logo-service-container
width: 100%
text-align: center
padding-top: 15px
display: flex
align-items: center
justify-content: center
#logo-main
$size: 26px
width: $size
height: $size
#logo-title-service-container
text-align: left
padding-left: 10px
#logo-title
font-size: 18px
#logo-subtitle
padding-top: -5px
font-size: 12px

How can I make my html text containers more responsive?

My site looks like this:
DESKTOP:
MOBILE:
However, I need the text to be inline with the middle of the corresponding image (both items centered, so that the subtext isn't off-centered).
My HTML:
<div class="col-lg-3>
<div class="container--wrap">
<div class="inward-text">
<br>
<img src="green-up.png" class="center" style="vertical-align: middle;">
<br>
<span style="color: #9BDDB4; font-family: robotobold; font-size: 30px; vertical-align: middle;" "="">4.51%</span>
<br>
<span style="color: #ffffff; font-family: robotolight; font-weight: lighter; font-size: 15px">from yesterday</span>
<img src="red-up.png" class="center" style="padding-top: 30px; vertical-align: middle;">
<br>
<br>
<br>
<br>
<div id="txtdown">
<span style="color: #EE939C; font-family: robotobold; font-size: 30px; vertical-align: middle;">1.80%</span>
<br>
<span style="color: #ffffff; font-family: robotolight; font-weight: lighter; font-size: 15px">from yesterday</span>
</div>
<img src="flag-ic.png" class="center" style="padding-top: 30px; vertical-align: middle;">
<br>
<br>
<br>
<div id="txtdown">
<span style="color: #AEAEAE; font-family: robotobold; font-size: 30px; vertical-align: middle;">text</span>
<br>
<span style="color: #ffffff; font-family: robotolight; font-weight: lighter; font-size: 15px">subtext</span>
</div>
</div>
</div>
</div>
Relevant CSS:
.container--wrap {
background-color: #000000;
border-radius: 15px;
margin: 5px;
overflow: hidden;
}
.col-lg-3 {
flex: 0 0 25%;
max-width: 25%;
}
.col {
flex-basis: 0;
flex-grow: 1;
max-width: 100%;
}
.center {
display: block;
margin-left: auto;
margin-right: auto;
width: 135px;
}
.inward-text span{
display: inline;
margin-left: 10px;
}
.inward-text img{
margin-left: 80px;
float: left;
}
#txtdown{
margin-top: 10px;
}
How do I do what I want to be doing?
EDIT:
I apologise in advance for the extremely messy <br>s that there are!
br tags it is not the best approach, I try to simplify your solution, block with your image and text should be like there:
<div class="items">
<div class="item red">
<img/>
<div class="item__text">
<span class="percent"></span>
<span class="description"></span>
</div>
</div>
<div class="item green">
<img/>
<div class="item__text">
<span class="percent"></span>
<span class="description"></span>
</div>
</div>
<div class="item grey">
<img/>
<div class="item__text">
<span class="percent"></span>
<span class="description"></span>
</div>
</div>
</div>
CSS
.items {
display: flex;
flex-direction: column;
}
.item {
display: flex;
align-items: center;
}
.item__text {
display: flex;
flex-direction: column;
}
And don't use be, use margin or padding, it is a more flexible and reliable approach.
Html:
<div class="container--wrap">
<div class="inward-text">
<div class="flex">
<img src="green-up.png" class="center" style="vertical-align: middle;">
<div id="txtdown">
<span style="color: #9BDDB4; font-size: 30px; vertical-align: middle;">4.51%</span>
<span style="color: #ffffff; font-weight: lighter; font-size: 15px">from yesterday</span>
</div>
</div>
<div class="flex">
<img src="green-up.png" class="center" style="padding-top: 30px; vertical-align: middle;">
<div id="txtdown">
<span style="color: #EE939C; font-size: 30px; vertical-align: middle;">1.80%</span>
<span style="color: #ffffff; font-weight: lighter; font-size: 15px">from yesterday</span>
</div>
</div>
<div class="flex">
<img src="green-up.png" class="center" style="padding-top: 30px; vertical-align: middle;">
<div id="txtdown">
<span style="color: #AEAEAE; font-size: 30px; vertical-align: middle;">text</span>
<span style="color: #ffffff; font-weight: lighter; font-size: 15px">subtext</span>
</div>
</div>
</div>
</div>
Css:
.container--wrap {
background-color: #000000;
border-radius: 15px;
margin: 5px;
overflow: hidden;
}
.flex {
display: flex;
}
.col-lg-3 {
flex: 0 0 25%;
max-width: 25%;
}
.col {
flex-basis: 0;
flex-grow: 1;
max-width: 100%;
}
.inward-text span {
display: inline;
margin-left: 10px;
}
#txtdown {
margin-top: 10px;
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
}
Step 1
Remove all inline styles from each element and place them in CSS, as classes, along these lines:
.percent {
color: #EE939C;
font-family: robotobold;
font-size: 30px;
vertical-align: middle;
}
.detail {
color: #ffffff;
font-family: robotolight;
font-weight: lighter;
font-size: 15px;
}
Step 2
Remove all <br/>s
Step 3
Wrap each of the items as the following markup
<div class="fancy-item"> <!-- your group -->
<img ...>
<div> <!-- flexbox sub-group -->
<span class="percent">1.80%</span>
<span class="detail">from yesterday</span>
</div>
</div>
Add the rest of your CSS:
.fancy-item {
display: flex;
align-items: center;
}
Step 4
Add some bottom margin to .percent or top margin to .detail if you want to set them slightly apart.
You're done!
Note: You don't have to use my class names, use whatever makes sense in your context.
Another note: Steps 1-3 are the most important. They allow you to change all the items at once, if you don't like a particular detail, without having to go through each of them and do the modification. DRY is one of the most important principles in programming.

Align 3 columns, middle column HR adjustable

i have this section:
What I'm trying to achieve, is to have the left span, with a padding on the right, then on the middle the HR, and on the right the span with the price, but I want to have the price align to the right, and make the HR adjustable, so it always ends on the price and starts after the first span. I'm not being able to achieve this, no matter what I try.
Here is the code:
<div class="ementaspan"><span class="span1"><h5 class="font-150690 h5 font-weight-600 text-color-118181-color" style="
display: inline-block;
"><span>Creme de Baunilha</span></h5></span> <span><hr class="dotted border-accent-color separator-no-padding" style="width: 90%;border-top-width: 4px;"></span><span class="span3"><h5 class="font-150690 h5 font-weight-300"><span>1,60€</span></h5></span></div>
Creme de Nata 1,60€
And the CSS:
.ementaspan span h5, .ementaspan hr {
display: inline-block !important;
}
.ementaspan {
text-align: left !important;
}
.ementaspan .span1 {
width: 25% !important;
}
.ementaspan .span1 h5 {
padding-right: 25px;
}
.ementaspan hr {
width: 50% !important;
}
.ementaspan .span3 {
width: 25% !important;
}
.ementaspan .span3 h5 {
padding-left: 25px;
}
the easiest way is to do it with flex
.maindiv {
display: flex;
width: 100%;
justify-content: space-between;
align-items: flex-end;
}
.maindiv .div1 {
padding-right: 20px;
}
.maindiv .div2 {
flex: 1 1 auto;
}
.maindiv .div2 hr {
height: 0;
background: none;
color: transparent;
border-bottom: 3px dotted #f00;
border-top: none !important;
margin: 0 0 4px !important;
}
.maindiv .div3 {
padding-left: 20px;
color: #f00;
}
<div class="maindiv">
<div class="div1">Creme de Baunilha</div>
<div class="div2"><hr></div>
<div class="div3">1,60€</div>
</div>
<div class="maindiv">
<div class="div1">Creme de Nata</div>
<div class="div2"><hr></div>
<div class="div3">11,60€</div>
</div>
<div class="maindiv">
<div class="div1">Baunilha e Noz</div>
<div class="div2"><hr></div>
<div class="div3">1,60€</div>
</div>
<div class="maindiv">
<div class="div1">Baunilha e Cookies</div>
<div class="div2"><hr></div>
<div class="div3">121,60€</div>
</div>
Playing a little with your code,
I ended up with this:
.ementaspan {
display: flex;
width: 100%;
text-align: left !important;
}
.ementaspan span h5 {
display: inline-block !important;
}
.ementaspan .span2 {
flex: auto;
padding: 20px; /* Instead of padding on span1 and span3 */
}
.ementaspan hr {
background: none;
color: transparent;
border: 0; /* Resets hr style */
border-bottom: 4px dotted #f00;
}
.ementaspan .span3 {
width: 25% !important;
color: #f00;
}
<div class="ementaspan">
<span class="span1">
<h5 class="font-150690 h5 font-weight-600 text-color-118181-color" style="
display: inline-block;
"><span>Creme de Baunilha</span></h5>
</span>
<span class="span2">
<hr class="dotted border-accent-color separator-no-padding">
</span>
<span class="span3">
<h5 class="font-150690 h5 font-weight-300"><span>1,60€</span></h5>
</span>
</div>
<div class="ementaspan">
<span class="span1">
<h5 class="font-150690 h5 font-weight-600 text-color-118181-color" style="
display: inline-block;
"><span>Creme de Nata</span></h5>
</span>
<span class="span2">
<hr class="dotted border-accent-color separator-no-padding">
</span>
<span class="span3">
<h5 class="font-150690 h5 font-weight-300"><span>2,60€</span></h5>
</span>
</div>
<div class="ementaspan">
<span class="span1">
<h5 class="font-150690 h5 font-weight-600 text-color-118181-color" style="
display: inline-block;
"><span>Baunilha e Noz</span></h5>
</span>
<span class="span2">
<hr class="dotted border-accent-color separator-no-padding">
</span>
<span class="span3">
<h5 class="font-150690 h5 font-weight-300"><span>10,60€</span></h5>
</span>
</div>
Note that I kept all your classes and your html structure.
The only HTML modification is the span2 class,
then you'll only need to copy/paste the CSS to try it!
I hope it helps.

Target specific div with pseudo element

I'am trying to simply target the third div in my html with a class of .counter-wrap. On a mobile device this div has a margin-bottom of 40px. I want to remove the margin-bottom on the third stacked div named .counter-wrap.
I thought I could simply do .counter-wrap: last-of-type but the reason this doesn't work I believe is because each .counter-wrap is in its own .col class. Can this be done with a pseudo element or would I be better off just using a unique id on the last .counter-wrap div and just apply margin-bottom: 0?
body {
color: black;
font-size: 15px;
}
.wrap {
width: 600px;
margin: 0 auto;
}
.container,
.container-long {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto
}
.row {
margin-left: -15px;
margin-right: -15px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.col {
position: relative;
padding-right: 15px;
padding-left: 15px;
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
}
.counter-wrap {
margin-bottom: 40px;
}
.counter-text,
.counter-number {
display: block;
text-align: center;
text-transform: uppercase;
color: black;
}
.counter-text {
letter-spacing: normal;
font-weight: 400;
}
.counter-number {
font-size: 60px;
font-weight: 500;
}
<div class="wrap">
<div class="container">
<div class="row">
<div class="col">
<div class="counter-wrap">
<span class="counter-text">Line1</span>
<span class="counter-number count">1234</span>
<span class="counter-text">Line 2</span>
</div>
</div>
<div class="col">
<div class="counter-wrap">
<span class="counter-text">Line1</span>
<span class="counter-number count">1234</span>
<span class="counter-text">Line 2</span>
</div>
</div>
<div class="col">
<div class="counter-wrap">
<span class="counter-text">Line1</span>
<span class="counter-number count">1234</span>
<span class="counter-text">Line 2</span>
</div>
</div>
</div>
</div>
</div>
Use last-of-type selector on the col class like this:
.col:last-of-type .counter-wrap {
margin-bottom: 0;
}
See demo below:
body {
color: black;
font-size: 15px;
}
.wrap {
width: 600px;
margin: 0 auto;
}
.container,
.container-long {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto
}
.row {
margin-left: -15px;
margin-right: -15px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.col {
position: relative;
padding-right: 15px;
padding-left: 15px;
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
}
.counter-wrap {
margin-bottom: 40px;
}
/*ADDED*/
.col:last-of-type .counter-wrap {
margin-bottom: 0;
}
.counter-text,
.counter-number {
display: block;
text-align: center;
text-transform: uppercase;
color: black;
}
.counter-text {
letter-spacing: normal;
font-weight: 400;
}
.counter-number {
font-size: 60px;
font-weight: 500;
}
<div class="wrap">
<div class="container">
<div class="row">
<div class="col">
<div class="counter-wrap">
<span class="counter-text">Line1</span>
<span class="counter-number count">1234</span>
<span class="counter-text">Line 2</span>
</div>
</div>
<div class="col">
<div class="counter-wrap">
<span class="counter-text">Line1</span>
<span class="counter-number count">1234</span>
<span class="counter-text">Line 2</span>
</div>
</div>
<div class="col">
<div class="counter-wrap">
<span class="counter-text">Line1</span>
<span class="counter-number count">1234</span>
<span class="counter-text">Line 2</span>
</div>
</div>
</div>
</div>
</div>
Please check the updated code. You only need to update this css rest you will get the desired result.
.wrap .col:last-child .counter-wrap {
margin-bottom: 0;
}
body {
color: black;
font-size: 15px;
}
.wrap {
width: 600px;
margin: 0 auto;
}
.container,
.container-long {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto
}
.row {
margin-left: -15px;
margin-right: -15px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.col {
position: relative;
padding-right: 15px;
padding-left: 15px;
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
}
.counter-wrap {
margin-bottom: 40px;
}
.counter-text,
.counter-number {
display: block;
text-align: center;
text-transform: uppercase;
color: black;
}
.counter-text {
letter-spacing: normal;
font-weight: 400;
}
.counter-number {
font-size: 60px;
font-weight: 500;
}
.wrap .col:last-child .counter-wrap {
margin-bottom: 0;
}
<div class="wrap">
<div class="container">
<div class="row">
<div class="col">
<div class="counter-wrap">
<span class="counter-text">Line1</span>
<span class="counter-number count">1234</span>
<span class="counter-text">Line 2</span>
</div>
</div>
<div class="col">
<div class="counter-wrap">
<span class="counter-text">Line1</span>
<span class="counter-number count">1234</span>
<span class="counter-text">Line 2</span>
</div>
</div>
<div class="col">
<div class="counter-wrap">
<span class="counter-text">Line1</span>
<span class="counter-number count">1234</span>
<span class="counter-text">Line 2</span>
</div>
</div>
</div>
</div>
</div>
You can use the nth-child() rule. Apply it to the parent element and then input the number of which child class you wish to target. In this case it would be
.col:nth-child(3) .counter-wrap {
background:red;
}
body {
color: black;
font-size: 15px;
}
.wrap {
width: 600px;
margin: 0 auto;
}
.container,
.container-long {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto
}
.row {
margin-left: -15px;
margin-right: -15px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.col {
position: relative;
padding-right: 15px;
padding-left: 15px;
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
}
.counter-wrap {
margin-bottom: 40px;
}
.counter-text,
.counter-number {
display: block;
text-align: center;
text-transform: uppercase;
color: black;
}
.counter-text {
letter-spacing: normal;
font-weight: 400;
}
.counter-number {
font-size: 60px;
font-weight: 500;
}
.col:nth-child(3) .counter-wrap {
background:red;
}
<div class="wrap">
<div class="container">
<div class="row">
<div class="col">
<div class="counter-wrap">
<span class="counter-text">Line1</span>
<span class="counter-number count">1234</span>
<span class="counter-text">Line 2</span>
</div>
</div>
<div class="col">
<div class="counter-wrap">
<span class="counter-text">Line1</span>
<span class="counter-number count">1234</span>
<span class="counter-text">Line 2</span>
</div>
</div>
<div class="col">
<div class="counter-wrap">
<span class="counter-text">Line1</span>
<span class="counter-number count">1234</span>
<span class="counter-text">Line 2</span>
</div>
</div>
</div>
</div>
</div>