Short text taking up 2 lines - html

I'm finding that on mobile, short text that i know can appear in just 1 line is taking up 2 lines.
I've found that "white-space: nowrap" will make sure that it will appear in 1 line. However, now I have a problem where long text that is supposed to take up 2 lines is now forced to appear in 1 line, which is a problem.
What's causing this issue and how do I solve it?
It's the third Lorem Ipsum
<div class="name">Lorem Ipsum </div>
That's causing this problem
What I want is that text that's supposed to take up 1 line (or 2 lines) take up just 1 line (or 2 lines).
.grid article {
position: relative;
}
.students {
position: absolute;
}
.person {
display: flex;
align-items: center;
margin,
padding: 0px;
}
.name {
letter-spacing: 2.2px;
flex: 1;
margin-left: 20px;
}
.picture {
flex: 0 0 28px;
margin: 0;
}
.person img {
margin-top: 0;
margin-bottom: 0;
vertical-align: middle;
}
#media (min-width: 1312px) {
.students {
top: 565px;
}
.name {
font-size: 15px;
letter-spacing: 2.2px;
margin-left: 20px;
}
.person img {
width: 28px;
}
.person {
margin-bottom: -1px;
}
}
#media (max-width: 599px) {
.students {
top: 375px;
}
.name {
font-size: 11px;
letter-spacing: 2.2px;
margin-left: 6px;
}
.person img {
width: 21px;
}
.person {
margin-bottom: 5px;
}
}
<article>
<a href="#">
<div class="photo" style="background-image: url(img/image.png);"></div>
</a>
<div class="text">
<div class="one">Lorem Ipsum</div>
<div class="two">Lorem Ipsum</div>
</div>
<div class="students">
<div class="person">
<div class="picture"><img src="img/sample.jpg"></div>
<div class="name">Lorem Ipsum </div>
</div>
</div>
</article>
Grid Layout CSS
.grid {
display: -ms-flexbox;
-ms-flex-wrap: wrap;
display: grid;
justify-content: start;
margin-top: -20px;
justify-content: space-between;
}
.grid article {
-ms-flex: 0 0 250px;
}
.grid .photo {
width: 100%;
background-size: contain;
background-position: center;
}
.grid .photo:after {
content: "";
display: block;
padding-bottom: 100%;
}
.grid a {
display: block;
text-decoration: none;
color: inherit;
}
.grid a:hover {
opacity: 0.8;
}
.grid .text {
margin: 0px;
}
#media (max-width: 599px) {
.grid {
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
grid-row-gap: 140px;
grid-column-gap: 20px;
margin-top: 18px;
}
}

Do you need the image to be next to the text on mobile?
If you want them to stay aligned then just add flex-direction: row; to your person class in the #media (max-width: 599px) and set a max-width on your picture and name div that doesn't exceed 599px.
If you want them to stack then just add flex-direction: column; to your person class in the #media (max-width: 599px)
Note: You may need to adjust width depending on how much text you want next to your image so it doesn't wrap when it hits the width threshold on mobile.
See snippet below.
.grid article {
position: relative;
}
.students {
position: absolute;
}
.person {
display: flex;
align-items: center;
margin,
padding: 0px;
}
.name {
letter-spacing: 2.2px;
flex: 1;
margin-left: 20px;
}
.picture {
flex: 0 0 28px;
margin: 0;
}
.person img {
margin-top: 0;
margin-bottom: 0;
vertical-align: middle;
}
#media (min-width: 1312px) {
.students {
top: 565px;
}
.name {
font-size: 15px;
letter-spacing: 2.2px;
margin-left: 20px;
}
.person img {
width: 28px;
}
.person {
margin-bottom: -1px;
}
}
#media (max-width: 599px) {
.students {
top: 375px;
}
.name {
font-size: 11px;
letter-spacing: 2.2px;
margin-left: 6px;
display: block;
width: 100%;
}
.picture {
width: 21px;
max-width: 21px;
}
.person {
flex-direction: row;
max-width: 200px;
}
}
<article>
<a href="#">
<div class="photo" style="background-image: url(img/image.png);"></div>
</a>
<div class="text">
<div class="one">Lorem Ipsum</div>
<div class="two">Lorem Ipsum</div>
</div>
<div class="students">
<div class="person">
<div class="picture"><img src="https://cdn.pixabay.com/photo/2020/10/28/11/08/castle-5693094__340.jpg"></div>
<div class="name">Lorem Ipsum </div>
</div>
</div>
</article>

Related

How to get text to align alongside image if image is larger?

This is my code which works - used vehicle platform - HTML with flex, but isn't quite esthetically pleasing:
body {
font-family: Verdana, sans-serif;
font-size: 16px;
line-height: 18px;
}
header.infog {
background-color: #333;
color: #FFF;
margin-bottom: 25px;
padding: 30px;
}
footer.infog {
background-color: #333;
color: #FFF;
margin-top: 20px;
margin-bottom: 25px;
padding: 10px;
}
.mainwrapper {
border: 2px solid;
display: table;
margin-left: 50px;
width: 900px;
}
.itemwrapper {
display: table-row;
width: 90px;
margin-right: -40px;
}
.itemwrapper1 {
display: table-row;
margin-left: -356em;
width: 100px;
}
.itemwrapper1 img {}
.some-page-wrapper {
margin: 15px;
}
.row {
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100%;
}
.column {
margin-left: 40px;
width: 600px;
color: #333;
margin: 0;
display: flex;
flex-direction: column;
flex-basis: 100%;
flex: 1;
padding: 20px;
}
.column1 {
margin-left: 40px;
background-color: blue;
color: #FFF;
margin: 0;
display: flex;
flex-direction: row;
flex-basis: 100%;
flex: 1;
padding: 20px;
}
.priceg {
font-size: 29px;
color: red;
padding-left: 500px;
}
.img-nac img {
max-width: 330px;
}
.img-nac1 img {
max-width: 460px;
}
.ncat {
flex-direction: row;
margin-left: -450px;
text-align: right 50px;
}
.ncat1 {
flex-direction: row;
margin-left: -200px;
text-align: right 50px;
}
.at1 {
white-space: nowrap;
margin-top: -20px;
}
.priceh {
margin-left: 180px;
margin-top: -20px;
}
.mainwrapper {
margin-bottom: 20px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Car , Van, Caravan Dealer | Quality Used Cars</title>
<link rel="stylesheet" type="text/css" href="styles/style.css">
</head>
<body>
<header class="infog">
header
</header>
<div class='some-page-wrapper'>
<div class='row'>
<div class='column1'>
2003 TOYOTA RAV4 2.0 GX
</div>
<div class='column1 priceg'>
£8995
</div>
</div>
<div class='row'>
<div class='column img-nac'>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a2/2013_Toyota_RAV4_XLE_AWD_front_left.jpg/1280px-2013_Toyota_RAV4_XLE_AWD_front_left.jpg">
</div>
<div class='column ncat'>
black
</div>
</div>
</div>
<div class='some-page-wrapper'>
<div class='row'>
<div class='column1'>
2003 TOYOTA RAV4 2.0 GX
</div>
<div class='column1 priceg'>
£8995
</div>
</div>
<div class='row'>
<div class='column img-nac1'>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a2/2013_Toyota_RAV4_XLE_AWD_front_left.jpg/1280px-2013_Toyota_RAV4_XLE_AWD_front_left.jpg">
</div>
<div class='column ncat'>
rowtt
</div>
</div>
</div>
<div class='some-page-wrapper'>
<div class='row'>
<div class='column img-nac'>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a2/2013_Toyota_RAV4_XLE_AWD_front_left.jpg/1280px-2013_Toyota_RAV4_XLE_AWD_front_left.jpg">
</div>
<div class='column at1'>
<h3>2004 TOYOTA RAV4 2.0</h4>
black
</div>
<div class='column priceh'>
<h3>£6000</h4>
</div>
</div>
</div>
<footer class="infog">
footer
</footer>
</body>
</html>
The problem is that I'm trying to make it so that if the image is large it's still alongside the text, like this from my page:
The blue line below is actually a bit of the next image... I didn't screencap well.
I've not figured out how to with the CSS and max-width size to do this, resulting in:
The car description in the second flexbox (column and ncat classes) doesn't show up.
But it works fine with the smaller image; I'm trying to make it big enough for people to see.
This isn't the final version, as I'm adding Roboto font etc. in the CSS, but it's almost working.
I'd much appreciate any advice on how to ensure I can get this to work in flexbox.
Just update your CSS with the following code
body {
font-family: Verdana, sans-serif;
font-size: 16px;
line-height: 18px;
}
header.infog {
background-color: #333;
color: #FFF;
margin-bottom: 25px;
padding: 30px;
}
footer.infog {
background-color: #333;
color: #FFF;
margin-top: 20px;
margin-bottom: 25px;
padding: 10px;
}
.mainwrapper {
border: 2px solid;
display: table;
margin-left: 50px;
width: 900px;
}
.itemwrapper {
display: table-row;
width: 90px;
margin-right: -40px;
}
.itemwrapper1 {
display: table-row;
margin-left: -356em;
width: 100px;
}
.some-page-wrapper {
margin: 15px;
}
.row {
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100%;
}
.column {
margin-left: 40px;
color: #333;
margin: 0;
display: flex;
flex-direction: column;
padding: 20px;
}
.column1 {
margin-left: 40px;
background-color: blue;
color: #FFF;
margin: 0;
display: flex;
flex-direction: row;
flex-basis: 100%;
flex: 1;
padding: 20px;
}
.priceg {
font-size: 29px;
color: red;
padding-left: 500px;
}
.img-nac img {
max-width: 330px;
}
.img-nac1 img {
max-width: 460px;
}
.ncat {
flex-direction: row;
text-align: right 50px;
}
.ncat1 {
flex-direction: row;
text-align: right 50px;
}
.at1 {
white-space: nowrap;
margin-top: -20px;
}
.priceh {
margin-left: 180px;
margin-top: -20px;
}
.mainwrapper {
margin-bottom: 20px;
}

How to make image resize with media query?

How would I make it so the image resizes properly when viewed on smaller screens. Right now, the image is over the container when viewed on smaller screens. There are also small gaps between the top/left of the container and the image. Would I have to resize the image in the media query or expand the width of my container in the media query?
.container {
width: 88%;
margin: 50px auto;
margin-top: 0px;
}
.heading {
text-align: center;
font-size: 30px;
margin-bottom: 50px;
}
.row {
display: flex;
flex-direction: row;
justify-content: space-around;
flex-flow: wrap;
}
.card {
width: 30%;
background: #fff;
border: 1px solid #ccc;
margin-bottom: 50px;
}
.image {
width: fit-content;
height: fit-content;
}
.card-body {
padding: 30px 10px;
text-align: left;
font-size: 18px;
}
.card-body .btn {
display: block;
color: #fff;
text-align: center;
background: black;
margin-top: 30px;
text-decoration: none;
padding: 10px 5px;
}
#media screen and (max-width: 1000px) {
.card {
width: 40%;
}
.heading {
text-align: auto;
}
.card-header {
margin: auto;
}
.image {
width: fit-content;
height: fit-content;
}
}
#media screen and (max-width: 620px) {
.container {
width: 100%;
}
.heading {
padding: 20px;
font-size: 20px;
text-align: auto;
}
.card {
width: 80%;
}
.image {
width: fit-content;
height: fit-content;
}
}
<div class="container">
<div class="heading">
<h1>Latest Posts</h1>
</div>
<div class="row">
<div class="card">
<div class="image">
<img src="https://via.placeholder.com/1920x1080.jpg">
</div>
<div class="card-body">
<p>
Text Here
</p>
Read more
</div>
</div>
I typically put width: 100%; on images in my projects and height: auto this way the image will be more responsive and scale up and down. You can reduce the width for the smaller media query if you want an even smaller image (width: 85%; for example) or I would probably personally end up reducing the width of the container to get the desired result.
1st: Remove your CSS for the class .image
2nd: Add this CSS line to the base-css (not within the media queries):
img {
object-fit: contain;
width: 100%;
}
What will that do?
object-fit: contain will keep the image aspect ratio while width: 100% will cause the image to fit exactly the given space. The height is set automatically according to the width while it maintain the image aspect ratio as mentioned above.
.container {
width: 88%;
margin: 50px auto;
margin-top: 0px;
}
.heading {
text-align: center;
font-size: 30px;
margin-bottom: 50px;
}
.row {
display: flex;
flex-direction: row;
justify-content: space-around;
flex-flow: wrap;
}
.card {
width: 30%;
background: #fff;
border: 1px solid #ccc;
margin-bottom: 50px;
}
.image {
width: fit-content;
height: fit-content;
}
.card-body {
padding: 30px 10px;
text-align: left;
font-size: 18px;
}
.card-body .btn {
display: block;
color: #fff;
text-align: center;
background: black;
margin-top: 30px;
text-decoration: none;
padding: 10px 5px;
}
img {
object-fit: contain;
width: 100%;
}
#media screen and (max-width: 1000px) {
.card {
width: 40%;
}
.heading {
text-align: auto;
}
.card-header {
margin: auto;
}
}
#media screen and (max-width: 620px) {
.container {
width: 100%;
}
.heading {
padding: 20px;
font-size: 20px;
text-align: auto;
}
.card {
width: 80%;
}
}
<div class="container">
<div class="heading">
<h1>Latest Posts</h1>
</div>
<div class="row">
<div class="card">
<div class="image">
<img src="https://via.placeholder.com/1920x1080.jpg">
</div>
<div class="card-body">
<p>
Text Here
</p>
Read more
</div>
</div>

remove "next to each other" placement on smaller screen sizes

I want to create a responsive navigation bar for my page. I use floating divs for the logo and navigation link bar.
If you want to test the fiddle I recommend opening this on full screen.
#navbar {
top: 0;
position: sticky;
height: 80px;
padding: 0 160px;
background: #232323;
}
.navbarItemContainer {
height: 100%;
}
#navbarLogoContainer {
display: flex;
float: left;
align-items: center;
}
#navbarLinkContainer {
display: grid;
grid-template-columns: 100px 100px 100px;
float: right;
text-align: center;
align-items: center;
}
.navbarLink {
color: #039be5;
transition: 0.2s;
}
.navbarLink:hover {
color: #25bdf7;
transition: 0.2s;
}
.navbarLink>img {
width: 32px;
height: 32px;
display: none;
}
#media only screen and (max-width: 1000px) {
#navbar {
padding: 0 60px;
}
.navbarLink>span {
display: none;
}
.navbarLink>img {
display: block;
}
.navbarLink>img {
width: 24px;
height: 24px;
}
#navbarLinkContainer {
grid-template-columns: 24px 24px 24px;
grid-gap: 0 40px;
}
}
#media only screen and (max-width: 400px) {
/* place logo above button bar */
#navbar {
background: red;
/* just a test */
}
}
<div id="navbar">
<div id="navbarLogoContainer" class="navbarItemContainer">
<a>
<img class="img" src="/resources/logo.png">
</a>
</div>
<div id="navbarLinkContainer" class="navbarItemContainer">
<a class="navbarLink">
<span>
Link 1
</span>
<img class="img" src="">
</a>
<a class="navbarLink">
<span>
Link 2
</span>
<img class="img" src="">
</a>
<a class="navbarLink">
<span>
Link 3
</span>
<img class="img" src="">
</a>
</div>
</div>
When it comes to mobile screen sizes the navigation bar with 6 icons is too big. I want to adjust the navigation bar at a screen size of 400px.
#media only screen and (max-width: 400px) {
#navbar {
background: red; // placeholder
}
}
I want to remove the floating divs and place the logo above the button bar. When it comes to a screen size smaller than 400px the logo would have to move one row up. The result would be
How can I achieve this?
EDIT:
I tried
#media only screen and (max-width: 400px) {
#navbarLogoContainer {
clear: left;
}
#navbarLinkContainer {
grid-template-columns: 33.33% 33.33% 33.33%;
clear: right;
}
}
but it did not help.
Try this:
#media only screen and (max-width: 400px) {
/* place logo above button bar */
#navbar {
background: red;
/* just a test */
}
#navbarLogoContainer {
display:block;
float:none;
text-align:center;
}
#navbarLinkContainer {
display: block;
width: 100%;
text-align: center;
}
.navbarItemContainer {
height: 30px;
padding: 5px 0;
}
.navbarLink {
display:inline-block;
}
}
I also made a snippet:
#navbar {
top: 0;
position: sticky;
height: 80px;
padding: 0 160px;
background: #232323;
}
.navbarItemContainer {
height: 100%;
}
#navbarLogoContainer {
display: flex;
float: left;
align-items: center;
}
#navbarLinkContainer {
display: grid;
grid-template-columns: 100px 100px 100px;
float: right;
text-align: center;
align-items: center;
}
.navbarLink {
color: #039be5;
transition: 0.2s;
}
.navbarLink:hover {
color: #25bdf7;
transition: 0.2s;
}
.navbarLink>img {
width: 32px;
height: 32px;
display: none;
}
#media only screen and (max-width: 1000px) {
#navbar {
padding: 0 60px;
}
.navbarLink>span {
display: none;
}
.navbarLink>img {
display: block;
}
.navbarLink>img {
width: 24px;
height: 24px;
}
#navbarLinkContainer {
grid-template-columns: 24px 24px 24px;
grid-gap: 0 40px;
}
}
#media only screen and (max-width: 400px) {
/* place logo above button bar */
#navbar {
background: red;
/* just a test */
}
#navbarLogoContainer {
display:block;
float:none;
text-align:center;
}
#navbarLinkContainer {
display: block;
width: 100%;
text-align: center;
}
.navbarItemContainer {
height: 30px;
padding: 5px 0;
}
.navbarLink {
display:inline-block;
}
}
<div id="navbar">
<div id="navbarLogoContainer" class="navbarItemContainer">
<a>
<img class="img" src="/resources/logo.png">
</a>
</div>
<div id="navbarLinkContainer" class="navbarItemContainer">
<a class="navbarLink">
<span>
Link 1
</span>
<img class="img" src="">
</a>
<a class="navbarLink">
<span>
Link 2
</span>
<img class="img" src="">
</a>
<a class="navbarLink">
<span>
Link 3
</span>
<img class="img" src="">
</a>
</div>
</div>
Let me know if this helped.
here is a simple working example that can help you with your code
.container {
height: 100vh;
}
.navbar {
display: flex;
}
.navbar .logo-container {
flex: 1;
display: flex;
}
.navbar .logo-container span {
flex: 1;
}
.navbar .links-container {
flex: 1;
display: flex;
}
.navbar .links-container div {
flex: 1;
}
#media only screen and (max-width: 400px) {
.navbar {
display: grid;
grid-template-rows: 150px auto;
grid-template-columns: repeat(6, 1fr);
}
.navbar .logo-container {
grid-column: 1/7;
display: flex;
justify-content: center;
text-align: center;
}
.navbar .links-container {
grid-column: 1/7;
display: flex;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="container">
<div class="navbar">
<div class="logo-container">
<span>image</span>
</div>
<div class="links-container">
<div>link1</div>
<div>link2</div>
<div>link3</div>
<div>link4</div>
<div>link5</div>
<div>link6</div>
</div>
</div>
</div>
</body>
</html>
For 400px I think I'll go for this one
What do you think about this solution?
#media only screen and (max-width: 400px){
#navbar {
height: 100px;
padding: 0 5px;
}
#navbarLogoContainer {
height: 50%;
display: block;
float: none;
text-align: center;
}
#navbarLinkContainer {
height: 50%;
display: grid;
float: none;
grid-template-columns: 16.66% 16.66% 16.66% 16.66% 16.66% 16.66%;
justify-items: center;
grid-gap: 0 5px;
}
}
#navbar {
top: 0;
position: sticky;
height: 80px;
padding: 0 160px;
background: #232323;
}
.navbarItemContainer {
height: 100%;
}
#navbarLogoContainer {
display: flex;
float: left;
align-items: center;
}
#navbarLinkContainer {
display: grid;
grid-template-columns: 100px 100px 100px;
float: right;
text-align: center;
align-items: center;
}
.navbarLink {
color: #039be5;
transition: 0.2s;
}
.navbarLink:hover {
color: #25bdf7;
transition: 0.2s;
}
.navbarLink>img {
width: 32px;
height: 32px;
display: none;
}
#media only screen and (max-width: 1000px) {
#navbar {
padding: 0 60px;
}
.navbarLink>span {
display: none;
}
.navbarLink>img {
display: block;
}
.navbarLink>img {
width: 24px;
height: 24px;
}
#navbarLinkContainer {
grid-template-columns: 24px 24px 24px;
grid-gap: 0 40px;
}
}
#media only screen and (max-width: 400px) {
/* place logo above button bar */
#navbar {
background: red;
/* just a test */
}
}
<div id="navbar">
<div id="navbarLogoContainer" class="navbarItemContainer">
<a>
<img class="img" src="/resources/logo.png">
</a>
</div>
<div id="navbarLinkContainer" class="navbarItemContainer">
<a class="navbarLink">
<span>
Link 1
</span>
<img class="img" src="">
</a>
<a class="navbarLink">
<span>
Link 2
</span>
<img class="img" src="">
</a>
<a class="navbarLink">
<span>
Link 3
</span>
<img class="img" src="">
</a>
</div>
</div>

allow button to expand fully in responsive grid without truncating text

I have a responsive grid and button container that appears on many different pages with different lengths of text on each page.
I don't want the text wrap so I have used white-space: nowrap on the button.
The problem is that the text is getting truncated for longer text such as save and continue.
Is there any way the text can expand to the amount needed irrespective of the width of the parent container?
I could use width: auto on the button but this falls apart at lower resolutions.
.wrapper {
margin: 0 auto;
padding: 0 15px;
}
.grid {
list-style: none;
margin: 0;
padding: 0;
margin-left: -30px;
}
.grid__item {
display: inline-block;
padding-left: 30px;
vertical-align: top;
width: 100%;
box-sizing: border-box;
}
.application-layout__container__right {
float: right;
}
.one-half {
width: 50%;
}
button {
width: 100%;
white-space: nowrap;
border: 1px solid #0065bd;
background-color: #0065bd;
color: #fff;
font-size: 16px;
height: auto;
text-transform: uppercase;
padding: 14px 22px;
line-height: 28px;
font-weight: bold;
cursor: pointer;
display: table;
vertical-align: middle;
text-align: center;
text-decoration: none;
border-radius: 0;
width: 100%;
}
#media (min-width: 380px) {
.application-layout__container {
padding-right: 0;
}
.wrapper {
max-width: 750px;
}
.medium--one-half {
width: 50%;
}
button {
font-size: 19px;
}
}
#media (min-width: 992px) {
.wrapper {
max-width: 970px;
}
.large--one-third {
width: 33.33333%;
}
}
#media (min-width: 1200px) {
.wrapper {
max-width: 1170px;
}
}
<div class="wrapper application-layout__button__wrapper">
<div class="grid">
<div class="grid__item one-half">
<div class="grid">
<div class="grid__item one-whole medium--one-half large--one-third ">
<button>Back
</button>
</div>
</div>
</div>
<div class="grid__item one-half application-layout__container__right">
<div class="grid">
<div class="grid__item one-whole medium--one-half large--one-third">
<button class="remote-submit-button__default button__default button__primary" type="button">Confirm and pay</button>
</div>
</div>
</div>
</div>
</div>
There is a value for what you need but it's not yet supported by all the broswer. It's fit-content that you can use with width/min-width:
.wrapper {
margin: 0 auto;
padding: 0 15px;
}
.grid {
list-style: none;
margin: 0;
padding: 0;
margin-left: -30px;
}
.grid__item {
display: inline-block;
padding-left: 30px;
vertical-align: top;
width: 100%;
box-sizing: border-box;
}
.application-layout__container__right {
float: right;
}
.one-half {
width: 50%;
}
button {
width: 100%;
white-space: nowrap;
border: 1px solid #0065bd;
background-color: #0065bd;
color: #fff;
font-size: 16px;
height: auto;
text-transform: uppercase;
padding: 14px 22px;
line-height: 28px;
font-weight: bold;
cursor: pointer;
display: table;
vertical-align: middle;
text-align: center;
text-decoration: none;
border-radius: 0;
min-width: fit-content;
}
#media (min-width: 380px) {
.application-layout__container {
padding-right: 0;
}
.wrapper {
max-width: 750px;
}
.medium--one-half {
width: 50%;
}
button {
font-size: 19px;
}
}
#media (min-width: 992px) {
.wrapper {
max-width: 970px;
}
.large--one-third {
width: 33.33333%;
}
}
#media (min-width: 1200px) {
.wrapper {
max-width: 1170px;
}
}
<div class="wrapper application-layout__button__wrapper">
<div class="grid">
<div class="grid__item one-half">
<div class="grid">
<div class="grid__item one-whole medium--one-half large--one-third ">
<button>Back
</button>
</div>
</div>
</div>
<div class="grid__item one-half application-layout__container__right">
<div class="grid">
<div class="grid__item one-whole medium--one-half large--one-third">
<button class="remote-submit-button__default button__default button__primary" type="button">Confirm and pay</button>
</div>
</div>
</div>
</div>
</div>

CSS - How to collapse floated right divs underneath on reduced screen width

I currently have a widget looking how I want it to a large screen, but have problems when reducing it to something mobile friendly.
The widget has a title section which was two additional fields which need to be floated to right, and only take up as much width as there is text inside of them. I need the title-text on the left to take up the rest of the remaining space.
this is what it looks like
my HTML looks something like this:
<div class="widget">
<div class="section-title">
<div class="title-info">
<div class="info-2">Info 2</div>
<div class="info-1">Info 1</div>
</div>
<div class="title-text">Title</div>
</div>
</div>
CSS looks like this:
.section-title {
height: 100%;
font-size: 1.3em;
color: white;
}
.section-title .title-text {
background-color: #3261AD;
padding: 20px;
}
.section-title .title-info {
display: inline-block;
float: right;
}
.section-title .info-1{
background-color: #264D8C;
padding: 20px;
display: inline-block;
float: right;
}
.section-title .info-2{
background-color: #5BB75B;
padding: 20px;
display: inline-block;
float: right;
}
#media (max-width: 420px) {
.section-title .title-text {
/* ??? */
display: block;
width: 100%;
float: left;
}
.section-title .title-info {
/* ??? */
display: block;
width: 100%;
}
}
The problem occurs when I try to reduce the screen width. I'd like the title-info to collapse beneath the title-text, but can't switch the divs around because then the divs don't float to the right in the order that I want. Is there a way of it look like the image below without sacrificing how it looks on full width or creating a separate markup for mobile?
How I want it to look on mobile
https://jsfiddle.net/cpc4c3kt/
.section-title {
height: 100%;
font-size: 1.3em;
color: white;
}
.section-title .title-text {
background-color: #3261AD;
padding: 20px;
}
.section-title .title-info {
display: inline-block;
float: right;
}
.section-title .info-1 {
background-color: #264D8C;
padding: 20px;
display: inline-block;
float: right;
}
.section-title .info-2 {
background-color: #5BB75B;
padding: 20px;
display: inline-block;
float: right;
}
#media (max-width: 420px) {
.section-title .title-text {
/* ??? */
display: block;
width: 80%;
padding:20px 10%;
float: left;
transform: translateY(-100%);
}
.section-title .title-info {
/* ??? */
display: block;
width: 100%;
transform: translateY(100%);
}
.section-title .title-info>div {
display: inline-block;
float: right;
width: 40%;
padding: 5%;
}
}
<div class="widget">
<div class="section-title">
<div class="title-info">
<div class="info-2">Info 2</div>
<div class="info-1">Info 1</div>
</div>
<div class="title-text">Title</div>
</div>
</div>
Try using Flexbox Grid Layout. Flexbox Layout Module is inbuilt in CSS3 so you don't have to import any CSS. I find it easier to use in positioning complex element layouts.
.section-title {
display: inline-flex;
justify-content: flex-start;
flex-flow: row nowrap;
font-size: 1.3em;
color: white;
width: 100%;
}
.title-text {
flex-basis: 70%;
background: #3261AD;
order: 1;
padding: 20px;
}
.title-info {
flex-basis: 30%;
order: 2;
display: inline-flex;
flex-flow: row nowrap;
}
.info-1 {
background: #264D8C;
order: 1;
flex-basis: 50%;
padding: 20px;
}
.info-2 {
background: #5BB75B;
order: 2;
flex-basis: 50%;
padding: 20px;
}
#media all and (max-width: 420px) {
.section-title {
flex-wrap: wrap;
}
.title-info {
flex-wrap: nowrap;
flex-basis: 100%;
}
.title-text {
flex-basis: 100%;
}
.info-1 {
flex-basis: 50%;
}
.info-2 {
flex-basis: 50%;
}
}
<div class="widget">
<div class="section-title">
<div class="title-info">
<div class="info-2">Info 2</div>
<div class="info-1">Info 1</div>
</div>
<div class="title-text">Title</div>
</div>
</div>
https://jsfiddle.net/yz93799v/