DIV center is not working [duplicate] - html

This question already has answers here:
How can I horizontally center an element?
(133 answers)
Closed 5 years ago.
I already tried fixing it with margin, table styles, and the bootstrap css but it isnt working
I need the A tags to center in the label-row-overview div and be responsive
HTML
<div class="label-row-overview">
<div class="label-img-overview"><span>EXTRA FOTO'S</span></div>
<div class="label-img-overview leftxspace"><span>MAATTABELLEN</span></div>
<div class="label-img-overview leftxspace"><span>PRODUCT SPECS</span></div>
<div class="label-img-overview leftxspace"><span>CERTIFICATEN</span></div>
</div>
Style.css
.label-row-overview a {
color: #FFF;
background-color: #12a19b;
padding: 10px;
display: inline-block;
margin: 5px;
overflow: hidden;
}

<div id="outer" style="width:100%">
<div id="inner">Foo foo</div>
</div>
You can apply this CSS to the inner :
#inner {
width: 50%;
margin: 0 auto;
}
Of course, you don't have to set the width to 50%. Any width less than the containing will work. The margin: 0 auto is what does the actual centering.
If you are targeting IE8+, it might be better to have this instead:
#inner {
display: table;
margin: 0 auto;
}
It will make the inner element center horizontally and it works without setting a specific width.
If you don't want to set a fixed width on the inner div you could do something like this:
#outer {
width: 100%;
text-align: center;
}
#inner {
display: inline-block;
}
<div id="outer">
<div id="inner">Foo foo</div>
</div>

Applying display: block and text-align: center to the div does the trick:
.label-row-overview a {
color: #FFF;
background-color: #12a19b;
padding: 10px;
display: inline-block;
margin: 5px;
overflow: hidden;
}
.label-row-overview {
display: block;
text-align: center;
}
<div class="label-row-overview">
<a href="{URL}" target="_blank">
<div class="label-img-overview"><span>EXTRA FOTO'S</span></div>
</a>
<a href="{URL}" target="_blank">
<div class="label-img-overview leftxspace"><span>MAATTABELLEN</span></div>
</a>
<a href="{URL}" target="_blank">
<div class="label-img-overview leftxspace"><span>PRODUCT SPECS</span></div>
</a>
<a href="{URL}" target="_blank">
<div class="label-img-overview leftxspace"><span>CERTIFICATEN</span></div>
</a>
</div>

Your a tags are naturally aligned with text since they are not block elements, so using text-align: center on their parent container solves the problem in this scenario.
.label-row-overview{
text-align: center;
}
.label-row-overview a {
color: #FFF;
background-color: #12a19b;
padding: 10px;
display: inline-block;
margin: 5px;
overflow: hidden;
}
<div class="label-row-overview">
<div class="label-img-overview"><span>EXTRA FOTO'S</span></div>
<div class="label-img-overview leftxspace"><span>MAATTABELLEN</span></div>
<div class="label-img-overview leftxspace"><span>PRODUCT SPECS</span></div>
<div class="label-img-overview leftxspace"><span>CERTIFICATEN</span></div>
</div>

Related

how to make div in bottom inside the main div? [duplicate]

This question already has answers here:
How can I position my div at the bottom of its container?
(25 answers)
Closed 3 years ago.
how to make div with class boxLinks = bottom in the main box = class = main-box?
my idea
this class main width 1200px;
this class main-box are 5 div, every div width 25%
.main-box {
width= "25%";
float= left;
}
<div class= "main">
<div class="main-box">
<div class="boxImg"></div>
<div class="boxTital"></div>
<div class="boxLinks">
<button> PRESS </button>
</div>
</div>
</div>
i want this div boxLinks in the last div,
You can use flexbox to do the work.
You have to set your main-box as flex.
then the boxLinks become a flex element, so with the properti align-self you can put it at the bottom.
You can fin a good tutorial on css-tricks
.main-box {
width: "25%";
float: left;
border: 1px solid #000;
width: 500px;
height: 400px;
display: flex;
}
.boxLinks {
flex: 0 1 100%;
height: 100px;
background: #000;
align-self: flex-end;/* this do the work */
}
<div class="main">
<div class="main-box">
<div class="boxImg"></div>
<div class="boxTital"></div>
<div class="boxLinks">
<button> PRESS </button>
</div>
</div>
</div>
Try this:
.main-box {
width= 25%;
float= left;
position:relative;
min-height:150px;
background:#000;
}
.boxLinks{
position:absolute;
bottom:0;
left:50%;
transform:translateX(-50%);
}
<div class= "main">
<div class="main-box">
<div class="boxImg"></div>
<div class="boxTital"></div>
<div class="boxLinks">
<button> PRESS </button>
</div>
</div>
</div>
It is pretty simple. You can use position: relative on 'main-box' and position: absolute, bottom:0 on 'boxLinks'.
Working example on jsFiddle.
.main {
display: flex;
}
.main-box {
width: 25%;
height: 100px;
float: left;
position: relative;
background-color: #f00;
}
.boxLinks {
position: absolute;
bottom: 0;
left: 0;
padding: 10px;
background-color: #0f0;
}
<div class="main">
<div class="main-box">
<div class="boxImg"></div>
<div class="boxTital"></div>
<div class="boxLinks">
<button> PRESS </button>
</div>
</div>
</div>

How to move elements around page [duplicate]

This question already has answers here:
Is it possible to center an inline-block element and if so, how?
(5 answers)
How can I horizontally center an element?
(133 answers)
Closed 3 years ago.
Currently, my webpage just consists of four images; two side-by-side. At the moment, they're all four off to the left side of the page and I would like to center them to the middle. I am currently using margin-top for its distance from the top of the page, so I am also using margin-left, right, etc. My elements stay in place when resizing my browser(which is what I wanted), but I can't move them to the center no matter how many times I change the left and right pixels.
body {
padding: 0px;
margin: 0px;
}
#dLand {
display: inline-block;
margin-top: 200px;
margin-left: auto;
margin-right: auto;
}
#sunset {
display: inline-block;
margin-top: 200px;
margin-left: auto;
margin-right: auto;
}
#griff {
display: inline-block;
margin-top: 5px;
margin-left: auto;
margin-right: auto;
}
#samo {
display: inline-block;
margin-top: 5px;
margin-left: auto;
margin-right: auto;
}
<div id='container'>
<img id='dLand' src='img/calidisney.jpeg' alt='Disneyland, CA' style='width: 40%'>
<img id='sunset' src='img/sunset.jpg' alt='Sunset Strip' style='width: 40%'>
<img id='griff' src='img/griffith.jpg' alt='Griffith Observatory' style='width: 40%'>
<img id='samo' src='img/samopier.jpg' alt='Santa Monica Pier' style='width: 40%'>
</div>
Try this one but if you want to display all images inline in mobile view use #media queries to archive that.
div#container {
margin-top: 200px;
width:100%;
text-align:center;
}
div.pic{
display:inline-block;
}
<div id="container">
<div class="pic"><img id='dLand' src='https://picsum.photos/id/237/200/300' alt='Disneyland, CA' ></div>
<div class="pic"><img id='sunset' src='https://picsum.photos/id/237/200/300' alt='Disneyland, CA' ></div>
<div class="pic"><img id='griff' src='https://picsum.photos/id/237/200/300' alt='Disneyland, CA' ></div>
<div class="pic"><img id='samo' src='https://picsum.photos/id/237/200/300' alt='Disneyland, CA' ></div>
</div>
see this in full-page.
There are different ways to center things, one technique is to set #container top and left to 50%, then transform: translate(-50%,-50%)
You may use flex to center and wrap them:
html {
min-height: 100%;
display: flex;
}
body {
/* or any wrapper within a flex or not parent*/
width: 80%;
margin: auto;
display: flex;
flex-wrap: wrap;
}
img {
width: 50%;
}
<img src="http://dummyimage.com/200x100/a0f">
<img src="http://dummyimage.com/200x100/bad">
<img src="http://dummyimage.com/200x100/def">
<img src="http://dummyimage.com/200x100/f00">

vertically center inline content [duplicate]

This question already has answers here:
How to vertical align an inline-block in a line of text?
(2 answers)
Closed 6 years ago.
I have text and image content/divs that are aligned. But I want them to be centred vertically with each other as well.
html
<div class="cell"><a href="...'</a></div>
<div class="separate"></div>
<div class="cell"><a href="...'</a></div>
<div class="separate"></div>
<div class="cell"><a href="...'</a></div>
css
.cell, .separate {
display: inline-block;
margin: 0 5px;
}
.separate {
width: 2px; height: 25px;
background-color: red;
}
To this rule, add vertical-align: middle;:
.cell, .separate {
display: inline-block;
margin: 0 5px;
vertical-align: middle;
}
One way to vertically align content is using line height. This method only works for one line of text though:
HTML
<div id="parent">
<div id="child">Text here</div>
</div>
CSS
#child {
line-height: 200px;
}
This can be extended for images too:
HTML
<div id="parent">
<img src="image.png" alt="" />
</div>
CSS
#parent {
line-height: 200px;
}
#parent img {
vertical-align: middle;
}
You can read about other methods to vertically center content here: http://vanseodesign.com/css/vertical-centering/
You can vertically align inline content with vertical-align
.cell, .separate {
display: inline-block;
margin: 0 5px;
vertical-align: middle;
}
.separate {
width: 2px; height: 25px;
background-color: red;
}
<div class="cell">asdf</div>
<div class="separate"></div>
<div class="cell">asdf</div>
<div class="separate"></div>
<div class="cell">asdf</div>

Align Img Vertically within Div HTML and CSS

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;
}

Responsive text fixed positioning with Button

http://i.imgur.com/Veauoig.png
I am currently trying to work out how to make the 'From £' text to keep in the same position as the buttons above. The page is responsive so I have been unable to keep the text in one position.
The CSS I have used so far -
element.style {position: absolute; width: 97%;}
I put each of the 'From £' parts in their own class. Not sure if there is an easier way?
<div class="price2">From £300</div>
Any help would be great. Thanks!
Add a container for the element for the price and button so that they remain in context with each other.
http://jsfiddle.net/05orkj1a/
.prices{
width: 100%;
}
.price-column{
display: table-cell;
width: 33%;
text-align: center;
margin: 0 auto;
padding: 0 5px;
}
<div class="prices">
<div class="price-column">
<button>Bass</button>
<div class="price2">From £65</div>
</div>
<div class="price-column">
<button>Mid</button>
<div class="price2">From £300</div>
</div>
<div class="price-column">
<button>Treble</button>
<div class="price2">From £715</div>
</div>
</div>
You could also Float the columns left to cause them to collapse vertically as the screen shrinks with the same html. Just change the margin or padding depending on how far apart you want them spaced
http://jsfiddle.net/z6agt11e/
.prices{
width: 100%;
overflow: hidden;
}
.price-column{
display: block;
float: left;
text-align: center;
padding: 5px 5px;
}
You can also add an outer container and then create a inner container for each button-price set.
Here is the HTML code:
<div class="outter">
<div class="block">
<div class="button">button1</div>
<div class="price2">From £65</div>
</div>
<div class="block">
<div class="button">button2</div>
<div class="price2">From £300</div>
</div>
<div class="block">
<div class="button">button3</div>
<div class="price2">From £715</div>
</div>
</div>
Here the CSS:
.outter{
width:100%;
}
.block{
width:33%;
background-color: yellow;
float:left;
text-align: center;
}
And here a jsfiddle:
http://jsfiddle.net/SoniaGM/ej4mdwx9/1/
Hope it helps.
You can use the CSS3 ::after pseudo-selector.
Give at button class:
position: relative;
Then you have to write something lime this:
.button-class::after {
content: 'From £300';
background: transparent;
height: 1%;
width: 3%;
position: absolute;
top: 20px;
left: 0px;
}
Obviously, you have to change height: 1%; width: 3%; and top: 20px; left: 0px;with whatever you want!