I'm creating a series of cards to display on screen with both an image and text using bootstrap. The cards render as expected on desktop (see below), but fail to render properly on mobile (I need to have the image and text on the same line like in the desktop version).
On mobile it looks like so:
I'm trying to keep it all inline (like grubhub does)
My code is as follows:
<div className="container">
<div className="row">
<div className="d-flex col-sm-6">
<div className="" style={{backgroundColor: 'white', borderRadius: 5, border: '1px solid #EAE8E8'}}>
<div className="row">
<div className="d-flex col-sm-8">
<div className="row" style={{paddingTop: 20, paddingBottom: 20, paddingLeft: 40}}>
<h4>
<b>{this.props.food.name}</b>
</h4>
<p style={{'fontWeight': 300}}>{this.props.food.description}</p>
<span className="munchtime pointer" style={{'fontSize': 16, 'fontWeight': 600}}>Add to Cart</span><br /><br />
{priceLabel}
</div>
</div>
<div className="d-flex col-sm-4">
<img src={this.props.food.images[0]} style={{width: '100%', height: 180, objectFit: 'cover'}} />
</div>
</div>
</div>
</div>
</div>
</div>
Any advice is appreciated!
Basically, you need to change your columns col-sm-8 and col-sm-4 by col-8 and col-4 respectively. I have made a basic example showing this also including some of your style:
.card-wrapper {
background-color: white;
border-radius: 5px;
border: 1px solid #EAE8E8;
}
.info-wrapper {
padding-top: 20px;
padding-bottom: 20px;
padding-left: 40px;
}
.custom-img {
width: 100%;
height: 180px;
object-fit: cover;
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<div class="container">
<div class="row">
<!-- Card 1 -->
<div class="col-sm-6">
<div class="row m-1 card-wrapper">
<div class="col-8 info-wrapper">
<h4><b>Food Name</b></h4>
<p>Food Description</p>
</div>
<div class="col-4 p-0">
<img class="custom-img" src="https://via.placeholder.com/250"/>
</div>
</div>
</div>
<!-- Card 2 -->
<div class="col-sm-6">
<div class="row m-1 card-wrapper">
<div class="col-8 info-wrapper">
<h4><b>Food Name</b></h4>
<p>Food Description</p>
</div>
<div class="col-4 p-0">
<img class="custom-img" src="https://via.placeholder.com/250"/>
</div>
</div>
</div>
</div>
</div>
Related
How does one overlay a bootstrap column on top of another column, but also keep its size and responsiveness?
For example, I have 4 columns in a row:
When I click on the Overlay btn, it should show the E column over B:
I currently have this test code I am playing with:
Live jsfiddle: https://jsfiddle.net/8pmt6ck2/2/
$(".a .btn").click(function() {
$(".e").toggleClass("d-none");
});
.one .a {
background-color: red;
}
.one .b {
background-color: blue;
}
.one .c {
background-color: green;
}
.one .d {
background-color: pink;
}
.one .e {
background-color: orange;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<div class="container one">
<div class="row">
<div class="col-sm-3 a">
<div class="vh-100 text-center">
<span>A</span>
<button class="btn btn-primary">Overlay btn</button>
</div>
</div>
<div class="col-sm-3 b">
<div class="vh-100">
<span>B</span>
</div>
</div>
<div class="col-sm-3 c">
<div class="vh-100">
<span>C</span>
</div>
</div>
<div class="col-sm-3 d">
<div class="vh-100">
<span>D</span>
</div>
</div>
<div class="col-sm-3 e position-absolute d-none">
<div class="vh-100">
<span>E</span>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
I am using d-none for E because it does not take up space, otherwise it'll cause Bootstrap to think there are 5 columns, when it's actually 4 columns and one overlay column (on top of B).
The above code sort of works due to position-absolute, but it's in the wrong location, and the column size is not the same as the other 4 columns (appears wider):
Part of the confusion also stems from the bootstrap documentation. It appears if I use position-absolute, I can only position things in certain quadrants of the screen, using top-, start-, end-, and bottom-:
https://getbootstrap.com/docs/5.0/utilities/position/
But because I need this to be responsive and match the column width and such of existing columns in the row, those positioning classes don't help me much here.
How can I overlay my E column properly? Ideally the solution should work for any number of columns in a row, not just 4 like I have above.
Absolute positioning is often problematic and unnecessary. Just toggle the columns in standard layout.
$(".a .btn").click(function() {
$(".b, .e").toggleClass("d-none");
});
.one .a {
background-color: red;
}
.one .b {
background-color: blue;
}
.one .c {
background-color: green;
}
.one .d {
background-color: pink;
}
.one .e {
background-color: orange;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<div class="container one">
<div class="row">
<div class="col-sm-3 a">
<div class="vh-100 text-center">
<span>A</span>
<button class="btn btn-primary">Overlay btn</button>
</div>
</div>
<div class="col-sm-3 b">
<div class="vh-100">
<span>B</span>
</div>
</div>
<div class="col-sm-3 e d-none">
<div class="vh-100">
<span>E</span>
</div>
</div>
<div class="col-sm-3 c">
<div class="vh-100">
<span>C</span>
</div>
</div>
<div class="col-sm-3 d">
<div class="vh-100">
<span>D</span>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
If you actually need both columns visible, I'd propose toggling contents instead of columns. Here you will use absolute positioning. I'm also toggling the style class on the column.
$(".a .btn").click(function() {
$('.b-e').toggleClass('b e');
$(".b-e .col-overlay").toggleClass("d-none");
});
.one .a {
background-color: red;
}
.one .b {
background-color: blue;
}
.one .c {
background-color: green;
}
.one .d {
background-color: pink;
}
.one .e {
background-color: orange;
left: 0;
right: 0;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<div class="container one">
<div class="row">
<div class="col-sm-3 a">
<div class="vh-100 text-center">
<span>A</span>
<button class="btn btn-primary">Overlay btn</button>
</div>
</div>
<div class="col-sm-3 b-e b position-relative">
<div class="vh-100 col-overlay position-absolute d-none">
<span>E</span>
</div>
<div class="vh-100">
<span>B</span>
</div>
</div>
<div class="col-sm-3 c">
<div class="vh-100">
<span>C</span>
</div>
</div>
<div class="col-sm-3 d">
<div class="vh-100">
<span>D</span>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
I am using bootstrap and I am trying to create the following layout:
I tried
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-lg-2 text-left">
<div class="card card-primary">
<div class="card-body p-2">
<img class="tv-symbol-icon tv-symbol-icon--size-auto" src="https://s3-symbol-logo.tradingview.com/apple--big.svg" alt="Apple Inc icon">
<div>APPLE INC (AAPL)</div>
<div>NASDAQ</div>
<div><img class="tv-flag-country tv-flag-country--us tv-flag-country--size_sub_title" src="https://www.tradingview.com/static/images/svg/common/flags/flag-square-us.svg" alt="US Flag"></div>
</div>
</div>
</div>
I tried flexboxes, however my layout does not arrange.
How to arrange the text next to the image?
Any suggestions what I am doing wrong?
You were 95% the way there. I have finished it off for you.
Really all you were missing was some nested bootstrap to make a col-10 that contains the company details sitting alongside the logo.
.name {
font-size: 2rem;
}
.tv-symbol-icon {
border-radius: 50%;
width: 100%;
}
.tv-flag-country {
margin: 0 0.5em;
border-radius: 50%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-lg-2 text-left">
<div class="card card-primary">
<div class="card-body p-2">
<div class="row">
<div class="col-sm-2">
<img class="tv-symbol-icon tv-symbol-icon--size-auto" src="https://s3-symbol-logo.tradingview.com/apple--big.svg" alt="Apple Inc icon">
</div>
<div class="col-sm-10">
<div class="row">
<div class="name">APPLE INC</div>
</div>
<div class="row">
<div>NASDAQ</div>
<div><img class="tv-flag-country tv-flag-country--us tv-flag-country--size_sub_title" src="https://www.tradingview.com/static/images/svg/common/flags/flag-square-us.svg" alt="US Flag"></div>
<div>(AAPL)</div>
</div>
</div>
</div>
</div>
</div>
</div>
I want to place 2 links on the left and 1 on the right side under some images.
The images are all different sizes and everything in my main div is centered.
main .about p {
margin-left: 50%;
transform: translateX(-50%);
width: 700px;
line-height: 1.5;
font-weight: 400;
z-index: 9;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<main class="section mb-5">
<!-- Main -->
<section class="container mb-4">
<div class="row">
<div class="col-md-12 ml-md-auto text-center about">
<header>
<h1 class="mb-3">Some Title</h1>
</header>
<img src="image.jpg" height="484" width="700">
<p class="text-left">
FHD Ansicht |
4K Ansicht
</p>
</div>
</div>
</section>
</main>
At the moment i did set the paragraph under the image to the width of the image:
And it looks like this with text only on the left side:
What i need is:
I guess a figure around the image and the text inside it is part of the solution.
Whats the best way doing it in the latest bootstrap?
Try playing with this snippet:
<main class="container-fluid">
<div class="row">
<img class="col-md-12" src="#" alt="test" style="background-color: blue; height: 400px;">
</div>
<div class="row subtitle-container">
<div class="col-md-10 left-subtitle">
Some Text | Some Text
</div>
<div class="col-md-2 right-subtitle">
Some Text
</div>
</div>
</main>
You can use float-left and float-right bootstrap classes to get texts to the left and right.
main .about p {
margin-left: 50%;
transform: translateX(-50%);
width: 700px;
line-height: 1.5;
font-weight: 400;
z-index: 9;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<main class="section mb-5">
<!-- Main -->
<section class="container mb-4">
<div class="row">
<div class="col-md-12 ml-md-auto text-center about">
<header>
<h1 class="mb-3">Some Title</h1>
</header>
<img src="image.jpg" class="w-100" height="484" width="700">
<div class="text-center clearfix">
FHD Ansicht
<span class="float-left mx-2">|</span>
4K Ansicht
<!-- <span>|</span> -->
another link
</div>
</div>
</div>
</section>
</main>
I am new to bootstrap and now making a website with it.
I want to align small images in one row for my mobile view. The code is used for it is below
<div class="mobile">
<div class="container">
<div class="row">
<div class="col-sm-1 col-xs-1">
<img src="assets/img/icon/birthday.png" alt="" style="height: 50px; width: 50px;"><p style="text-transform: uppercase;"><b>Birthday</b></p>
</div>
<div class="col-sm-1 col-xs-1">
<img src="assets/img/icon/birthday.png" alt="" style="height: 50px; width: 50px;"><p style="text-transform: uppercase;"><b>Birthday</b></p>
</div>
</div>
</div>
</div>
with this, the result is below
Not in one row
All I want is that it appear side to side and not stacked. Please help me
Thanks in advance
col-sm-1 is too small and the width doesn't fit the content that the reason it broke line.
so set col-sm->1
Also in bootstrap 4 there is no xs size. so remove it
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="mobile">
<div class="container">
<div class="row">
<div class="col-sm-2">
<img src="https://i.stack.imgur.com/3mG2d.jpg" alt="" style="height: 50px; width: 50px;"><p style="text-transform: uppercase;"><b>Birthday</b></p>
</div>
<div class="col-sm-2">
<img src="https://i.stack.imgur.com/3mG2d.jpg" alt="" style="height: 50px; width: 50px;"><p style="text-transform: uppercase;"><b>Birthday</b></p>
</div>
</div>
</div>
</div>
Good day, I am trying to center two col-md-6 where the left side with the text is aligned in the center beside the image. here are my css:
.full_width {
width: 100% !important;
}
.align-row {
display:flex !important;
}
.align-row > *
{
align-self:end !important;
}
I tried to align it with align-row but the text goes to the bottom, any help would be appreciated.
<div class="full_width">
<div class="align-row row align-items-center">
<div class="col-md-6 text-align-center">
<span>
<h2 class="color-mwc-blue">SELF-CARE IS SELF-LOVE: 2019 WELLNESS GOALS</h2><br>
<h2 class="color-mwc-orange">REGISTER</h2><br>
<h2 class="color-mwc-blue">TO ENJOY A WELTH OF DEALS FOR WELLNESS</h2>
</span>
</div>
<div class="col-md-6">
<img src="img/_stock_replace_this_1.jpg" class="img-responsive">
</div>
</div>
</div>
PS, I am using bootstrap 4
Use align-self:center; to align center element
.align-row > *
{
align-self:center;
}
.full_width {
width: 100%;
}
h2{
font-size:16px;
}
.align-row {
display:flex;
}
.align-row > *
{
align-self:center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" >
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="full_width">
<div class="align-row row align-items-center">
<div class="col-md-6 text-align-center">
<span>
<h2 class="color-mwc-blue">SELF-CARE IS SELF-LOVE: 2019 WELLNESS GOALS</h2><br>
<h2 class="color-mwc-orange">REGISTER</h2><br>
<h2 class="color-mwc-blue">TO ENJOY A WELTH OF DEALS FOR WELLNESS</h2>
</span>
</div>
<div class="col-md-6">
<img src="https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" class="img-responsive">
</div>
</div>
</div>
Just use d-flex and align-self-center boostrap default class to align the content equally center.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-6 d-flex">
<div class="align-self-center">
<h2 class="color-mwc-blue">SELF-CARE IS SELF-LOVE: 2019 WELLNESS GOALS</h2>
<br>
<h2 class="color-mwc-orange">REGISTER</h2>
<br>
<h2 class="color-mwc-blue">TO ENJOY A WELTH OF DEALS FOR WELLNESS</h2>
</div>
</div>
<div class="col-md-6 col-sm-6">
<img src="https://i.imgur.com/9Q9pgmR.jpg" class="img-fluid">
</div>
</div>
</div>