I have the following code and want the anchor everywhere in the box not only at the image:
HTML:
<p style="clear:left" />
<div class="reference_container">
<div class="reference_box reference_box_geraete">
<a href="google.de">
<img src="http://www.hanselman.com/blog/content/binary/WindowsLiveWriter/Hans.NETMVCJeffAtwoodandhistechnicalteam_1349C/stackoverflow-logo-250_3.png"/>
</a>
</div>
<div class="reference_box reference_box_geraete">
<a href="google.de">
<img src="http://www.johndscomputers.com/wp-content/uploads/2014/02/200px-Apple_logo_black.svg_.png"/>
</a>
</div>
<div class="reference_box reference_box_geraete">
<a href="google.de">
<img src="http://www.johndscomputers.com/wp-content/uploads/2014/02/200px-Apple_logo_black.svg_.png"/>
</a>
</div>
<div class="reference_box reference_box_geraete">
<a href="google.de">
<img src="http://www.hanselman.com/blog/content/binary/WindowsLiveWriter/Hans.NETMVCJeffAtwoodandhistechnicalteam_1349C/stackoverflow-logo-250_3.png"/>
</a>
</div>
</div>
<p style="clear:left" />
CSS:
.reference_container {
display: flex;
}
.reference_box {
border: 1px solid #ddd;
border-radius: 5px;
margin: 1%;
position:relative;
overflow: hidden;
padding: 15px;
white-space: nowrap;
display:inline-block;
}
.reference_box_geraete {
width: 22%;
/*box-sizing: border-box;*/
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
.reference_box_geraete img {
vertical-align: middle;
max-width: 100%;
max-height: 100%;
}
The problem is that I don't get the anchor to stretch to the whole surrounding div.
I tried to remove the div and make the anchor as block-element, but then the images are not stretched correctly (doesn't keep aspect-ratio) when resizing the browser window.
How can I achieve this.
set width , height and display:block for element a
check this:
<p style="clear:left" />
<div class="reference_container">
<a class="reference_box reference_box_geraete" href="google.de">
<img src="http://www.hanselman.com/blog/content/binary/WindowsLiveWriter/Hans.NETMVCJeffAtwoodandhistechnicalteam_1349C/stackoverflow-logo-250_3.png"/>
</a>
<a href="google.de" class="reference_box reference_box_geraete">
<img src="http://www.johndscomputers.com/wp-content/uploads/2014/02/200px-Apple_logo_black.svg_.png"/>
</a>
<a href="google.de" class="reference_box reference_box_geraete">
<img src="http://www.johndscomputers.com/wp-content/uploads/2014/02/200px-Apple_logo_black.svg_.png"/>
</a>
<a href="google.de" class="reference_box reference_box_geraete">
<img src="http://www.hanselman.com/blog/content/binary/WindowsLiveWriter/Hans.NETMVCJeffAtwoodandhistechnicalteam_1349C/stackoverflow-logo-250_3.png"/>
</a>
</div>
<p style="clear:left" />
Demo: http://www.cssdesk.com/p5Cqd
Related
This question already has answers here:
Why are flex items not wrapping?
(2 answers)
Closed 1 year ago.
So am new to learning/using the "display: flex" property.
*{
margin: 10px;
padding: 0;
-webkit-margin:0;
-webkit-padding:0;
}
.container {
display: flex;
}
.imagebox {
position: relative;
flex: 1;
margin: 15px;
}
.imagebox img {
max-height: 200px;
max-width: 100%;
position: absolute;
}
<div class="container">
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
</div>
Here are 4 boxes of a certain size but if I insert one more, the size gets smaller as it tries to fit the 5th box in the same line, how to get the 5th box in the next line?
*{
margin: 10px;
padding: 0;
-webkit-margin:0;
-webkit-padding:0;
}
.container {
display: flex;
}
.imagebox {
position: relative;
flex: 1;
margin: 15px;
}
.imagebox img {
max-height: 200px;
max-width: 100%;
position: absolute;
}
<div class="container">
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
</div>
I want the images to automatically go on to the next line when it reaches the end of the main container, I have tried reducing the width as well, it didn't work.
It's probably something very simple but I can't really seem to find the way, also am not fully accustomed with all the flexbox properties
change width of .imagebox {} accordingly
*{
padding: 0;
-webkit-margin:0;
-webkit-padding:0;
}
.container {
display: flex;
flex-wrap: wrap;
}
.imagebox {
position: relative;
margin: 15px;
width: 20%;
}
.imagebox img {
max-height: 200px;
max-width: 100%;
}
<div class="container">
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
</div>
You can use the flex-wrap property:
.container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
Flexbox doesn't play nicely with absolutely-positioned children. By taking the images out of the normal flow, they no longer take part in the flexbox calculations. The remaining imagebox element is not wide enough to trigger wrapping.
.container {
display: flex;
flex-wrap: wrap;
gap: 15px;
}
.imagebox {
flex: 0 0 calc((100% - 45px) / 4);
}
.imagebox img {
max-height: 200px;
max-width: 100%;
}
<div class="container">
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
<div class="imagebox">
<a href="#" class="images">
<img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
</a>
</div>
</div>
I am trying to center my image gallery without decreasing the size of the images. I tried to work with some of the solutions in similar questions but they require making the images super small. Is there a way to keep the size of my images, have my images side by side, and just center the whole thing? :D Thanks so much in advance!
Here is my code:
<style>
div.gallery {
margin: 5px;
border: 0px solid #ccc;
float: left;
text-align: center;
width: 330px;
}
div.gallery:hover {
border: 0px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 9px;
text-align: center;
display: block;
margin: 0 auto;
}
</style>
<div id="container">
<div class="gallery">
<a target="_blank" href="img.jpg">
</a><a target="_blank" href="img.jpg"><img src="img.jpg" alt="Select Your Flavors" width="600" height="400">
</a>
<div class="desc"><h3>Choose Your Flavors</h3></div>
<div class="desc">
<p>Text</p>
<div class="center-section"><a class="btn button" href="https://completeats.myshopify.com/collections/shop">Find Your Box</a></div>
</div>
<p></p>
</div>
<div class="gallery">
<a target="_blank" href="img.jpg">
</a><a target="_blank" href="img.jpg"><img src="img" alt="Get Your Box" width="600" height="400">
</a>
<div class="desc"><h3>Get Your Box</h3></div>
<div class="center-section">
<a class="btn button" href="https://completeats.myshopify.com/collections/shop">Find Your Box</a><p></p>
</div>
</div>
<p></p>
</div>
<div class="gallery">
<a target="_blank" href="img.jpg">
</a><a target="_blank" href="img.jpg"><img src="img" width="600" height="400">
</a>
<div class="desc"><h3>text</h3></div>
<div class="center-section"><a class="btn button" href="">Shop Now</a></div>
</div>
<p></p>
</div></div>
i add "cover" your "gallery" div with "gallery-wrapper" class and add css for center image align.
.gallery-wrapper{
display:table;
margin:0 auto;
}
<style>
div.gallery {
margin: 5px;
border: 0px solid #ccc;
float: left;
text-align: center;
width: 330px;
}
div.gallery:hover {
border: 0px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 9px;
text-align: center;
display: block;
margin: 0 auto;
}
</style>
<div id="container">
<div class="gallery-wrapper">
<div class="gallery">
<a target="_blank" href="img.jpg">
</a><a target="_blank" href="img.jpg"><img src="https://images.unsplash.com/photo-1469317835793-6d02c2392778?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1352&q=80" alt="Select Your Flavors" width="600" height="400">
</a>
<div class="desc"><h3>Choose Your Flavors</h3></div>
<div class="desc">
<p>Text</p>
<div class="center-section"><a class="btn button" href="https://completeats.myshopify.com/collections/shop">Find Your Box</a></div>
</div>
</div>
<div class="gallery">
<a target="_blank" href="img.jpg">
</a><a target="_blank" href="img.jpg"><img src="https://images.unsplash.com/photo-1469317835793-6d02c2392778?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1352&q=80" alt="Get Your Box" width="600" height="400">
</a>
<div class="desc"><h3>Get Your Box</h3></div>
<div class="center-section">
<a class="btn button" href="https://completeats.myshopify.com/collections/shop">Find Your Box</a><p></p>
</div>
</div>
<div class="gallery">
<a target="_blank" href="img.jpg">
</a><a target="_blank" href="img.jpg"><img src="https://images.unsplash.com/photo-1469317835793-6d02c2392778?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1352&q=80" width="600" height="400">
</a>
<div class="desc"><h3>text</h3></div>
<div class="center-section"><a class="btn button" href="">Shop Now</a></div>
</div>
</div>
like this :https://i.ibb.co/pzz0MxF/846c4b24-6934-4447-82c1-a25b11ea581c.png
Note: always use class name as section name like "club-works" for good css under standing
You have to add css in this class
.custom-html .custom-html__code {
display: table;
margin: 0 auto;
}
My images won't sit side by side & I'm not sure why.
I've set the display to be inline and it still doesn't work.
I think i should mention that i'd like the 4 colourful buttons to be grouped as how they are now, 2 on top and 2 on the bottom, but i'd still like for it to be inline with the logo and the pfp image..
Here's what I have for the css page so far.
and here's how they currently sit
*the 'vengage' box is the logo, so it should sit like
on 1 row [vengage][home][settings] [pfp]
and then have [fyp] [search] directly underneath the home & settings buttons
if it's useful, this is along the lines of how i'd like them to sit on the webpage if possible
* {
box-sizing: border-box;
}
body {
width: 999px;
height: 1000px;
text-decoration: none;
}
.logo {
padding: 5px;
display: flex;
}
.menu {
display: flex;
flex-direction: row;
}
<div class='menu'>
<div class='logo'>
<img src='https://via.placeholder.com/140x100?text=LOGO' width='100'>
</div>
<div class='above'>
<div class='homebutton'>
<a href='Code draft.html'>
<img src='https://via.placeholder.com/140x100' width='50'>
</a>
</div>
<div class='settingsbutton'>
<a href='menusettings.html'>
<img src='https://via.placeholder.com/140x100' width='50'>
</a>
</div>
</div>
<div class='below'>
<div class='fypbutton'>
<a href='fyp.html'>
<img src='https://via.placeholder.com/140x100' width='50'>
</a>
</div>
<div class='searchbutton'>
<a href='search.html'>
<img src='https://via.placeholder.com/140x100' width='50'>
</a>
</div>
</div>
<div class="pfp">
<a href="Profile Page.html">
<img src='https://via.placeholder.com/140x100' width='50'>
</a>
</div>
</div>
Remove display: inline from menu class and add display: flex again if you want to align all the elements with the logo than just change the position of menu div, make it as a mother div. Hope it solves your problem
* {
box-sizing: border-box;
}
body {
display: inline-block;
width: 999px;
height: 1000px;
text-decoration: none;
}
.logo {
padding: 5px;
display: inline;
}
.menu {
display: flex;
}
<div class='menu'>
<div class='logo'>
<img src='https://i.ibb.co/h9L3Fyq/logo.jpg' width='100'>
</div>
<div class='above'>
<div class='homebutton'>
<a href='Code draft.html'>
<img src='https://via.placeholder.com/140x100' width='50'>
</a>
</div>
<div class='settingsbutton'>
<a href='menusettings.html'>
<img src='https://via.placeholder.com/140x100' width='50'>
</a>
</div>
</div>
<div class='below'>
<div class='fypbutton'>
<a href='fyp.html'>
<img src='https://via.placeholder.com/140x100' width='50'>
</a>
</div>
<div class='searchbutton'>
<a href='search.html'>
<img src='https://via.placeholder.com/140x100' width='50'>
</a>
</div>
</div>
<div class="pfp">
<a href="Profile Page.html">
<img src='https://via.placeholder.com/140x100' width='50'>
</a>
</div>
</div>
try this instead,
Add display:flex; to body. also add vertical-align:top;to all image
that is
body{
display:flex;
}
img{
vertical-align:top;
}
* {
box-sizing: border-box;
}
body{
width: 999px;
height: 1000px;
text-decoration: none;
display:flex;
}
img{
vertical-align:top;
border:1px solid #111;
}
<div class='logo'>
<img src='https://i.stack.imgur.com/8U82Z.png' width ="75px">
</div>
<div class = 'menu'>
<div class = 'above'></div>
<div class = 'homebutton'>
<a href = 'Code draft.html'>
<img src = 'https://i.stack.imgur.com/QM11G.png' width = "50px">
</a>
</div>
<div class = 'settingsbutton'>
<a href = 'menusettings.html'>
<img src = 'https://i.stack.imgur.com/LFcP2.png' width = "50px">
</a>
</div>
</div>
<div class = 'below'>
<div class = 'fypbutton'>
<a href = 'fyp.html'>
<img src = 'https://i.stack.imgur.com/rV49R.png' width = "50px">
</a>
</div>
<div class = 'searchbutton'>
<a href = 'search.html'>
<img src = 'https://i.stack.imgur.com/z6gVZ.png' width = "50px">
</a>
</div>
</div>
<div class="pfp">
<a href="Profile Page.html">
<img src='https://i.stack.imgur.com/qpEQy.png' width = "29px">
</a>
</div>
</div>
Hey guys take a look at this example. (Look full screen) You can see the elements change opacity on hover.
However flex items that flex-wrap to the second row seem to move or change height with this same hover... It looks like a bounce effect. Nothing should be different but opacity. I tried only targeting opacity in my transition, tried flex: 0 0 23%; so links shouldn't be changing size, but still get the same result.
Basically since I've added the opacity hover/transition, second row of flex items bounce on hover.
What is going on?
.nav-dropdown {
display: block;
width: 100%;
max-width: 980px;
padding: 30px;
background-color: #fbfbfb;
}
.nav-dropdown-image-links {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.image-link {
flex: 0 1 23%;
margin-bottom: 20px;
}
.image-link a {}
.image-link a img {
display: block;
width: 100%;
margin-bottom: 8px;
opacity: 1;
transition: 0.3s;
}
.image-link a img:hover {
opacity: 0.9;
}
<div class="nav-dropdown">
<div class="nav-dropdown-image-links">
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
</div>
</div>
Use the following style
.image-link * {
-webkit-backface-visibility: hidden;
}
This link explains why we need it.
.nav-dropdown {
display: block;
width: 100%;
max-width: 980px;
padding: 30px;
background-color: #fbfbfb;
}
.nav-dropdown-image-links {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.image-link {
flex: 0 1 23%;
margin-bottom: 20px;
}
.image-link a {}
.image-link a img {
display: block;
width: 100%;
margin-bottom: 8px;
opacity: 1;
transition: 0.3s;
}
.image-link a img:hover {
opacity: 0.9;
}
.image-link * {
-webkit-backface-visibility: hidden;
}
<div class="nav-dropdown">
<div class="nav-dropdown-image-links">
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
<div class="image-link">
<a href="https://placeholder.com">
<img src="http://via.placeholder.com/260x168">
</a>
</div>
</div>
</div>
I have tried for some time to do something like on the image.
Elements (.element) goes down but they are not centered but stick left.
My code now is:
Html:
<div id="_technology_page" class="region">
<div class="actions_container">
<div class="actions">
{{#each actions}}
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
{{text}}
</p>
</a>
</div>
{{/each}}
</div>
</div>
</div>
Css: (scss):
#_technology_page {
.actions_container {
max-width: 100%;
position: relative;
text-align: center;
display: flex;
.actions {
position: relative;
.action {
float: left;
position: relative;
position: relative;
margin: 10px 40px;
text-align: center;
float: left;
height: 300px;
width: 250px;
display: flex;
img {
margin: auto;
width: 120px
}
.action_text {
width: 100%;
color: black;
position: absolute;
bottom: 0;
}
}
}
}
}
I have tried many things, search examples, bot nothing works as I want it to works.
Also, I have tried to do it on Bootstrap grid system, but those elements are still stuck to the left side of the container.
Please provide some examples how to do it, I have no idea how to do it anymore.
using flexbox here is a way simpler code from yours
body {
margin: 0
}
.region {
border: solid;
padding: 50px 0
}
.actions {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
border: red solid;
padding: 10px;
}
.action {
flex: 0 140px;
height: 140px;
border: orange solid;
margin: 5px;
}
<div id="_technology_page" class="region">
<div class="actions_container">
<div class="actions">
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
</p>
</a>
</div>
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
</p>
</a>
</div>
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
</p>
</a>
</div>
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
</p>
</a>
</div>
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
</p>
</a>
</div>
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
</p>
</a>
</div>
<div class="action">
<a href="{{link}}">
<img src="/img/technology/grafiki/{{icon}}.png" alt="">
<p class="action_text">
</p>
</a>
</div>
</div>
</div>
</div>