I am new for web design. I am trying to making a box including an icon and a link. When the screen is laptop, the link should be in the left of the icon and align with its center vertically; when screen is tablet and mobile phone, the icon should be under the bottom of the icon and align with its center horizontally. And the icon is much bigger than the link. Here are the code and images links:
<div class="box">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6">
<span class="info-box-icon"><i class="mega-octicon octicon-server"></i></span>
</div>
<div class="col-xs-12 col-sm-12 col-md-6">
<a class="side-box-link" href="workflow-summary" style="vertical-align:middle;">Work Flow</a>
</div>
</div>
</div>
image links:
bg and md:
http://ww3.sinaimg.cn/bmiddle/77f9deafgw1evmq9c8z5tj206703amx6.jpg
sm and xs:
http://ww3.sinaimg.cn/bmiddle/77f9deafgw1evmq9cxdttj2045041gll.jpg
I've tried many method but still cannot make the link align with the icon's center vertically, and the link is always align in top of the box. The methods I've tried:
Use table, and set the icon and link as two table data: they can align as
what I want, but since they are two column, the link cannot move
down when the screen size change.
Use table, put them in same line: align in the box top.
Use list: align in the box top.
Use margin in CSS: align well in md and bg screen but the icon and
link will have gap in sm and xs as well.
Use "vertical-align:middle" in CSS: just not working
What should I do? Any advice will be appreciate, thank you!
You can use Flexbox, there is a nice guide here A Complete Guide to Flexbox
Also take a look at this this example I made for you, hope it can help you out.
Html code:
<div class="box">
<div class="row">
<div class="icon">
<span class="info-box-icon"><i class="mega-octicon octicon-server"></i></span>
</div>
<div class="link">
<a class="side-box-link" href="workflow-summary" style="vertical-align:middle;">Work Flow</a>
</div>
</div>
And this is the CSS:
.row {
display: flex;
align-items: center;
}
.icon {
width: 200px;
height: 200px;
background-color: salmon ;
}
.link{
padding: 10px;
}
a {
text-decoration: none;
}
#media (max-width: 450px) {
.row {
flex-direction: column;
}
}
I did use fixed sizes with the icon to illustrate, but it'll work with any size.
Take a look at this live example JSFiddle Flex Example
Related
I have a dynamic audio player with artist and title.
It works fine but on mobile view, artist and title stick out my div.
Here is a picture:
I'd like artist - title (when longer that user's screen) display just a line below.
I already tested by changing display, overflow-text, word-breakā¦
Here is my code:
#media screen and (orientation: portrait) and (max-width: 750px) {
.titrage { display: inline-grid; }
}
<div class='titrage'>
<div class='now'>Your are listening <img class='cover' src="cover.png" alt='audio-cover'> : </div>
<div class='artist'>Loading </div>
<div class='separator'>-</div>
<div class='title'>...</div>
</div>
Use flex maybe? This should work fine without media queries. Or can with media queries too.
.titrage {
display: flex;
flex-direction: row;
align-items: center;
}
.pad {
padding: 10px;
}
<div class='titrage'>
<div class='now'>
<img class='cover' src="https://via.placeholder.com/75" alt='audio-cover'>
</div>
<div class="pad">
<span>You are Listening :</span>
<span class='artist'>Bee Gees </span>
<span class='separator'>-</span>
<span class='title'>Stayin' Alive (1977)</span>
</div>
</div>
Changing the divs to use display: inline-block; instead of inline grid will change the divs layout behavior.
Here is a link from MDN with more details on block and inline layout flow.
Right now with inline-grid each div is taking up a full row, regardless of its content's size, changing to inline-block will make each div take up roughly the amount of size that its content requires, resulting in them displaying on the same line if they can fit, demonstrated in code snippet below:
.titrage, .now, .artist, .separator, .title { display: inline-block; }
<div class='titrage'>
<div class='now'>Your are listening <img class='cover' src="cover.png" alt='audio-cover'> : </div>
<div class='artist'>Loading </div>
<div class='separator'>-</div>
<div class='title'>...</div>
</div>
This question about making divs layout on the same line is directly related.
Also this question about preferred line break points seems tangentially related.
Thanks for answering ;)
I finally found a solution.
I just put artist - title a line below 'You are listening'.
On .titrage a display: block. On .now a display: fixed. And on a new div .now (including .artist, .separator and .title) a display: flex
It's working for me :p
I have a very trivial problem. I just needed two simple arrows (left and right) vertically aligned to the middle to the image. Arrows have to be responsive and become smaller with screen size.
My code now is just:
<div class="row">
<div class="offset-md-1 col-md-1">
<i class="fa fa-arrow-left" style="position:relative; top:50%"></i>
</div>
<div class="col-md-8 detail_pic">
<img src="#image" style="width:80%;">
<h2 style="text-align:center;">#Title</h2>
</div>
<div class="col-md-1">
<i class="fa fa-arrow-right" style="position:relative; top:50%"></i></div>
</div>
</div>
This looks like the image below. But it doesn't work well when I size down the screen as the cols get stacked over each other. How do I get the arrows and the image in one col and make them responsive?
For the image size...you can have automatically resizing arrow icons by using viewport units like this img{ width: 2vmin} which listens to the shorter of the width/height dimensions in your viewport, and uses a percentage of this dimension... css tricks link for more info css-tricks.com/fun-viewport-units
For positioning the arrows in the center of the div use
img{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
a helpful article on flexbox vertical centering phillipwalton.com
I have the following structure:
<div class="footer col-md-12">
<div class="social col-md-3 col-sm-4 col-sm-offset-0 col-xs-8 col-xs-offset-4">
<div id="fb"></div>
<div id="linkedin"></div>
<div id="gplus"></div>
</div>
</div>
There is also a div with copyright text, that I can't post. it is before the "social" div. On mobile devices, I am removing the copyright text(via display: none;), and I want to center the social icons, but I am unable to do so. I manage to do it, with margins and percentages, but on a specific resolution only, all other mobile resolutions are broken. Can someone assist me?
Note: I tried changing the xs column width and offset, but no combination managed to center the icons. I am posting the one, that was closest, that I centered with adding some margins.
i think that you just need to use class names in html and css as below
HTML
<div class="footer col-md-12">
<div class="copyright col-md-9 col-sm-8">
copyright information
</div>
<div class="social col-md-3 col-sm-4 col-xs-12">
Facebook -
Twitter -
Linkedin
</div>
</div>
CSS
.social{
background:aqua;
text-align: center;
}
.copyright{
background:silver;
}
#media screen and (max-width: 767px) {
.copyright {
display: none !important;
}
}
and this is the sample : https://jsfiddle.net/Tanbi/asohog47/1/
PS: For understanding clearly i used css background colors.
Have you tried:
.social {
display: block;
margin: 0 auto;
}
I find this works for me in most responsive centering dilemmas (with bootstrap in past times too I believe).
Let us know if this helps?
I'm trying to line up three pictures within a bootstrap grid. All of the images were centered, which is what I'm trying to, before I added a img-responsive class to one of the images. I do however want the images to be responsive while also making them a tiny bit larger than they are already. Tried numerous things such as "width: 200%;" however without success
How it looks
I created a "center-all" class within my css that should center all the three of them, and it did work, just until I added the img-responsive class to the red one. The class was not added to any of the other images.
.center-all {
text-align: center;
align-items: center;
align-content: center
vertical-align: center;
}
JSFiddle
https://jsfiddle.net/8a6ee7f5/
Images doesn't work in Fiddle ofc.
What I want to achieve:
I want the images to be 2 times larger than what they currently are and I want them to be responsive while still keeping them centered.
Thanks in advance!
I found the answer to my question(s).
When adding the img-responsive class to the image it moves to the left. By adding "center-block" to the class to the image it should stay in the center.
<img src="..." class="img-responsive center-block">
Now I just need to find the answer on how to upscale my pictures to 200%.
EDIT:
I found the following to upscale my images:
CSS
.wrapper {
width: 40%;
}
and added that to my image class.
HTML
<img src="..." class="img-responsive center-block wrapper">
And that fixed it.
So bootstrap already has an element centering class called .text-center you can just add this class to the row wrapping your items and everything in that row will be centered. Then instead of using .img-responsive you can add a width to the image instead or give the image a percentage width. It will maybe look something like the following hopefully this is what you are looking for:
Here is a fiddle Updated Fiddle
note: I have added a border-radius of 50% to your images because I assume you want them to be round. If you want to use 100px you can change it back.
Css:
#values img{
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
width: 80%;
}
#val1 {
background-color: #792c24;
}
#val2 {
background-color: #4f5e6d;
}
#val3 {
background-color: #665e25;
}
Html:
<div class="container" id="values">
<h3 class="fancy">Values</h3>
<div class="row text-center">
<div class="col-sm-4">
<h4>Independent</h4>
<img id="val1" src="http://placehold.it/300x300">
</div>
<div class="col-sm-4">
<h4>Team Player</h4>
<img id="val2" src="http://placehold.it/300x300">
</div>
<div class="col-sm-4">
<h4>Dedicate</h4>
<img id="val3" src="http://placehold.it/300x300">
</div>
</div>
</div>
I am curious as to what I have to change to the following jsbin (see code below) in order to get a couple things to happen:
The 4 images should be in the centre of the page, in stead they are off a bit.
The 4 images should sit beside each other (not over lapping like they are) and they should stay beside each other, with no gaps developing, above 1920px. They should then follow bootstrap conventions when the screen shrinks. (This leads to point 3)
When the screen shrinks bootstrap conventions should be followed for how rows and columns and containers behave. Images should shrink down appropriately.
Currently what I have is my attempt. I can get them beside each other, with gaps as the screen size gets larger or over lapping at 1920px.
When the screen shrinks, things go hey wire. There should be 4 images beside each other with the same width of gap on either side of the first and last image, they should stay beside each other regardless of the screen size (going up) and then follow bootstrap conventions when the screen shrinks, images should also shrink to fit on mobile devices.
Html
<div id="wrap">
<div class="container">
<div class="container image-links">
<div class="row-helper">
<div class="row text-center">
<div class="col-md-3">
<img src="http://placehold.it/355x354" />
</div>
<div class="col-md-3">
<img src="http://placehold.it/355x354" />
</div>
<div class="col-md-3">
<img src="http://placehold.it/355x354" />
</div>
<div class="col-md-3">
<img src="http://placehold.it/355x354" />
</div>
</div>
</div>
</div>
</div>
</div>
Css
-- This is compiled down from sass.
#wrap .container .image-links {
width: 100%;
}
#wrap .container .image-links .row-helper {
margin-left: 245px;
}
#wrap .container .image-links .row-helper .row .col-md-3 {
margin-left: -2px;
margin-right: -62px;
}
I guess this is what you want. Check here.
Well, the images need to be given a size so that they fill their containers and not overflow. This was the reason of their overlapping. So just gave them a width here.
.img{
width:100%;
}
So removed the css you gave for adjusting the margins.
And, for removing those gaps, just made padding as 0px as below.
#wrap .container .image-links .row-helper .row .col-md-3 {
padding:0px;
}