How to make the picture and text go in a row - html

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

Related

How to fix the text inside a block below an image

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.

How to vertically center text adjacent to image in grid alignment?

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.

Flexbox: centering everything on one line

I'm trying to recreate this layout with flexbox only:
I'm trying to keep it as simple as possible with minimal markup, however I'm having a hard time vertically centering everything on one line.
What am I doing wrong?
This is the code:
body {
margin: 0;
}
#p {
background: #26272b;
color: white;
display: flex;
align-items: center;
padding: 1rem;
justify-content: space-between;
}
img {
width: 1rem;
}
.pp {
width: 2rem
}
<div id="p">
<div id="pl">
<img src="http://mortenhjort.dk/synchub/imgs/beamed-note.svg" alt="note">
<h4>A Head Full Of Dreams <span>- Coldplay</span></h4>
</div>
<div id="pc">
<a href="#">
<img src="http://mortenhjort.dk/synchub/imgs/previous.svg" alt="Click to go back">
</a>
<a href="#">
<img class="pp" src="http://mortenhjort.dk/synchub/imgs/play.svg" alt="Click to play">
</a>
<!-- <img class="pp" src="http://mortenhjort.dk/synchub/imgs/pause.svg" alt="Click to pause"> -->
<a href="#">
<img src="http://mortenhjort.dk/synchub/imgs/next.svg" alt="Click to skip">
</a>
</div>
<div id="pr"></div>
<time>00:14 / 00:30</time>
<div></div>
This is the JSFiddle: https://jsfiddle.net/h1k8v16g/
Your primary flex container is working to keep flex items vertically centered.
However, the content of the flex items is still in a block formatting context.
Therefore, make the flex items into flex containers with centering:
div { display: flex; align-items: center; }
revised fiddle
Learn more about the scope of a flex formatting context here: https://stackoverflow.com/a/37844240/3597276

How to make anchor tag fit to content? not entire width of page

I have got the look I desire with my css. A centered <p> and <div> one on top of the other and they are both wrapped in <a> tags.
Now my issue is that the <a> tags go for the entire width of the page, I just want to be able to click on the link where the actual content is.
example link:
https://jsfiddle.net/vinko_k_design/dge4fx2z/
Put the anchor tags inside the p tag.
<p class="page-nav">Check out our Map</p>
Using a span (inline element) instead of a div/p (block element), and moving the text-align property to the upper level will fix your issue. As follows:
.page-nav-buttons {
text-align: center;
}
.page-nav {
}
.page-nav-img {
width: 20px;
height: 20px;
background-color: red;
display: inline-block;
margin-left: auto;
margin-right: auto;
}
<div class="page-nav-buttons">
<a href="#map">
<span class="page-nav">Check out our Map</span>
</a>
<br/>
<a href="#map">
<span class="page-nav-img"></span>
</a>
</div>
Try this
https://jsfiddle.net/dge4fx2z/1/
<div class="page-nav-buttons">
<p class="page-nav"> <a href="#map">
Check out our Map
</a>
</p> <span class="page-nav-img">
<a href="#map">
<span class="page-nav-img"></span>
</a>
</span>
</div>

Variation on CSS vertical image align

I'm in the midst of creating a gallery. I have rows of thumbnail images where each row is its own div, and there are five thumbnails to a row. The problem is, the heights of these thumbnails are neither uniform nor predictable. I have given the thumbnails a width of 10.25rem in order to keep their widths predictable while maintaining their proportional heights. Unfortunately, this has resulted in the horizontally-aligned images to have varying degrees of whitespace above them, and the result is kind of ugly. My current code, just so we're all on the same page at this point:
Relevant CSS:
#gallery {
margin-top: 0.85em;
}
.gallery-row {
margin-top: 0.25em;
}
.gallery-thumb {
margin: 0 0.25em;
width: 10.250rem;
border: 1px solid #c70f36;
border-radius: 4px;
}
Relevant HTML/Twig:
<div id="gallery">
<div class="gallery-row">
{% for image in images %}
{% if loop.index0 % 5 == 0 %}
</div><div class="gallery-row">
{% endif %}
<img src="{{ asset('uploads/gallery/' ~ image.filename) }}" class="gallery-thumb">
{% endfor %}
</div>
</div>
What I'd like to do is vertically align all the images to the middle of each gallery-row. Since the row's height is dependent on the tallest thumbnail, they'd fill the row and the shorter thumbnails would be in the middle rather than the bottom. Only problem is that I'm not sure how to do it. I've tried the various suggestions listed here, but they haven't worked. All I get are my images stacked on top of one another, completely outside of the normal document flow.
You can make your images display: inline and add vertical-align: middle, like this:
http://jsfiddle.net/s9gp49kq/
Is this what you are looking for?
If so, is what I did?
» Remove your width on .gallery-thumb
» Added this code below to do the trick:
#gallery {
display:table
}
.gallery-row:before {
content:"";
display: inline-block;
height: 100%;
vertical-align: middle;
}
.gallery-row {
display:table-cell;
vertical-align:middle
}
This way you have either your .gallery-row and .gallery-thumb vertical aligned whether the height is.
See Full Snippet Below:
#gallery {
margin: 1em;
border:1px solid blue;
display:table
}
.gallery-row {
display:table-cell;
vertical-align:middle
}
.gallery-row:before {
content:"";
display: inline-block;
height: 100%;
vertical-align: middle;
}
.gallery-thumb {
margin: 0 0.25em;
padding:.5em;
border: 1px solid #c70f36;
border-radius: 4px;
}
<div id="gallery">
<div class="gallery-row">
<a href="#" data-lightbox="gallery">
<img src="http://placehold.it/100x100" class="gallery-thumb" />
</a>
</div>
<div class="gallery-row">
<a href="#" data-lightbox="gallery">
<img src="http://placehold.it/100x110" class="gallery-thumb" />
</a>
</div>
<div class="gallery-row">
<a href="#" data-lightbox="gallery">
<img src="http://placehold.it/100x120" class="gallery-thumb" />
</a>
</div>
<div class="gallery-row">
<a href="#" data-lightbox="gallery">
<img src="http://placehold.it/100x130" class="gallery-thumb" />
</a>
</div>
<div class="gallery-row">
<a href="#" data-lightbox="gallery">
<img src="http://placehold.it/100x140" class="gallery-thumb" />
</a>
</div>
</div>