Seems super simple but I am unable to horizontally center text in a parent element while using display:inline-block on the text. I need it to be display:inline-block because I want the border around the text I create to be the size of the text and NOT the parent.
Is there another way to make the border I give the text the width of the text and not the parent?
a.studio-nav {
font-family: 'brandon-reg';
font-weight: 900;
color: white;
font-size: 20px;
display: inline-block;
text-align: center;
margin:0 auto;
padding:7px 4px;
}
a.studio-nav:hover {
border:2px solid white;
-webkit-border-radius: 7px;
-moz-border-radius: 7px;
border-radius: 7px;
text-decoration: none;
}
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row clearfix">
<div class="col-xs-4 col-md-4">
<a href="/" class="studio-nav">
text
</a>
</div>
<div class="col-xs-4 col-md-4">
<a href="/" class="studio-nav">
I want
</a>
</div>
<div class="col-xs-4 col-md-4">
<a href="/" class="studio-nav">
centered
</a>
</div>
</div>
Could it be as simple as this?
.row {
text-align: center;
}
Example fiddle: https://jsfiddle.net/rczfnf6d/
Bootstrap has also a quick way of achieving this with an alignment class called ".text-center"
<div class="col-xs-4 col-md-4 text-center"> <!-- class added-->
<a href="/" class="studio-nav">
text
</a>
</div>
Try
display: inline-table;
instead of
display: inline-block;
Related
I have to differentiate value 1 and value 2 using dot icon so I wrote css for that and placed in div but it is overlapping on each other I just want to show two div side by side with icon and text without overlapping
.dot {
height: 12px;
width: 12px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
}
.user-values-color{
background-color: #1BBC9B;
float: left;
}
.default-values-color{
background-color: #2D3E50;
float: left;
}
<div class="user-values-color dot" ><span style="float:left;">Value 1</span></div>
<div class="default-values-color dot"><span style="float:left;"> value 2</span></div>
take the span out of the div put it side by side in a parent container like below:
.dot {
height: 12px;
width: 12px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
}
.user-values-color{
background-color: #1BBC9B;
float: left;
}
.default-values-color{
background-color: #2D3E50;
float: left;
}
.container {
display: inline-block;
}
<div class="container">
<div class="user-values-color dot" ></div>
<span style="float:left;">Value 1</span>
</div>
<div class="container">
<div class="default-values-color dot"></div>
<span style="float:left;"> value 2</span>
</div>
If you are really using bootstrap then you shall learn about Grid system, it 's the basic.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="container">
<div class="row justify-content-start">
<div class="col-2">
Value 1
</div>
<div class="col-2">
value 2
</div>
</div>
</div>
now you are just using inline css
I've an image and text in one div parent,
I need to move the image and text to center,
but to let text beside img, I need to use float: left
here's the example code:
.boxtitlestillneedHeader {
background-color:#ff00 ; margin-bottom:15px;
}
.boxtitlestillneed {
color:#000000; font-size:26px; margin-bottom:1px; font-weight: bold;
}
.smal{
font-size: 20px;
}
.larg{
font-size: 40px;
color: red;
}
.inn{
width: 50%;
margin: 0 auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="col-md-1 col-sm-1 col-xs-12"></div>
<div class="col-md-12 col-sm-12 col-xs-12 text-left boxtitlestillneedHeader" id="status">
<div class="col-md-12 col-sm-12 col-xs-12 boxtitlestillneed">
<img src="https://image.flaticon.com/icons/png/128/50/50268.png" class="img-responsive" style="float: left; margin-left: 25%;">
<span class="need smal inn">you still need</span><br>
<span class="curr larg site-font-bold">IDR</span>
<span id="resultMoney" class="larg site-font-bold">2,1</span><br>
<span id="lifep4c2" class="smal">foo foo foo foo foo foo foo foo foo</span>
</div>
</div>
<div class="col-md-1 col-sm-1 col-xs-12"></div>
</div>
there's a way to make image and text center without using margin-left: n%?
jsfiddle
You can center align text with text align center.
.smal{
font-size: 20px;
text-align:center;
}
This should center the image. Apply this to the container holding the image. hope it helps.
.boxtitlestillneedHeader {
display: flex;
justify-content: center;
align-items: center;
}
I am using bootstrap grid system.
I have 3 grids which aligned center:
<div id="jumbotron">
<div class="container">
<div class="row row-centered">
<div class="col-md-4 col-centered">
<p>
Logo
</p>
</div>
<div class="col-md-4 col-centered">
<h3>
Some text
<h3>
</div>
<div class="col-md-4 col-centered">
<ul class="list">
<li>
<img src="img_url"/>
<a class="phones" href="+1-380-555-5555">+13805555555</a>
</li>
<li>
<img src="img_url"/>
<a class="phones" href="+1-380-555-5555">+13805555555</a>
</li>
<li>
<img src="img_url"/>
<a class="phones" href="+1-380-555-5555">+13805555555</a>
</li>
</ul>
</div>
</div>
</div>
</div>
and CSS looks like:
.row-centered {
text-align: center;
}
.list {
text-decoration: none;
color: #f1f0e9;
font-size: 20px;
font-family: 'Trirong', serif;
list-style-type: none;
text-align-last: right;
}
In third grid I have which I want to be aligned right.
text-align: right helps, but when I switch to mobile mode bootstrap makes grids in a column and third grid become right aligned(two others centered).
So I need that third grid will come right aligned but inside parent grid which has center align. Is it possible?
Try add a pull-right class to those you want right
Remove text-align-last: right; property because it's not affect to the a tag inside li. Use .list:last-child a will select the last li tag and affect to its a tag.
.row-centered {
text-align: center;
}
.list {
text-decoration: none;
color: #f1f0e9;
font-size: 20px;
font-family: 'Trirong', serif;
list-style-type: none;
/*text-align-last: right;*/
}
.list li:last-child a{
text-align: right;
}
Answer:
I have separated columns on two <ul class = "list"> objects and add
display: inline-block;
*display: inline;
properties to list class.
I have found the following solution for aligning an img vertically within a div
https://stackoverflow.com/a/7310398/626442
and this works great for a basic example. However, I have had to extend this and I want a row with two bootstrap col-md-6 columns in it. In the first column I want a 256px image, in the second I want a h1, p and a button. I have to following HTML:
<div class="home-costing container">
<div class="row">
<div class="frame">
<span class="helper"></span>
<div class="col-md-6">
<img src="http://www.nijmegenindialoog.nl/wp-content/uploads/in.ico" height="256" width="256" />
</div>
<div class="col-md-6">
<h2>Header</h2>
<p>
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA<br /><br/>
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
</p>
<a class="btn btn-default"
href='#Url.Action("Index", "Products")'
role="button">
Learn More
</a>
</div>
</div>
</div>
</div>
and the following CSS:
.home-costing {
color: #fff;
text-align: center;
padding: 50px 0;
border-bottom: 1px solid #ff6500;
}
.home-costing h2 {
text-transform: uppercase;
font-size: 60px;
}
.home-costing p {
font-size: 18px;
}
.home-costing .frame {
height: 256px;
width: 256px;
border: 0;
white-space: nowrap;
text-align: center;
margin: 1em 0;
}
.home-costing .helper {
display: inline-block;
height: 100%;
vertical-align: middle;
}
.home-costing img {
vertical-align: middle;
max-height: 256px;
max-width: 256px;
}
The problem is that now the second column is no longer contained and the text does not wrap and goes off to the right.
How can I center align my image in the first column with the text in the right column and still get the correct wrapping in the second column?
Fiddler: https://jsfiddle.net/Camuvingian/1sc40rm2/2/
Your HTML needed updated, in Bootstrap, the div order should ALWAYS go .container > .row > .col- * - *, your code however went .container > .row > .frame > .col- * - *. I have corrected your HTML and now your code works.
HTML:
<div class="home-costing container">
<div class="row">
<div class="col-md-6">
<img src="http://www.nijmegenindialoog.nl/wp-content/uploads/in.ico" height="256" width="256" class="center-block" />
</div>
<div class="col-md-6">
<h2>UserCost</h2>
<p>Hello, I'm a paragraph</p>
<a class="btn btn-default"
href='#Url.Action("Index", "Products")'
role="button">
Learn More
</a>
</div>
</div>
</div>
</div>
Link to finished code example:
Codepen - Updated & working code
This fixes the word wrap issue also on the p tag.
CSS:
p {
font-size: 18px;
word-wrap: break-word;
}
I am trying to get text to vertically align to the middle but can't seem to get it to work.
HTML:
<div class="row">
<div class="col-md-4">
Login
</div>
<div class="col-md-4">
Menu
</div>
<div class="col-md-4">
Contact
</div>
</div>
CSS:
.custom-button {
color:#ECDBFF;
background-color:#4F0100;
display:inline-block;
height: 220px;
font-family:Verdana, Geneva, sans-serif;
font-size:20px;
font-weight:bold;
text-align:center;
text-decoration:none;
}
.width-100 {width: 100%;}
I have googled quite a bit and tried a couple of things but i can't seem to get the text to go to the middle. can anyone advise what i would need to add/change to get this to work.
If your have a text which is restricted to single line then line-height would be the best solution.
try with this
line-height:220px; /*height of your container */
JsFiddle Demo
You can as well use vertical-align a pseudo element (:before or :after ) and an extra box (inline-block) to allow content to wrap on a few lines : see and run snippet below.
.custom-button {
color: #ECDBFF;
background-color: #4F0100;
display: inline-block;
height: 220px;
font-family: Verdana, Geneva, sans-serif;
font-size: 20px;
font-weight: bold;
text-align: center;
text-decoration: none;
}
.width-100 {
width: 100%;
}
.custom-button:before {
display:inline-block;
content:'';
height:220px;
vertical-align:middle;
margin:-0 -0.25em;;
}
a span {display:inline-block;
vertical-align:middle;
}
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"/>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css"/>
<div class="row">
<div class="col-md-4 col-xs-4">
Login
</div>
<div class="col-md-4 col-xs-4">
Menu
</div>
<div class="col-md-4 col-xs-4">
<span>Cont<br/>act</span>
</div>
</div>