How can I get my content centered in this responsive div? - html

I have 4 columns in a row that become 1 column on mobile. The way this looks on mobile is fine, but I want to center the content in divs 2 and 4 in each row. What would be the best way to do this?
Apparently my edit was deleted or the site messed up, but I had said I want to do this vertical and horizontal. However, it was my fault I forgot to link to the page. Sorry, guys. - http://www.dismantledesign.com/testsite2/clients.html
Edit: I appreciate all the answers, but I don't think anyone understands that this div has no set height. I just want that text and icons to stay centered as the screen moves. The flex didn't seem to work because it required setting a height to the div.
I also simplified my HTML
Code
.clientsdetail {
text-align: center;
margin: 0px;
padding: 0px;
overflow-x: hidden;
}
.clientinfo h3 {
padding-top: 10px;;
}
.clientinfo p {
padding: 0px 30px;
font-size: 15px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-md-3 nopadding">
<img class="img-responsive" src="img/clients/ivey.jpg">
</div>
<div class="col-md-3 nopadding cinfo">
<div class="clientinfo text-center">
<h3>IVEY</h3>
<p>Clarksville, TN</p>
<div class="social-icons-clients">
<span class="icon-sprite sprite-ig"> </span>
<span class="icon-sprite sprite-fb"> </span>
<span class="icon-sprite sprite-gp"> </span>
<span class="icon-sprite sprite-sc"> </span>
<span class="icon-sprite sprite-tw"> </span>
</div>
</div>
</div>
<div class="col-md-3 nopadding cinfo">
<img class="img-responsive" src="img/clients/rufus.jpg">
</div>
<div class="col-md-3 nopadding">
<div class="clientinfo text-center">
<h3>RUFUS DAWKINS</h3>
<p>Clarksville, TN</p>
<div class="social-icons-clients">
<span class="icon-sprite sprite-ig"> </span>
<span class="icon-sprite sprite-fb"> </span>
<span class="icon-sprite sprite-gp"> </span>
<span class="icon-sprite sprite-sc"> </span>
<span class="icon-sprite sprite-tw"> </span>
</div>
</div>
</div>
</div>

You can use flex properties to make your content to center.
for more details, you can check
Flexbox: center horizontally and vertically

(UPDATED)
You can use the Pseudoclass to select the 2 and 4 div.
.row div:nth-child(2n) {
/* Your CSS Style */
}
If the content inside the 2 and 4 div are inline/inline-block, just use text-align: center;.
Demo
Here is the simple demo for the pseudoclass.
.row > div {
padding: 10px;
}
.row > div:nth-child(2n) {
color: #fff;
background: red;
text-align: center;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
}
<div class="row">
<div>One</div>
<div>Two</div>
<div>Three</div>
<div>Four</div>
</div>
Hope this is helpful for you.
Thanks.

Try a different approach. Bootstrap's floating grid system will not get you where you want.
First, remove row and col- classes so you have something like this:
<div class="my-row">
<div></div>
<div></div>
<div></div>
</div>
Then use CSS to achieve the same result as before, but with the content aligned center:
#media (min-width: 992px) {
.my-row {
display: flex;
align-items: stretch;
}
.my-row > div {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
}
}
If you are using SASS, then replace hardcoded 992px with the #screen-md-min variable.
Here's a JsFiddle of your simplified example:
https://jsfiddle.net/mpnz9b30/1/

<div class="col-md-6 nopadding cinfo">
<div class="clientinfo">
<h3>IVEY</h3>
<p>Clarksville, TN</p>
<div class="social-icons-clients">
<span class="icon-sprite sprite-ig"> </span>
<span class="icon-sprite sprite-fb"> </span>
<span class="icon-sprite sprite-gp"> </span>
<span class="icon-sprite sprite-sc"> </span>
<a href="https://twitter.com/contracoda" target="_blank">
<span class="icon-sprite sprite-tw"> </span>
</a>
</div>
</div>
</div>

Related

How to style horizontally and vertically?

<div class="flex-container">
<div class="flex-row">
<li class="org-li" v-for="o in orgs">
<div class="flex-item">
<button v-b-modal.link_printer #click="click_org(o.id)" class="org-btn">
<img class="org-img" :src="`http://localhost:8080/orgs/org_pictures/${o.img}`" alt=""/>
</button>
</div>
<li class="printer-li" v-for="p in printers[o.id]">
<div class="flex-item">
<button variant="outline-primary" class="printer-btn" v-bind:org_id="`${o.id}`" v-bind:printer_id="`${p.id}`" #click="onClick(o.id, p.id, p.serial_number)" >
<img class="printer-img" :src="`http://localhost:8080/printers/printer_pictures/${p.img}`" alt=""/>
</button>
</div>
</li>
</li>
</div>
</div>
I want the org-img to be 55px x 55px and I want the printer-img to be 25px x 25px. Each org-btn and printer-btn should be centered vertically on the screen.
I have been having difficulties with the printer-img being slightly offset from being vertically aligned.
you can do it that way. This adds the CSS styles to your component's block. The .org-img and .printer-img styles will define the width and height of the images, and the .flex-item style will center the buttons within the div elements that contain them. And the .flex-container will wrap the content inside on overflow.
You can make adjustments as needed to match your component's specific structure and class naming.
<template>
<div class="flex-container">
<div class="flex-row">
<li class="org-li" v-for="o in orgs">
<div class="flex-item">
<button v-b-modal.link_printer #click="click_org(o.id)" class="org-btn">
<img class="org-img" :src="`http://localhost:8080/orgs/org_pictures/${o.img}`" alt=""/>
</button>
</div>
<li class="printer-li" v-for="p in printers[o.id]">
<div class="flex-item">
<button variant="outline-primary" class="printer-btn" v-bind:org_id="`${o.id}`" v-bind:printer_id="`${p.id}`" #click="onClick(o.id, p.id, p.serial_number)" >
<img class="printer-img" :src="`http://localhost:8080/printers/printer_pictures/${p.img}`" alt=""/>
</button>
</div>
</li>
</li>
</div>
</div>
</template>
<style>
.org-img {
width: 55px;
height: 55px;
}
.printer-img {
width: 25px;
height: 25px;
}
.flex-item {
display: flex;
align-items: center;
justify-content: center;
}
.flex-container {
display: flex;
flex-wrap: wrap;
}
</style>

how to align multiple line text as the column of the table

I have to display text as follows(please notice that the month should be properly aligned with the months of other two rows, time should be properly aligned with the time of other two rows and so is the date as follows):
and all these values are coming from two way data binding inside a div in an angular 7 project as follows:
<div *ngFor="let date of dates">
{{date.month}} {{date.day}} {{date.time}}
<div>
please help me to display these values in the exact same style style.
Just make your Angular create the following HTML structure:
.table {
display: table;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
padding: 0 10px;
}
<div class="table">
<div class="row">
<span class="cell">December</span>
<span class="cell">15,2015</span>
<span class="cell">5 a.m.</span>
</div>
<div class="row">
<span class="cell">October</span>
<span class="cell">10, 2010</span>
<span class="cell">6 p.m.</span>
</div>
<div class="row">
<span class="cell">March</span>
<span class="cell">12, 2012</span>
<span class="cell">12 a.m.</span>
</div>
</div>
In your Angular, that would be
<div class="table">
<div class="row" *ngFor="let date of dates">
<span class="cell">{{date.month}}</span>
<span class="cell">{{date.day}}</span>
<span calls="cell">{{date.time}}</span>
<div>
</div>
you can simply do this:
<div *ngFor="let date of dates">
<span>{{date.month}}</span><span>{{date.day}}</span><span>{{date.time}}</span>
<div>
And give some style to these span (padding, margin)...
HTML:
<div [ngClass]="'container'" *ngFor="let date of dates">
<div>{{date.month}}</div>
<div>{{date.day}}</div>
<div>{{date.time}}</div>
</div>
CSS:
.container{
width:100%;
overflow:hidden;
}
.container > div{
width:33.333%;
float:left;
}
Stacklitz solution
Follow below stacklitz code for solution
css
.wrapper{
display: flex;
justify-content: space-between;
}
.colm{
min-width:100px;
}
component
<div class=" row wrapper" *ngFor="let date of dates">
<div class="colm">{{date.month}}</div>
<div class="colm">{{date.day}} </div>
<div class="colm">{{date.time}}</div>
<div>

bootstrap 4 center items except first element [duplicate]

This question already has answers here:
Flexbox horizontal menu centering while keeping last element to the right side [duplicate]
(1 answer)
How can I "pin" one node to left viewport edge, while keeping other node horizontally centered relative to viewport?
(3 answers)
Closed 5 years ago.
.c-footer {
background: #000;
padding: 20px 0;
color: #fff; }
.c-footer__logo {
display: inline; }
.c-footer__link {
color: inherit; }
.c-footer__link a {
color: inherit; }
.c-footer__link a:hover {
color: #fff; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="c-footer text-center">
<div class="c-footer__logo">
<img src="http://dynamicdog.se/wp-content/themes/dynamicdog/img/logo.png">
</div>
<span class="c-footer__link">
Malmö<span> - </span>
</span>
<span class="c-footer__link">
Stockholm<span> - </span>
</span>
<span class="c-footer__link">
Malmö<span> - </span>
</span>
<span class="c-footer__link">
Stockholm<span> - </span>
</span>
<span class="c-footer__link">
Malmö<span> - </span>
</span>
<span class="c-footer__link">
Stockholm
</span>
</div>
I want to accomplish the picture below:
Centering the text while having the image floated to the left. I tried with the bootstrap class center-text however it centers all elements...
Heres my markup:
<div class="c-footer">
<div class="c-footer__logo">
<img src="/static/media/q-logo.98ed5701.png">
</div>
<span class="c-footer__link">
Malmö<span> - </span>
</span>
<span class="c-footer__link">
Stockholm<span> - </span>
</span>
</div>
How would you accomplish this?
Using the flex properties, you can just have a div on each side. Since the logo is 100px in my example, I have it set as 100px. Remember to the have the img have a class of img-fluid.
I've also attached a codepen for you.
https://codepen.io/Gwapedwink/pen/yPmaVN?editors=1100#0
<footer>
<div class="container d-flex align-items-center">
<div class="footer-side">
<img src="http://placehold.it/400/fff/999&text=LOGO" class="img-fluid" />
</div>
<div class="mx-auto d-flex">
Link Label
Link Label
Link Label
Link Label
Link Label
</div>
<div class="footer-side">
<!-- nothing here, homie -->
</div>
</div>
</footer>
<style>
/* this is all that matters */
footer .footer-side {
width: 100px; /* whatever you want the logo width to be */
}
</style>
In my approach, I use text-align and float. text-align will align all inline items. this affects both the text and the image since both are inline. Since we want the image to stay on the left side, we can float the image.This should place the image along the left side of its container.
Those two combined makes the image stick to the left while rest of the content inside c-footer is aligned to the center regardless of device width! :)
.c-footer {
background-color: #000;
height: 80px;
text-align: center;
}
.c-footer__logo {
padding-left: 20px;
float: left;
}
.c-footer__logo img {
height: 80px; /* Just for the looks of the example */
}
.c-footer__link a{
line-height: 80px;
color: #fff;
}
.c-footer__link:after {
color: #fff;
content: '\00a0-\00a0'
}
.c-footer__link:last-child:after {
content: ''
}
<footer class="c-footer">
<div class="c-footer__logo">
<img src="https://i.gyazo.com/1e2e3e71c2e236cb827f8026d1aa813e.png">
</div>
<span class="c-footer__link">
Bergen
</span>
<span class="c-footer__link">
Oslo
</span>
<span class="c-footer__link">
Stavanger
</span>
<span class="c-footer__link">
Kristiansand
</span>
<span class="c-footer__link">
Trondheim
</span>
<span class="c-footer__link">
Drammen
</span>
</footer>

Vertical allign using bootstrap not working [duplicate]

This question already has answers here:
vertical-align with Bootstrap 3
(26 answers)
Bootstrap how to get text to vertical align in a div container
(3 answers)
Closed 5 years ago.
I'm using Bootstrap v3.2.0 and i have an html structure like this:
<div class="header-seller-profile col-md-12">
<div class="left-header-content col-md-5">
<div class="seller-banner">
<img src="http://bouquet.developers-server.com/pub/media/avatar/banner-image.png" alt="no image">
</div>
</div>
<div class="middle-header-content col-md-4">
<div class="seller-address">
<div class="wefrom">
<a class="cont-name" title="Search" href="http://bouquet.developers-server.com/marketplace/seller/location/shop/dasdasdad?loc=sadasdasd" target="_blank">
<span>sadasdasd</span>
<img class="piccountry" title="View Map" src="http://bouquet.developers-server.com/pub/static/version1504776489/frontend/Mgs/organie/en_US/Webkul_Marketplace/images/country/countryflags/ID.png">
</a>
</div>
</div>
</div>
<div class="right-header-content col-md-3">
<div class="seller-social-media">
<div class="wk-mp-profile-container storename wk-mp-display-block-css">
<a href="//facebook.com/sadasda" target="blank">
<span class="wk-social-icon wk-icon wk-social-icon-fb" title="Check in Facebook"></span>
</a>
<a href="//twitter.com/dasdsadas" target="blank">
<span class="wk-social-icon wk-icon wk-social-icon-tw" title="Check in Twitter"></span>
</a>
</div>
</div>
</div>
</div>
i tried to make the content inside header-seller-profile class align to bottom but it's not working at all, it keeps stick to the top.
here's my css code:
.header-seller-profile{
background-color: #333333;
color: #fff;
display: inline-block;
}
.middle-header-content,right-header-content,left-header-content{
vertical-align: bottom;
}
.seller-banner img{
width: 100%;
}
Are you looking for this ?
https://codepen.io/swapnaranjitanayak/pen/GvaLNJ
CSS:
.header-seller-profile{
background-color: #333333;
color: #fff;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
align-items: flex-end;
}
.header-seller-profile img{
vertical-align:bottom;
}
Replace your css
From :
vertical-align: bottom;
To
vertical-align: text-bottom;

CSS float right weird behaviour

I have 2 threads in an imageboard stacked on top of each other, each thread has some text and an image file.
I want images to be always on right of the thread, instead of being on top of reply button.
When I float image to right by float: right; the images keep stacking on top of each other instead and form a branch like structure
How do I force images with post-image class to not break <div> structure of following thread and stay on right of screen?
<div class="you" id="thread_27" data-board="b" align="Right">
<div class="files">
<div class="file">
<p class="fileinfo">File: 1454704253855.jpg <span class="unimportant">(78.69 KB, 1024x768, <span class="postfilename">soft-color-background.jpg</span>)</span>
</p>
<img class="post-image" src="/b/thumb/1454704253855.png" style="width: 255px; height: 192px; max-width: 98%;" alt="">
</div>
</div>
<div class="post op" id="op_27">
<p class="intro">
<input class="delete" name="delete_27" id="delete_27" type="checkbox">
<label for="delete_27"><span class="name">Anonymous (You)</span>
<time data-local="true" datetime="2016-02-05T20:30:54Z">02/05/16 (Fri) 22:30:54</time>
</label> <a class="post_no" id="post_no_27" onclick="highlightReply(27)" href="/b/res/27.html#27">No.</a><a class="post_no" onclick="citeReply(27)" href="/b/res/27.html#q27">27</a>[Reply]</p>
<div class="body">xxxxxx2</div>
</div>
<br class="clear">
<hr>
</div>
<div class="you" id="thread_26" data-board="b" align="Right">
<div class="files">
<div class="file">
<p class="fileinfo">File: 1454704190918.jpg <span class="unimportant">(157.33 KB, 1024x768, <span class="postfilename" title="mac-style-presentation-background.jpg">mac-style-presentation-bac….jpg</span>)</span>
</p>
<img class="post-image" src="/b/thumb/1454704190918.png" style="width: 255px; height: 192px; max-width: 98%;" alt="">
</div>
</div>
<div class="post op" id="op_26">
<p class="intro">
<input class="delete" name="delete_26" id="delete_26" type="checkbox">
<label for="delete_26"><span class="name">Anonymous (You)</span>
<time data-local="true" datetime="2016-02-05T20:29:51Z">02/05/16 (Fri) 22:29:51</time>
</label> <a class="post_no" id="post_no_26" onclick="highlightReply(26)" href="/b/res/26.html#26">No.</a><a class="post_no" onclick="citeReply(26)" href="/b/res/26.html#q26">26</a>[Reply]</p>
<div class="body">xxxxx</div>
</div>
<br class="clear">
<hr>
</div>
when I add CSS
.post-image
{
float: right;
}
it breaks everything.
jsfiddle before
js fiddle after floating post-image to the right
This happens because of float left or right. clear controls the float behavior hence, the ideal way is to make all the float properties inside a container usually div. Sometimes, browser renders it differently so whenever coming to a new container or sibling, ideal way is to clear the float(if you don't need the floating property).
In your code you could probably
Add this:
.clear{
clear:both;
}
to better understand. Also don't forget to play with it to put it ideally where it is required.
If you can use flexbox (no way to old browsers) try something like:
.row{
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
align-content: stretch;
align-items: flex-start;
}
.col1{
position: relative;
flex: 1 1 100%;
align-self: stretch;
overflow: hidden;
}
.col2{
position: relative;
display: flex;
flex-direction: column;
flex: 0 1 45px;
align-self: stretch;
}
on a html strukture like
<div class="row">
<div class="col1">
</div>
<div class="col2">
</div>
</div>
Add one more div with "clear: both" styling will fix your problem.
<div class="file">
your code here...
<div style="clear:both"></div>
</div>
jsfiddle