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>
Related
I am working on a project and i can't seem to find a way that works to center and make my footer responsive.
This is my html code.
#footer {
position: absolute;
left:0;
bottom: 0;
width: 100%;
height: 2.5rem;
background-color: black;
border-top: 4px solid #F2D380 !important;
}
.socialIcon {//update
width: 20px;
}
<div id="footer">
<div class="col-lg-2 link_list">
Company Information
</div>
<div class="col-lg-2 link_list">
<a href="#" > Privacy Policy and User Agreement </a>
</div>
<div class="col-lg-2 link_list">
About
</div>
<div class="col-lg-2 link_list">
<a href="#" >
©2019 Copyright claim
</a>
</div>
```
<div class="col-sm-6 col-lg-3">//update
<a href="#">
<img src="images/linkedin.png" class=" socialIcon">
</a>
<a href="#" >
<img src="images/instagram.png" class=" socialIcon">
</a>
<a href="#">
<img src="images/facebook.png" class=" socialIcon">
</a>
<a href="#" >
<img src="images/youtube.png" class="socialIcon">
</a>
</div>
</div>
```
I tried some bootstrap classes like justify-content-center but it simply does not work. I know i need to be looking at flexbox but it won't work and i don't know what the problem is.
Thank you in advance for answering.
*Update after i did what i saw in the comments it doesn't work with the socialmedia icons.
I've edited your codes. I explained what I changed in the comment lines. I removed the display table. You don't need this with this codes.
Html :
<div id="footer">
<div class="row text-center"> // I added row here, and I've got all the columns in a row, because all columns must be in a row. I added a "text center" class to keep all the text in the middle.
<div class="col-sm-6 pb-sm-2 col-lg-3"> // that's how I arranged your columns . So they will adjust their width for each width value
Company Information
</div>
<div class="col-sm-6 col-lg-3">
Privacy Policy and User Agreement
</div>
<div class="col-sm-6 pb-sm-2 col-lg-3"> // "pb-sm-2" class to add padding bottom when dimensions are sm
About
</div>
<div class="col-sm-6 col-lg-3">
<a href="#">
©2019 Copyright claim
</a>
</div>
</div>
</div>
Css:
#footer {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
/* height: 2.5rem; */ you can use padding this way instead of specifying height. if you give a single height value, you will need to set height separately for all dimensions.
padding: 20px;
background-color: black;
border-top: 4px solid #F2D380 !important;
}
I hope I could help. Good Luck!
See the code below. You can forget about wrapping each anchor within a "div". It will be a lot easier to simply group them into the parent DIV and then target them. This should work and you can have more flexibility. Also, don't have to worry about flexbox or any external libraries.
<style>
body{
height:2000px; /* for demonstration purposes*/
}
/* position the footer div RELATIVE and give it a "top" property of 100% so it always sits at the bottom regardless of your window height*/
#footer {
position: relative;
top:100%;
width: 100%;
height: 2.5rem;
background-color: black;
border-top: 4px solid #F2D380 !important;
}
/* center all items INSIDE the link_list DIV*/
.link_list{
text-align:center;
}
/* target all the ANCHOR tags as inline elements*/
.link_list a {
margin:50% 20px;
color:white;
text-decoration:none;
text-align: center;
flex: 0 0 16.666667%;
}
</style>
<body>
<div id="footer">
<div class="col-lg-2 link_list">
Company Information
<a href="#" > Privacy Policy and User Agreement </a>
About
<a href="#" >©2019 Copyright claim</a>
</div>
</div>
</body>
Add display:flex; to #footer and it gets a bit of responsiveness.
quick fiddle => https://jsfiddle.net/0b9hoag1/
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;
}
Currently, the top of my web page looks like this:
I'm trying to use Bootstrap instead of CSS as I was told it was simpler (however so far I'm struggling to bend it to my will just as much as CSS). I have a div containing the logo and title, and a Bootstrap container with a list group of buttons to share the website. I want the buttons to appear on the right hand side of the page inline with the logo.
HTML:
<div class="headerDiv" style="display: inline">
<div>
<img id="logo" src="{% static "images/logo.jpg" %}" alt="Fact or Fiction Logo" />
</div>
<div class="titleDiv">
<h1 id="title">FACTorFICTION</h1>
</div>
</div>
<div class="container" style="display: inline">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<div class="list-group list-group-horizontal">
<script>
function fbs_click() {
u = location.href;
t = document.title;
window.open
('http://www.facebook.com/sharer.php?u=' +
encodeURIComponent(u) + '&t=' + encodeURIComponent(t),
'sharer', 'toolbar=0,status=0,width=626,height=436');
return false;
}
</script>
<a class="list-group-item" href="http://www.facebook.com/share.php?u=http://www.example.com/" onclick="return fbs_click()" target="_blank">
<img src="{% static "images/facebook.jpg" %}" alt="Share to Facebook.">
</a>
<a class="list-group-item" href="https://twitter.com/home?status=http://www.example.com/" onclick="window.open('https://twitter.com/home?status=Fact Or Fiction http://www.example.com/; return false;">
<img src="{% static "images/twitter.jpg" %}" alt="Share to Twitter.">
</a>
<a class="list-group-item" href="https://plus.google.com/share?url=http://www.example.com/" onclick="window.open('https://plus.google.com/share?url=http://www.example.com/',null,'height=626,width=436,status=yes,toolbar=no,menubar=no,location=no'); return false;" target="_blank">
<img src="{% static "images/googleplus.jpg" %}" alt="Share to Google Plus.">
</a>
<a class="list-group-item" href="http://www.reddit.com/submit" onclick="window.open('http://www.reddit.com/submit?url=http://www.example.com/',null,'height=900,width=750,status=yes,toolbar=no,menubar=no,location=no'); return false;">
<img src="{% static "images/reddit.jpg" %}" alt="Share to Reddit.">
</a>
</div>
</div>
</div>
</div>
CSS:
.list-group-horizontal .list-group-item {
display: inline-block;
}
.list-group-horizontal .list-group-item {
margin-bottom: 0;
margin-left:-4px;
margin-right: 0;
}
.list-group-horizontal .list-group-item:first-child {
border-top-right-radius:0;
border-bottom-left-radius:4px;
}
.list-group-horizontal .list-group-item:last-child {
border-top-right-radius:4px;
border-bottom-left-radius:0;
}
.headerDiv {
float: left;
padding-top: 10px;
padding-left: 10px;
padding-right: 10px;
margin-bottom: 5px;
margin-right: 5px;
}
.headerDiv div {
display:table-cell;
}
.titleDiv {
position: relative;
top: 30px;
width:100%;
}
I have tried putting the two divs inside another, however for some reason this causes my buttons to be vertical, and still beneath the logo.
I'm open to all suggestions, including telling me that I'm going about this completely wrong. Thanks in advance.
Bootstrap is easy as long as you understand the fundamental concept and basic structure. It general has a structure of a container with rows and within each row, you could have several cols. With that in mind, it is as easy as this:
<div class="container">
<div class="row">
<div class="headerDiv col-xs-4">
<img src="https://placehold.it/200x50">
<h1 id="title">Company Name</h1>
</div>
<div class="list-group list-group-horizontal col-xs-8">
<img src="https://placehold.it/80x20">
<img src="https://placehold.it/80x20">
<img src="https://placehold.it/80x20">
<img src="https://placehold.it/80x20">
</div>
</div>
</div>
With minimum styling as:
.headerDiv {
display:inline;
float:left;
}
h1#title {
display:inline;
}
.list-group {
float: right;
}
You can style the rest of margins and alignment of text as you need.
I been trying to make a page with four responsive images in it arranged in blocks.
Like two images on first row and two on second row.
And since responsive i tried to make them shrink while staying at their places.
But it kinda juggles all around while i try to resize the window.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
#image1 {
position:relative;
float: left;
padding-left: 10px;
margin-left:250px;
border:1px solid;
}
#image2 {
position:relative;
float: left;
padding-left: 10px;
margin-left:300px;
border:1px solid;
padding-bottom:10px;
}
#image3 {
position:relative;
float: left;
margin-left:250px;
padding-top:10px;
border:1px solid;
}
#image4 {
position:relative;
float: left;
padding-top:10px;
padding-left: 10px;
margin-left:300px;
border:1px solid;
}
<div class="container">
<h2>Image</h2>
<p>This text is responsive too</p>
<img class="img-responsive" src="img.png" id="image1" alt="Chania" width="150" height="150">
<img class="img-responsive" src="img.png" id="image2" alt="Chania" width="150" height="150">
<img class="img-responsive" src="img.png" id="image3" alt="Chania" width="150" height="150">
<img class="img-responsive" src="img.png" id="image4" alt="Chania" width="150" height="150">
</div>
Any suggestion is greatly appreciated..
First off. I see you are using bootstrap. Make sure you are utilizing the built in grid layout system. Your container won't be used unless you set rows and columns. That will handle most of your responsive behaviour.
Then you need to set two images in a row.
Not sure why you'd set the images position. Unless you are making the images reach outside the container you really don't need to utilize the positions.
If you do need the position. Then the parent will have the relative property. The child you want to move will be set to absolute. Google mdn position for more info on the properties. Note: if you don't set the position of the child to absolute, then that element will remain in the normal flow and ignore the relative parent.
Something like this might get you headed in the right direction:
<style>
parent-div {
position: relative;
}
child-image {
position: absolute;
left: 0;
top: 0;
}
child-text {
position: absolute;
bottom: 10px;
left: 0;
z-index: 10; /*set text above image*/
}
img {
width: 100%; /* fill to parent */
}
</style>
<body class="container-fluid">
<div class="row">
<div class="col-md-6 parent-div">
<p class="child-text">This text is responsive too</p>
<img class="child-image" href="" alt="">
</div>
<div class="col-md-6 parent-div">
<img class="child-image" href="" alt="">
</div>
</div><!-- End of row -->
<div class="row">
<div class="col-md-6 parent-div">
<p>This text is responsive too</p>
<img class="child-image" href="" alt="">
</div>
<div class="col-md-6 parent-div">
<img class="child-image" href="" alt="">
</div>
</div><!-- End of row -->
</body><!-- End of page -->
What I want to do is have the images on this site change in width and height (they should be equal) between 50-60px. However between them they all need to have a minimum padding of 5px. This can vary depending on the size of the images, this is the case as the two end images need to fit to the edges of the parent div, to align with an image about it. The height/width/padding should all change to ensure the images are still properly aligned when then screen size changes.
If you look at this page you will be able to see what I mean. The images that need to change are the grey squares at the bottom.
http://media.gaigo.org/work2.html
This is my html:
<div class="smallImages">
<div><img src="static/img/smallImage.png"></div>
<div><img src="static/img/smallImage.png"></div>
<div><img src="static/img/smallImage.png"></div>
<div><img src="static/img/smallImage.png"></div>
</div>
and my css is as follows:
smallImages div {
display: inline-block;
padding: 5px;
}
.smallImages div img {
max-width: 60px;
min-width: 50px;
max-height: 60px;
min-height: 50px;
}
Sorry if this seems confusing. Just ask if you need me to explain more.
One option is to set percentage widths, however that number percentage is dependent upon the number of images in your row. See this example:
* {
box-sizing:border-box; /* You need this so that heights and widths are inclusive of padding and border */
}
.container {
width:400px; /* set this to whatever you like, it should work still */
padding:5px;
border:1px solid;
}
.row {
width:100%;
padding:0 5px;
}
.row img {
padding:5px;
}
.row.one img {
width:100%;
}
.row.two img {
width:50%;
}
.row.three img {
width:33.33%;
}
.row.four img {
width:25%;
}
<div class="container">
<div class="row one">
<img src="http://placehold.it/150x150">
</div>
<div class="row two">
<img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150">
</div>
<div class="row three">
<img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150">
</div>
<div class="row four">
<img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150">
</div>
</div>
Putting HTML comments between lines means there's no white space between the images.
This is what you are after.
Display inline-block wont let the images behave in that manner you need to use table.
You should just check the source code of the site you are working from..
.row {
display: table-row;
}
.smallImages {
padding-left: 0px;
margin-bottom: 0px;
display: table;
text-align: center;
}
.smallImages .row div {
display: table-cell;
padding: 5px;
}
.smallImages .row div:first-child {
padding-left: 0;
}
.smallImages .row div img {
max-width: 100%;
}
img {
border: 0;
}
<div class="smallImages">
<div class="row">
<div>
<a href="#item-1">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-2">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-3">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-4">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-5">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-6">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-7">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-8">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-9">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-10">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-11">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-12">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
</div>
</div>