Center elements in a div - html

I'm making a website for a design class and I'm having a hard time placing things like I would want them to be.
I would like all box on the same row to be the same height, but I don't want a fixed height because the website will be responsive in the future. I would also like it if I could vertically center the content of the boxes.
Here is a screenshot of what it should look like:
And this is what it actually look like:
I tried many things but I can't think of a nice way to do that.
Here is a link to my current code: http://cgagnier.ca/gived/design/
Thank you very much

For equal heights columns you can also take a look here (use of pseudo elements):
http://nicolasgallagher.com/multiple-backgrounds-and-borders-with-css2/
Or another way is to explore the display:table rule, so you could define boxes as table-cells. This would then probably address also the vertical align problem (just using the vertical-align property on table-cell elements).
--
For the vertical aligning itself, I sometimes take advantage of the inline-block vertical-align property.
So, define every inner block as inline-block and with vertical-align:middle (so they align with each other). Then use a pseudo ghost element with height:100% to align the others with it.
I've also got a sass mixin for that:
//to be placed on a pseudo :after/before
#mixin vertical_pivot{
content:"";
width: 1px;
height: 100%;
display:inline-block;
vertical-align: middle;
}
this last technique is also explained here (see the ghost element part by Michał Czernow):
http://css-tricks.com/centering-in-the-unknown/

This will solve your issue:
#premium figure {min-height: 203px;}
It is mobile responsive.
Another solution will be to use a <table> layout, but in my opinion, stick to the solution above.

You just need to specify a max-height for those images like so
#premium figure img {
max-width: 45%;
display: inline-block;
max-height: 149px;
min-height: 149px;
}

Put an div arround those div's give it a class, like container, and give it a min-height and max-height.
div:
<div class='container'>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
</div>
css:
.container{
min-height: 200px;
max-height: 200px;
}

Wrap your two figures in flex box div
<div style="
display: flex;
"><figure class="grille_6">
<img alt="DLC" src="img/p_dlc.png">
<figcaption>
<h1>Tous les DLC gratuits</h1>
<p>Obtenez gratuitement tous les DLC de Bugfield. Vous pourrez profiter de tous ces nouveaux bug une semaine en avance!</p>
</figcaption>
</figure>
<figure class="grille_6">
<img alt="Mallette" src="img/p_mallette.png">
<figcaption>
<h1>Participation au banquier™</h1>
<p>Lorsque vous achetez le Premium™, vous êtes automatiquement inscrit pour faire partie des spectateur du Banquier™</p>
</figcaption>
</figure>
</div>
<div style="
display: flex;
">
<figure class="grille_6">
<img alt="Couteau" src="img/p_couteau.png">
<figcaption>
<h1>Nouvelles armes exclusives</h1>
<p>Obtenez des nouvelles armes exclusives tel que le couteau bipod qui comprend une lampe tactique et une mire optique x10</p>
</figcaption>
</figure>
<figure class="grille_6">
<img alt="Priorité réduite" src="img/p_serveur.png">
<figcaption>
<h1>Priorité en file réduite</h1>
<p>Lorsque vous rejoindrez un serveur, vous serez placé dans une file spéciale à priorité réduite. Tous les autres joueurs passeront avant vous.</p>
</figcaption>
</figure>
</div>

You can also create a container and use the 2 columns as table cells. This is a really primitive demonstration, but I hope you've got the point. Fiddle
CSS:
#container {
display: table;
}
#content {
display: table-cell;
vertical-align: top;
background: #000;
color: #fff;
padding: 0 10px;
}
#sidebar {
display: table-cell;
vertical-align: top;
background: #cecece;
padding-right: 10px;
}
HTML
<div id="container">
<div id="sidebar">
<p>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br></p>
</div>
<div id="content">
<p>Main content</p>
</div>
</div>

Related

Trying to align image on the right of text using HTML & CSS

I am trying to align my image next to the text using HTML, so far I have tried adding float:right but it just seems to push the div down. I have also tried adding overflow:hidden but it does not seem to work.
I am using media queries to make this website responsive, and this is where I am having issues with moving the image to the right of the text,
I hope you can help.
<section id="section_about" class="grid">
<h2 class="content-title">
Our Story
</h2>
<div class="content-wrap about_content">
<p>
The History of Kitchens and Cooks gives further intimation on Mr Boulanger usual menu, stating
confidently that "Boulanger served salted poultry and fresh eggs, all presented without a tablecloth
on small marble tables". Numerous commentators have also referred to the supposed restaurant owner's
eccentric habit of touting for custom outside his establishment, dressed in aristocratic fashion and
brandishing a sword
<br><br>
Numerous commentators have also referred to the supposed restaurant owner's eccentric habit of
touting for custom outside his establishment, dressed in aristocratic fashion and brandishing a
sword
</p>
</div>
<div class="about_img_container">
<img src="./img/about_img.jpg" class="about_img">
</div>
</section>
CSS:
.content-title {
font-family: 'Playball', sans-serif;
color: #C59D5F;
font-size: 2.5em;
padding: 5px 0;
margin-top: 10px;
}
.content-wrap p {
padding-left: 20px;
line-height: 30px;
}
.about_img{
padding: 0 10px;
}
#media(min-width: 1024px) {
.about_content {
width: 50%;
background: pink;
}
.about_img_container{
background: red;
margin: 150px;
float: right;
overflow: hidden;
}
}
A more modern way of doing this would be with flexbox:
HTML
<div class="flex-container">
<div class="content-wrap about_content">
<p>
Your Text here
</p>
</div>
<div class="about_img_container">
<p>sodfosdf</p>
</div>
</div>
CSS
.flex-container {
display: flex;
justify-content: space-around;
}
The justify-content property defines how the two elements are displayed next to each other or under each other.
First you will need to remove h2 from the section:
<h2 class="content-title">
Our Story
</h2>
<section id="section_about" class="grid">
<div class="content-wrap about_content">
<p>
The History of Kitchens and Cooks gives further intimation on Mr Boulanger usual menu, stating
confidently that "Boulanger served salted poultry and fresh eggs, all presented without a tablecloth
on small marble tables". Numerous commentators have also referred to the supposed restaurant owner's
eccentric habit of touting for custom outside his establishment, dressed in aristocratic fashion and
brandishing a sword
<br><br>
Numerous commentators have also referred to the supposed restaurant owner's eccentric habit of
touting for custom outside his establishment, dressed in aristocratic fashion and brandishing a
sword
</p>
</div>
<div class="about_img_container">
<img src="./img/about_img.jpg" class="about_img">
</div>
</section>
Then give the section a display: flex.
#section_about {
display: flex;
flex-direction: row;
}
Just restrict the size of the image container by applying an appropriate width to it in your CSS rule, and move it above the DIV that contains the text so the text can float next to and under the image.
HTML
<div class="container">
<div class="content-wrap about_content">
<p>
Pls text here
</p>
</div>
<div class="about">
<p>Pls text here</p>
</div>
</div>
CSS
.container {
display: flex;
justify-content: space-around;
}

Center vertically an element

I just get stucked of how to center vertically an element.
<div class="wpb_wrapper">
<article class="callout"><a class="callurl" href="#">NOS SUCCESS STORIES</a>
<h3>Développement IT</h3><p></p>
<p>La transformation digitale, c’est avant tout un nouveau rapport d’opportunités d’innovations immense, dynamisé par :</p>
<p>- L’adhésion accélérée du grand public à de nouveaux usages.</p>
<p>- La collecte et le traitement de données toujours plus nombreuses.</p>
<p>- Le partage de la connaissance et l'Open Innovation IT.</p>
<p></p></article>
</div>
The code is in: http://jsfiddle.net/lzyphil/2bq7zqvf/
In fact,this part of code is generated by a wordpress plugin Webnus Callout,and I'm trying to modify the css in the hope that 'NOS SUCESS STORIES' sits vertically in the middle of <article>
Anyone get some ideas? Solution would be appreciated! Thanks
You can place the callout button absolutely positioned with respect to the relative parent container. It overlaps when mobile size browser breakpoint is reached. But you can modify it using media query with the desired position.
Output:
.callout a.callurl {
position: absolute;
right: 5%;
top: 40%;
}
JSfiddle

Put two different texts in the same place of an HTML page

I would like to put a text written in French on an HTML page and his hidden translation in English at the same place. A click on a JavaScript button will show the English text instead of the French one, by changing the Visibility attribut of each markup containing the text.
Maybe it's not the best way to do this sort of thing but I have to do it like this.
I've tried the following HTML and CSS code :
.presentationField {
vertical-align: text-top;
margin-left: auto;
margin-right: auto;
width: 500px;
border: 2px dashed blue;
}
<div id="frenchField" class="presentationField">
<h1>Les villes du Québec</h1>
<form>
Veuillez saisir le nom d'une ville au Québec<br>
<input type="text" id="recherche">
</form>
</div>
<div id="englishField" class="presentationField">
<h1>Cities of Québec</h1>
<form>
Please type the name of a town located in the province of Québec<br>
<input type="text" id="recherche">
</form>
</div>
But it doesn't work : the English text is below the French one and I can't figure out why.
If the text should be in the same exact location, use the CSS position property to overlap them. You may also have to make use of the z-index property depending on your desired result.
Example:
p{ color:red; font-size:200%; }
#alt{ color:blue; position:relative; top:-70px; }
<p>Regular Word</p>
<p id ="alt">French Word</p>
Or you could use display:none instead of visibility:hidden which removes the element from the layout rendering as well.
You can do something like this, just flip the visibility:
function change() {
document.getElementById('frenchField').style.display = 'none';
document.getElementById('englishField').style.display = 'block';
}
.presentationField {
vertical-align: text-top;
margin-left: auto;
margin-right: auto;
width: 500px;
border: 2px dashed blue;
}
#englishField {display: none;}
button {margin: auto; width: 200px; display: block}
<div id="frenchField" class="presentationField">
<h1>Les villes du Québec</h1>
<form>
Veuillez saisir le nom d'une ville au Québec
<br>
<input type="text" id="recherche">
</form>
</div>
<div id="englishField" class="presentationField">
<h1>Cities of Québec</h1>
<form>
Please type the name of a town located in the province of Québec
<br>
<input type="text" id="recherche">
</form>
</div>
<button onclick="change()"> FR -> EN </button>
You can also check which one is active first if you wish to be able to go back to French.
You should not put the translation as Hidden behind any other element. You should grab it from somewhere and just set the innerHTMLValue value.
function Translate(Language)
{
if(Language=='English')
{
document.getElementById("myBox").innerHTML = "Hi";
}
else
{
document.getElementById("myBox").innerHTML = "Hola";
}
}
Then you can simply pass the language. You should construct the Language Library as a Javascript object since that would be really the best way based on object oriented design and future requests may come that requires this solution.

How to align several text and images in CSS

Have a look at this screenshot for my problem:
This is the html code:
<div class="parent_process">
<div class="first_process"><img src="images/exprimer-besoin-telephonie.png"/><span style="width:18%">Vous remplissez le formulaire pour exprimer votre besoin (env 1 min)</span></div>
<div class="second_process"><img src="images/contacter-tous-les-vendeurs-autocommutateurs.png"/><span style="width:18%">Vous remplissez le formulaire pour exprimer votre besoin (env 1 min)</span></div>
<div class="third_process"><img src="images/recevoir-offre-standard-telephonique-pas-cher.png"/><span style="width:18%">Vous remplissez le formulaire pour exprimer votre besoin (env 1 min)</span></div>
</div>
This is css code:
.parent_process{ width:100%; white-space:nowrap; }
.parent_process div{ display:inline-block; width:33.3%;}
.first_process{ text-align:left; }
.second_process{ text-align:center; }
.third_process{ text-align:right; }
How can I have my 3 columns:
1)my text 1 | 2) my text 2 | 3) my text 3
Someone can help please?
Regards
Your three containers are the correct width, but the whitespace: nowrap style prevents the text from wrapping. So with overflow showing it just spills over.
If you remove whitespace: nowrap, your text will stay within the width of the container. However, you will notice a new problem. The columns do not fit on a single row:
http://jsfiddle.net/q1g0uxx4/2/
This is because the columns will have almost no space in between - not even space for a single character. With inline block, that causes them to wrap
You can remove all the whitespace between your divs, and they will fit:
http://jsfiddle.net/q1g0uxx4/1/
This isn't great for formatting though. Another way is to set the font-size of your container to 0.1px. Then it will fit even with formatted markup:
http://jsfiddle.net/q1g0uxx4/3/
I suggest using bootstrap as your css framework. They have a nice column system in place.
JSFiddle
The css is as simple as col-sm-4.
<div class='col-sm-4'>
<img src='http://ethanwiner.com/Smiley%20Land/Frenchie.gif' />some type of stuff that you can type some type of stuff that you can type</div>
<div class='col-sm-4'>
<img src='http://ethanwiner.com/Smiley%20Land/Frenchie.gif' />some type of stuff that you can type some type of stuff that you can type</div>
<div class='col-sm-4'>
<img src='http://ethanwiner.com/Smiley%20Land/Frenchie.gif' />some type of stuff that you can type some type of stuff that you can type</div>

element will not display at 100% height

On the following webpage http://rocoru.com/web/course.html on line 91 the following HTML
<li><strong>Description</strong></li>
doesn't display at 100% height with the following CSS applied to it:
li strong {
width: 35%;
float: left;
height: 100%;
display: block;
}
What are potential reasons why this element would not equal the height of the < li> tag with the CSS shown above applied to it?
The Problem is in
<div>Il y a des petites fees au creux de ma main et qui prennent le the dans un jardin. Il y a des petites fees au creux de ma main et qui prennent le the dans un jardin</div>
You Used to much text..
try changing it to
<div> test text </div> and see the difference :)
hope it helps