bootstrap 4 center items except first element [duplicate] - html

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>

Related

Move a specific part of text to next line if it have to

I am trying to view a Name and rating value and a star in a single line but I am thinking of if the name gets larger than the star and rating must move collectively to the next line but in my condition it first rating moves then star, is there any possible solution that if moving to next line then both star and rating value
like
Abdul* 4.5
if get more then
Abdul Wahab
*4.5
if bigger then
Abdul Wahab
amir *4.5
<p className="Bold mb-0 FS_16 Black" style={{fontSize: "100%"}}> Any name
<span>
<img src={Star} alt="" className="mb-2 p-1" />
<span className="Bold FS_16" style={{ color: "yellow" }}>{props.Rating}</span>
</span>
</p>
if moving to next line then both star and rating value
Looks like you just need your rating to be solid block, so, you can force it to be solid with
<p className="Bold mb-0 FS_16 Black" style={{fontSize: "100%"}}> Any name
<span className="rating">
<img src={Star} alt="" className="mb-2 p-1" />
<span className="Bold FS_16" style={{ color: "yellow" }}>{props.Rating}</span>
</span>
</p>
.rating {
display: inline-block
}
Or you can use display: inline-flex or whatever is better for your current layout and styling. You can also post your CSS, it will be easier to help you
A p element is a block element, it covers the whole width of its container and adds an inline box to its body where it can place inline elements. span and img elements are inline elements. Inline elements are subject to line-wrapping and you can place inline elements inside each other.
Solution: wrap the parts of the content where you DO NOT want line-breaking inside a span and set its css property white-space to nobreak. This content will then never line-break but this entire wrapping span, seen as an compund inline element in its surrounding may still break relative to other content in the surrounding box.
Check my primitive but meaningful samples and verify that the star and rating never separates with a line-break.
.container { text-align: center; background-color: lightgreen; border: 1px solid black; }
.w25 { width: 25px; }
.w50 { width: 50px; }
.w100 { width: 100px; }
.w150 { width: 150px; }
.w200 { width: 200px; }
.nobreak { white-space: nowrap }
<html>
<body>
<div class="container w25">
<p>
<span>This is a name</span>
<span class="nobreak">
<span>&star;</span>
<span>4.5</span>
</span>
</p>
</div>
<div class="container w50">
<p>
<span>This is a name</span>
<span class="nobreak">
<span>&star;</span>
<span>4.5</span>
</span>
</p>
</div>
<div class="container w100">
<p>
<span>This is a name</span>
<span class="nobreak">
<span>&star;</span>
<span>4.5</span>
</span>
</p>
</div>
<div class="container w150">
<p>
<span>This is a name</span>
<span class="nobreak">
<span>&star;</span>
<span>4.5</span>
</span>
</p>
</div>
<div class="container w200">
<p>
<span>This is a name</span>
<span class="nobreak">
<span>&star;</span>
<span>4.5</span>
</span>
</p>
</div>
</body>
</html>

How do I center text with CSS so that one of the elements is always at the center of parent element?

I have an element in which I want to show two team names like so: Team1 vs. Team2. However, when the name of one team is considerably longer than the other one, the vs. gets off-centered.
How can I achieve the "vs." part always staying dead-center and having the two elements go right next to it on either sides? All elements are text.
Example:
--------Team1-vs.-Team2--------
Team1Longname-vs.-Team2--------
--------Team1-vs.-Team2Longname
You can use flexbox and assign both of the team names flex: 1. Then give the team name on the left text-align: right
.wrapper {
display: flex;
}
.wrapper .team {
flex: 1;
}
.wrapper .vs {
margin: 0 10px;
}
.wrapper .team:first-child {
text-align: right;
}
<div class="wrapper">
<span class="team">Team 1</span>
<span class="vs">vs.</span>
<span class="team">Team 2</span>
</div>
<div class="wrapper">
<span class="team">Team 1</span>
<span class="vs">vs.</span>
<span class="team">Team 2 with A Long Name</span>
</div>
<div class="wrapper">
<span class="team">Team 1 with A Long Name</span>
<span class="vs">vs.</span>
<span class="team">Team 2</span>
</div>

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

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>

How to align the content of two divs vertically?

I'm trying to align two divs horizontally inside my HTML: the first one contains an image and the second a text, and this is the used code:
<div style="float: left; width: 55px;">
<img src="../img/look.svg" alt="">
</div>
<div style="display: inline-block;">
<span> Look for cases </span>
<span> from people near you. </span>
</div>
I tried many methods, but I've been unable to get the text line in the same level as the image vertical axis, and the text inside the second div gets displayed very far from the image vertically.
So, is there any possibility to fix that?
The problem is with the float. The vertical-align: middle; line-height: 1; will fix the issue:
div {
display: inline-block;
vertical-align: top;
line-height: 1;
}
div:first-child {
width: 55px;
}
<div>
<img src="//placehold.it/50?text=DP" alt="">
</div>
<div style="display: inline-block; vertical-align: middle; line-height: 1;">
<span> Look for cases </span>
<span> from people near you. </span>
</div>
Preview
Top Alignment:
Middle Alignment:
The vertical-align decides the vertical alignment. If you want the image and text to be on the same line, use vertical-align: top.
A few things first:
don't use inline styles
don't mix float with inline-block
Option 1: using flebox
section {
display: flex;
gap: 10px;
}
<section>
<div>
<img src="//dummyimage.com/55x55" alt="">
</div>
<div>
<span> Look for cases </span>
<span> from people near you. </span>
</div>
</section>
Option #2 using inline-block
div {
display:inline-block;
vertical-align:top;
margin-right:10px
}
<div>
<img src="//dummyimage.com/55x55" alt="">
</div>
<div>
<span> Look for cases </span>
<span> from people near you. </span>
</div>
Option #3 using float
div {
float: left;
margin-right:10px
}
<div>
<img src="//dummyimage.com/55x55" alt="">
</div>
<div>
<span> Look for cases </span>
<span> from people near you. </span>
</div>
flexbox to the rescue.
I added your divs inside another one, which will align its items. In my CSS my image has 100px so I changed the width to 100px. Change yours accordingly.
.halign {
display:flex;
align-items: center;
}
<div class="halign">
<div style="width: 100px;">
<img src="http://lorempixel.com/100/100/" alt="">
</div>
<div>
<span> Look for cases </span>
<span> from people near you. </span>
</div>
</div>
Try to seprate the CSS and HTML and do not mix display:inline-block with float:left. Also use clear:both after both div
<style>
.fisrstDiv {
float: left;
display:block;
}
.secondDiv {
float: left;
display:block;
}
.clear {
clear: both;
}
</style>
HTML
<div class="fisrstDiv">
<img src="//placehold.it/50?text=DP" alt="">
</div>
<div class="secondDiv">
<span> Look for cases </span>
<span> from people near you. </span>
</div>
<div class="clear"></div>

Vertical text floating in bootstrap div

I created piece of code. In span class mean-head increase horizontally if the text of the span increase. I want to fix it's width for like 30 characters. After that text so go to new line.
EXAMPLE FIEDLE
<span class="top-head"> Recommended URLs </span>
<div class="c1">
<div class="item">
<div class="image">
<img class="media-object" src="http://deathandtaxesmag.wpengine.netdna-cdn.com/wp-content/uploads/2014/02/Screen-Shot-2014-02-27-at-12.39.17-PM.png" >
</div>
<div class="descriptionContainer">
<span class="main-head"> Mashable - Business </span>
<span class="min-head">Title of link Title of link Title of link Title of link </span>
<span class="subcont">
<span class="fa fa-retweet"> RT 100+ | </span>
<span class="fa fa-twitter"> Tweet 100+</span>
</span>
</div>
</div>
</div>
Give fixed width for span class and add display block
.min-head { width:150px; display:block}
Will this help you?
span.min-head {
display: block;
font-size: 9px;
margin-top: 1px;
max-width: 130px;
white-space: pre-wrap;
}
Check the fiddle HERE