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>
Related
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'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>
I want to center a DIV within a DIV but not the text, all the solutions are saying to specify my width and set margins to auto, but how does that work if it's a responsive build as if I set the width it wont be? I want to align the contact-info DIVS but not the text. Hope that is clear enough.
Thanks!
<div id="upperfooter">
<div class="container">
<div id="links">
<div class="contact-info col-lg-offset-0 col-lg-3 col-xs-4 col-md-offset-0 col-md-4">
<div class="contact-item">
<h3><strong>COMPANY INFO</strong></h3>
<p>About Nielsen</p>
<p>Investor Relations</p>
<p>Nielsen Families</p>
<p>Responsibility & Sustainability</p>
<p>Press Room</p>
<p>Careers</p>
<p>Contact Us</p>
</div>
</div>
<div class="contact-info col-lg-offset-0 col-lg-3 col-xs-4 col-md-offset-0 col-md-4">
<div class="contact-item">
<h3><strong>INSIGHTS</strong></h3>
<p>Newswire</p>
<p>Reports</p>
<p>News Center</p>
<p>Top 10 & Trends</p>
<p>How We Measure</p>
<p>Webinars & Events</p>
<p>Newsletter Sign-up</p>
</div>
</div>
<div class="contact-info col-lg-offset-0 col-lg-3 col-xs-4 col-md-offset-0 col-md-4">
<div class="contact-item">
<h3><strong>SOLUTIONS</strong></h3>
<p>Advertising Effectiveness</p>
<p>Audience Measurement</p>
<p>Marketing ROI</p>
<p>Price and Promotion</p>
<p>Product Development</p>
<p>Reputation Management</p>
<p>Shopper</p>
</div>
</div>
</div>
</div>
</div>
You should add position: relative to main div and set the smaller width on a contact div, that worked for me.
Since the only elements I see not centered are those with contact-info, but only when screen size is large, an approach is to add some style to the wrapper. Also, you have to remenber that col-x divs should by wrapped by a div with row class on Bootstrap. So, we going to add style display:flex and justify-content:center to this wrapper. Check next example, where redundant classes where removed and borders where added so you have a reference on the visualization.
.contact-info {
border: 1px solid blue;
}
.contact-item {
border: 1px solid red;
}
.row {
border: 1px solid green;
display: flex;
justify-content: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/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" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div id="upperfooter">
<div class="container">
<div id="links" class="row">
<div class="contact-info col-lg-3 col-xs-4">
<div class="contact-item">
<h3><strong>COMPANY INFO</strong></h3>
<p>About Nielsen</p>
<p>Investor Relations</p>
<p>Nielsen Families</p>
<p>Responsibility & Sustainability</p>
<p>Press Room</p>
<p>Careers</p>
<p>Contact Us</p>
</div>
</div>
<div class="contact-info col-lg-3 col-xs-4">
<div class="contact-item">
<h3><strong>INSIGHTS</strong></h3>
<p>Newswire</p>
<p>Reports</p>
<p>News Center</p>
<p>Top 10 & Trends</p>
<p>How We Measure</p>
<p>Webinars & Events</p>
<p>Newsletter Sign-up</p>
</div>
</div>
<div class="contact-info col-lg-3 col-xs-4">
<div class="contact-item">
<h3><strong>SOLUTIONS</strong></h3>
<p>Advertising Effectiveness</p>
<p>Audience Measurement</p>
<p>Marketing ROI</p>
<p>Price and Promotion</p>
<p>Product Development</p>
<p>Reputation Management</p>
<p>Shopper</p>
</div>
</div>
</div>
</div>
</div>
I already tried different solutions posted here to get two columns with the same height, but unfortunately I can't get this to work. The Problem is, that I have three images, one on the left in "portrait mode" and two on the right in "landscape mode". I want both images together on the right to have the same height as the image on the left.
I think that this could be a solution, but I didn't get this to work: The two items on the right could each have a height of 50% of the div on the left. The images inside the item then should fill the height and have an auto width.
Like this:
Here is what my basic code looks so far: https://jsfiddle.net/qg7t976L/
.padding-0 {
padding: 0;
}
img {
width: 100%;
}
img {
border: 1px white solid;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" />
<div id="work" class="content">
<div class="container-fluid work-body">
<div class="row">
<div class="padding-0 col-sm-6">
<div class="work-inner">
<div class="work-item">
<img src="http://placehold.it/500x750" alt="work1">
</div>
<!--/.work-item-->
</div>
<!--/.work-inner-->
</div>
<div class="padding-0 col-sm-6">
<div class="padding-0 work-inner col-sm-12">
<div class="work-item">
<img src="https://placehold.it/450x250" alt="work2">
</div>
<!--/.work-item-->
</div>
<div class="padding-0 work-inner col-sm-12">
<div class="work-item">
<img src="https://placehold.it/500x250" alt="work3">
</div>
<!--/.work-item-->
</div>
</div>
</div>
</div>
<!--/.container-->
</div>
<!--/work-->
You can try with these code.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row row--equal">
<div class="col-md-6 no-padding">
<div class="item item--full-height">
<img src="https://i.stack.imgur.com/WS7U5.png" alt="">
</div>
</div>
<div class="col-md-6 item--half-height no-padding">
<div class="item ">
<img src="https://i.stack.imgur.com/cslWU.png" alt="">
</div>
<div class="item item--half-height">
<img src="https://i.stack.imgur.com/niAPD.png" alt="">
</div>
</div>
</div>
</div>
</body>
</html>
CSS:
.row--equal{
display: flex;
}
.no-padding{
padding-left: 0px !important;
padding-right: 0px !important;
}
.item{
margin-right: 1px;
margin-bottom: 1px;
}
.item img{
width: 100%;
height: 100%;
}
.item--full-height{
height: 100%;
}
.item--half-height{
height: 50%;
}