Trying to vertically center align text next to an image in a three across grid alignment. Have tried many things but either one of two things happens:
- text vertically center aligns for one row of text, but wraps under the image if there is more than one row of text
- text wraps properly for multiple rows of text, but won't vertically center align, as shown in the provided code
Any suggestions?
.tile-third {
font-size: 18px;
text-transform: uppercase;
float: left;
width: 25%;
margin-right: 1%;
margin-bottom: 1%;
}
.tile-image {
vertical-align:middle;
float:left;
margin-right: 1%;
background-color:#000;
}
.tile-text {
}
<div class="tile-third">
<a href="#">
<img class="tile-image" src="http://acmebeachandbike.com/wp-content/uploads/2016/05/icon-outside.png"/>
<div class="tile-text">Department Description One (DD1)</div>
</a>
</div>
<div class="tile-third">
<a href="#">
<img class="tile-image" src="http://acmebeachandbike.com/wp-content/uploads/2016/05/icon-lowimpact.png"/>
<span class="tile-text">Department Description Two</span>
</a>
</div>
<div class="tile-third">
<a href="#">
<img class="tile-image" src="http://acmebeachandbike.com/wp-content/uploads/2016/05/icon-fun.png"/>
<span class="tile-text">Department Description Three (DD3)</span>
</a>
</div>
the image and the text is inside in an anchor tag,
change the style of the anchor tag to achieve the required.
example,
.tile-third a {
height: 100%;
display: flex;
align-items: center;
}
Is this what you are looking for??
.tile-third {
display: inline-block;
font-size: 18px;
text-transform: uppercase;
width: 30%;
}
.tile-third > a {
align-items: center;
display: flex;
}
.tile-image {
background-color:#000;
margin-right: 2%;
}
.tile-text {
}
<div class="tile-third">
<a href="#">
<img class="tile-image" src="http://acmebeachandbike.com/wp-content/uploads/2016/05/icon-outside.png"/>
<div class="tile-text">Department Description One (DD1)</div>
</a>
</div>
<div class="tile-third">
<a href="#">
<img class="tile-image" src="http://acmebeachandbike.com/wp-content/uploads/2016/05/icon-lowimpact.png"/>
<span class="tile-text">Department Description Two</span>
</a>
</div>
<div class="tile-third">
<a href="#">
<img class="tile-image" src="http://acmebeachandbike.com/wp-content/uploads/2016/05/icon-fun.png"/>
<span class="tile-text">Department Description Three (DD3)</span>
</a>
</div>
I set the display value for the <a> tag under the <div class="tile-third"> to flex which is an easy way to get things to properly align.
This allows the <img> and <div> inside the <a> to properly align.
Related
I've been trying to work on a new section for my website, but I've been having a lot of trouble when trying to keep things aligned in the way I want them too
I've edited a screencap really quick to show what I'm trying to accomplish
And without text, the images line up just fine, but the moment I add text is when everything falls apart
Here's how it looks
How can I get the results I want?
Here's my CSS code
.downloadscontainer {
text-align: center;
}
.downloadbutton {
display: inline-block;
float: left;
}
.downloadbutton2 {
display: inline-block;
float: center;
}
.downloadbutton3 {
display: inline-block;
float: center;
}
And here's the HTML code for the section I'm having trouble with
<div class="downloadscontainer">
<a href="https://mega.nz/file/z6ZzGSAQ#NzUXO0iZ_4ftp9YKnYBptFq5PHG7IYke6QhZ5WskMjE" target="_blank">
<img src="../../downloads/fonts/images/TerminusFont.png" class="downloadbutton"></a>
<p>This is supposed to be an example</p>
<a href="https://mega.nz/file/C6ZlWZZb#5JGq04jfIP-xGz_xQ-EhpRHA7htTTcg9Pgrp_bqSqw0" target="_blank">
<img src="../../downloads/fonts/images/VisitorFont.png" class="downloadbutton2"></a>
<p>This is also an example</p>
<a href="https://mega.nz/file/CyQFzYKa#Hq7uDGnrni0ZteWg-8s_-8nbAkSJjA1gZIDVcP786Ns" target="_blank">
<img src="../../downloads/fonts/images/JBlackFont.png" class="downloadbutton3"></a>
<p>Another example LOL</p>
</div>
Make the .downloadscontainer a flex element (flex is awesome).
Then wrap each set of image+text in a div.
CSS:
.downloadscontainer {
display: flex;
text-align: center;
}
div.wrapper {
flex: 1;
}
HTML:
<div class="downloadscontainer">
<div class="wrapper">
<a href="https://mega.nz/file/z6ZzGSAQ#NzUXO0iZ_4ftp9YKnYBptFq5PHG7IYke6QhZ5WskMjE" target="_blank">
<img src="../../downloads/fonts/images/TerminusFont.png" class="downloadbutton"></a>
<p>This is supposed to be an example</p>
</div>
<div class="wrapper">
<a href="https://mega.nz/file/C6ZlWZZb#5JGq04jfIP-xGz_xQ-EhpRHA7htTTcg9Pgrp_bqSqw0" target="_blank">
<img src="../../downloads/fonts/images/VisitorFont.png" class="downloadbutton2"></a>
<p>This is also an example</p>
</div>
<div class="wrapper">
<a href="https://mega.nz/file/CyQFzYKa#Hq7uDGnrni0ZteWg-8s_-8nbAkSJjA1gZIDVcP786Ns" target="_blank">
<img src="../../downloads/fonts/images/JBlackFont.png" class="downloadbutton3"></a>
<p>Another example LOL</p>
</div>
</div>
You must use margin
.downloadscontainer {
margin: 0 auto;
}
Try this.
HTML:
<div class="downloadscontainer">
<div>
<a href="https://mega.nz/file/z6ZzGSAQ#NzUXO0iZ_4ftp9YKnYBptFq5PHG7IYke6QhZ5WskMjE" target="_blank">
<img src="../../downloads/fonts/images/TerminusFont.png" class="downloadbutton">
</a>
<p>This is supposed to be an example</p>
</div>
<div>
<a href="https://mega.nz/file/C6ZlWZZb#5JGq04jfIP-xGz_xQ-EhpRHA7htTTcg9Pgrp_bqSqw0" target="_blank">
<img src="../../downloads/fonts/images/VisitorFont.png" class="downloadbutton2">
</a>
<p>This is also an example</p>
</div>
<div>
<a href="https://mega.nz/file/CyQFzYKa#Hq7uDGnrni0ZteWg-8s_-8nbAkSJjA1gZIDVcP786Ns" target="_blank">
<img src="../../downloads/fonts/images/JBlackFont.png" class="downloadbutton3">
</a>
<p>Another example LOL</p>
</div>
</div>
CSS:
.downloadscontainer {
text-align: center;
display: inline-flex;
}
.downloadscontainer > div {
margin: auto;
}
Not being able to see your pictures from your code, makes it hard to help you out as I wanted.
But here's a little help:
CSS:
.downloadscontainer {
text-align: center;
display:flex;
}
.downloadbutton {
display: block;
float: left;
}
.downloadbutton2 {
display: block;
float: center;
}
.downloadbutton3 {
display: block;
float: center;
}
HTML
<div class="downloadscontainer">
<a href="https://mega.nz/file/z6ZzGSAQ#NzUXO0iZ_4ftp9YKnYBptFq5PHG7IYke6QhZ5WskMjE" target="_blank">
<img src="../../downloads/fonts/images/TerminusFont.png" class="downloadbutton"></a>
<p>This is supposed to be an example</p>
<a href="https://mega.nz/file/C6ZlWZZb#5JGq04jfIP-xGz_xQ-EhpRHA7htTTcg9Pgrp_bqSqw0" target="_blank">
<img src="../../downloads/fonts/images/VisitorFont.png" class="downloadbutton2"></a>
<p>This is also an example</p>
<a href="https://mega.nz/file/CyQFzYKa#Hq7uDGnrni0ZteWg-8s_-8nbAkSJjA1gZIDVcP786Ns" target="_blank">
<img src="../../downloads/fonts/images/JBlackFont.png" class="downloadbutton3"></a>
<p>Another example LOL</p>
</div>
This should keep the images horizontally and the text below the images.
But keep an eye on this website, if you want to wrap the text in an image and align the text different, I think float:none; or text-align:center; is what you want to achieve:
https://hostpapasupport.com/align-float-images-website/
W3schools has many tutorials and awesome gimmicks to help you out with this matter,
so many code-snippets that could help you out with that too.
https://www.w3schools.com/howto/default.asp
I hope I could help you with the sites and the code.
I need the default picture and text to go in a row, but when the screen resolution decreased, the text moved under the picture
<div style="background-color:#474747;">
<p><img src="{{ MEDIA_URL }}{{ article.img.url }}"/></p>
<a href="" style="margin-left:20px;">
<h3>{{article.title}}</h3>
<i class="glyphicon glyphicon-eye-open" style="font-size:20px; color:white;">
{{ article.view }} {{article.date|date:"d-m-Y"}}
</i>
</a>
</div>
I don't really know what its supposed to look like but you should fix your broken code then use CSS to tell all your block-level elements to be inline-block instead. Something like:
.allinline {
background-color: #474747;
}
.allinline * {
display: inline-block;
}
<div class="allinline">
<p><img src="imgurlhere" /></p>
<a href="" style="margin-left:20px;">
<h3>article.title</h3>
<i class="glyphicon glyphicon-eye-open" style="font-size:20px; color:white; ">article.date</i> </a>
</div>
Better yet, refactor your html into something a little more semantic and then use flexbox to achieve your desired layout. (Again, I'm guessing a bit at what you want it to look like)
.linkblock {
display: flex;
align-items: center;
background-color: #474747;
font-size: 20px;
}
.linkblock img {
margin-right: 20px;
}
.linkblock em {
color: white;
}
<a href="#" class="linkblock">
<img src="https://via.placeholder.com/100" />
<strong>article.title</strong> <em class="glyphicon glyphicon-eye-open">article.date</em>
</a>
To prevent children elements from breaking into diffrent lines, set white-space:nowrap on parent.
<div style="white-space:nowrap;background-color:#474747;">
<p><img src="{{ MEDIA_URL }}{{ article.img.url }}"/></p>
<a href="" style="margin-left:20px;">
<h3>{{article.title}}</h3>
<i class="glyphicon glyphicon-eye-open" style="font-size:20px; color:white;">
{{ article.view }} {{article.date|date:"d-m-Y"}}
</i>
</a>
</div>
Note: block elements always take 100% of width. You have also to update that paragraph and h1 to be inline-block
Try to use flex box while creating responsive Web designs.
Reference: - https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Summary: In the example below, i have a parent element with display flex,and i have defined two child elements. One child will have image and the other will have text. I have defined on parent element to wrap the child elements if there is no space left using flex-wrap property.
<div class="parent">
<div class="flex-1 child-image">
<img src="https://via.placeholder.com/720
C/O https://placeholder.com/"/>
</div>
<div class="flex-1 child-text">
Some Dummy Text
</div>
</div>
body {
background-color: #a3d5d3;
}
.parent{
display: flex;
align-items: center;
flex-wrap: wrap;
}
.flex-1{
flex: 1;
}
.child-text{
whitespace: nowrap;
}
I am working on a project and want to have infinite horizontal scrolling for cells that each contain a thumbnail and some text. I have everything mostly working. However, I can not get text to wrap. The css and html are below. The first two items in the scroll box have text that should wrap, but overflows.
This is the style (cell 2 is only for demo to alternate background colors):
.container {
display: flex;
flex-direction: row;
padding: 10px;
height: 10%;
overflow-x: auto;
white-space: nowrap;
}
.cell {
background: #818181;
flex: fit-content;
padding: 10px;
width: 220px;
height: 8%;
display: inline-block;
}
.cell2 {
background: #f44336;
flex: fit-content;
padding: 10px;
width: 220px;
height: 8%;
display: inline-block;
}
.data {
justify-content: center;
word-wrap: break-word;
}
<div>
<h2>Scroll Test</h2>
<div class="container">
<div class="cell">
<a href= "#">
<span class="data"> <img src="http://roncabeanz.com/Roncabeanz/images/CoffeeIcon.jpg" width="200px"></span>
<span class="data"> <h3>Some text here</h3></span>
</a>
</div>
<div class="cell2">
<a href= "#">
<span class="data"> <img src="http://roncabeanz.com/Roncabeanz/images/CoffeeIcon.jpg" width="200px"></span>
<span class="data"> <h3>Some text here that will over flow</h3></span>
</a>
</div>
<div class="cell">
<a href= "#">
<span class="data"> <img src="http://roncabeanz.com/Roncabeanz/images/CoffeeIcon.jpg" width="200px"></span>
<span class="data"> <h3>Some text here</h3></span>
</a>
</div>
<div class="cell2">
<a href= "#">
<div class="data"> <img src="http://roncabeanz.com/Roncabeanz/images/CoffeeIcon.jpg" width="200px"> </div>
<div class="data"> <h3>Some text here</h3></div>
</a>
</div>
<?php } ?>
</div>
</div>
Link to fiddle: https://jsfiddle.net/jonathannah/3rxcktpm/29/
Just add
h3 { white-space: normal }. The children of .containerinherit white-space: nowrap, which causes the problem.
Another issue in your html is the h3 inside a span, which is invalid. You shouldn't use block elements inside inline elements. You can change it to a div give it the style display: inline
I have a title composed of two words, the first word appears in the logo, the second I add it with a h1. How do i do to align image and h1 to get the full title and is responsive?
The result I want to get is something like this: http://i65.tinypic.com/34t9ukj.png
The html is:
<div id="header">
<a href="xxxxx.html">
<img src="img/logo.jpg" id="logo" alt="logo">
<h1 id="titolo_logo"> Abbigliamento </h1>
</a>
</div>
You can use flexbox, with the a tag as the container and align-items: center; to get the vertically centered alignment:
#header a {
display: flex;
align-items: center;
}
h1 {
margin-left: 10px;
}
<div id="header">
<a href="xxxxx.html">
<img src="http://placehold.it/150x150/fb3" id="logo" alt="logo">
<h1 id="titolo_logo"> Abbigliamento </h1>
</a>
</div>
A second solution would be to make the inner items inline-blocks, with the following settings:
#header a > img,
#titolo_logo{
display: inline-block;
vertical-align: middle;
}
#titolo_logo {
padding-left: 10px;
}
<div id="header">
<a href="xxxxx.html">
<img src="http://placehold.it/150x150/fb3" id="logo" alt="logo"><h1 id="titolo_logo">Abbigliamento</h1>
</a>
</div>
The disadvantage is that in this case not the whole header area (which I assume this is supposed to be) is clickable as a link, but only the image and the h1 themselves, whereas in the flexbox solution you can also click above and below the h1 to open the link.
I'm trying to centre two buttons but having no luck!
It also has a header image above the buttons within the HTML.
Here's my current HTML:
HTML:
<div>
<img src=".jpg" style="width:700px;display:block;margin-left:auto;margin-right:auto;" alt=""><div class="nav3" style="height:705px;">
<span class="icons"><a href="https://twitter.com/" class="icons">
<img src=".png" style="width:100px;display:block;margin-left:auto;margin-right:auto;" alt=""></a>
</span>
<a href="https://www.amazon.co.uk/" class="icons">
<img src=".png" style="width:100px;display:block;margin-left:auto;margin-right:auto;" alt=""></a>
</div>
I revised your code and separate it the inline style from your html code.
div {
text-align: center;
width: 700px;
}
div img{
width:700px;
margin-bottom: 20px;
}
.nav3 img {
width: 100px;
display: inline;
}
<div>
<img src="http://placehold.it/700x260" alt="">
<div class="nav3">
<img src="http://placehold.it/640x260" alt="">
<img src="http://placehold.it/640x260" alt="">
</div>
</div>
Currently, I set the width of div to width: 700px; and the place holder also contains the same width. Modify these width to suit your needs.