• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

responsive css/html float left and mobile

Hello,

How do I get the buttons that are under the ask-a-nurse button on the attached screenshot (broken.png) to float left next to the nurse? Looking for 6 buttons to the right of the nurse.

Also, make sure it looks good on mobile.

Looking for html & css

<div id="nurseLinks">
<a href="http://www.idiaper.com/Ask-A-Nurse_ep_29.html"><img id="left-nurse1" alt="ask a nurse button" src="/assets/images/left-nurse2.jpg"></a>
<div id="iconDiv-nurse">
  <a href="http://www.idiaper.com/womens-diapers"><img alt="for women button" src="http://www.idiaper.com/assets/images/women-nurse2.jpg"></a><a 
  href="http://www.idiaper.com/Auto-Reorder_ep_43-1.html"><img alt="auto-reorder button button" src="http://www.idiaper.com/assets/images/auto-ship-nurse3.jpg"></a><a 
  href="http://www.idiaper.com/mens-diapers"><img alt="for men button" src="http://www.idiaper.com/assets/images/men-nurse.jpg"></a><a 
  href="http://www.idiaper.com/overnight-adult-diapers"><img alt="overnight products button" src="http://www.idiaper.com/assets/images/overnight-nurse2.jpg"></a><a 
  href="http://www.idiaper.com/adult-pullups"><img alt="pull ups button" src="http://www.idiaper.com/assets/images/pull-ups-nurse2.jpg"></a><a 
  href="http://www.idiaper.com/adult-cloth-diapers-briefs"><img alt="adult cloth diapers button" src="http://www.idiaper.com/assets/images/acd-nurse2.jpg"></a>
</div>
</div> 

Open in new window


#imgLinks-nurse {
text-align:center;
background-color:#3babdd;
}

#iconDiv-nurse {
padding-top: 0.8em;
float:left;
background-color:#59c8fd;
}

#left-nurse1
{
float:left;
width:29.2674%;
}

#iconDiv-nurse img{
width:23.2086%;
border:0;
margin-top:-5px;
flaot:left;
}

#iconDiv-nurse a{
border:0;
margin:0;
vertical-align:center;
}


@media screen and (max-width: 600px){
   #iconDiv-nurse img {width: 50.33%;}
   #leftnurse1 img {width: 100%;}
}

Open in new window

broken.png
0
weikelbob
Asked:
weikelbob
  • 7
  • 2
  • 2
  • +1
3 Solutions
 
Jan LouwerensSoftware EngineerCommented:
If you want the links to be on the left of the nurse, it sounds like you want the nurse to be floated right, and the anchors to be floated left.

Also check your spelling: "flaot:left;" will not work.
0
 
Juana VillaFront-end DeveloperCommented:
Hi Weikelbob,

The simplest solution will be to make them display: inline-block. Using display:inline-block will make your life easier when making it responsive.
Here is the sample I did with your code Try to resize the screen and notice how they behave.
0
 
weikelbobAuthor Commented:
Fixed my flaot to float

Didn't fix it.

Tried display:inline-block;

That didn't work either.

What could be going wrong?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
weikelbobAuthor Commented:
@Juana

If you put in

<div class="nurseImage">Here is the nurse</div>

<div id="nurseLinks">
<a href="http://www.idiaper.com/Ask-A-Nurse_ep_29.html"><img id="left-nurse1" alt="ask a nurse button" src="http://www.idiaper.com/assets/images/left-nurse2.jpg"></a>
<div id="iconDiv-nurse">
  <a href="http://www.idiaper.com/womens-diapers"><img alt="for women button" src="http://www.idiaper.com/assets/images/women-nurse2.jpg"></a><a 
  href="http://www.idiaper.com/Auto-Reorder_ep_43-1.html"><img alt="auto-reorder button button" src="http://www.idiaper.com/assets/images/auto-ship-nurse3.jpg"></a><a 
  href="http://www.idiaper.com/mens-diapers"><img alt="for men button" src="http://www.idiaper.com/assets/images/men-nurse.jpg"></a><a 
  href="http://www.idiaper.com/overnight-adult-diapers"><img alt="overnight products button" src="http://www.idiaper.com/assets/images/overnight-nurse2.jpg"></a><a 
  href="http://www.idiaper.com/adult-pullups"><img alt="pull ups button" src="http://www.idiaper.com/assets/images/pull-ups-nurse2.jpg"></a><a 
  href="http://www.idiaper.com/adult-cloth-diapers-briefs"><img alt="adult cloth diapers button" src="http://www.idiaper.com/assets/images/acd-nurse2.jpg"></a>
</div>
</div> 

Open in new window


into codepen,

then in at least some browsers it is still broken. I just fixed a broken link of yours.
0
 
Juana VillaFront-end DeveloperCommented:
What about this  note: I changed the html by adding a class to the <a> tag of the nurse image

This solution is using display flex in order to make the nurse image and the #iconDiv-nurse having the same height. I am making it two columns by using display: inline-block; and with one media query I am making it responsive.


I hope this solves your problem.
0
 
Slick812Commented:
greetings, , ,  As I tried to tell you can not use the  float: left;  all the time to get what you need. here is some code that works , PLEASE look at it and try to understand what the elements (<a> , <div> , <img> )  and the CSS are doing to work together to have your display be aligned and responsive.

<style>

#iconDiv-nurse {
background-color:#59c8fd;
text-align: center;
}

#nurseLinks {
display: inline-block;
width:68.8%;
verical-align: top;
background-color:#59c8fd;
}

#nurseLinks img{
width: 33.33%;
border:0;
}

#nurseLinks a{
border:0;
margin:0;
vertical-align:center;
}

#nurseImg {
display: inline-block;
verical-align: top;
width:31%;
}

#nurseImg img{
width:100%;
}

@media screen and (max-width: 600px){
   #nurseLinks {display: block; width: 100%;}
   #nurseImg {width: 283px;}
}
</style>

<div id="iconDiv-nurse">
<a id="nurseImg" href="http://www.idiaper.com/Ask-A-Nurse_ep_29.html"><img id="left-nurse1" alt="ask a nurse button" src="http://www.idiaper.com/assets/images/left-nurse2.jpg"></a><div id="nurseLinks">
  <a href="http://www.idiaper.com/womens-diapers"><img alt="for women button" src="http://www.idiaper.com/assets/images/women-nurse2.jpg"></a><a 
  href="http://www.idiaper.com/Auto-Reorder_ep_43-1.html"><img alt="auto-reorder button button" src="http://www.idiaper.com/assets/images/auto-ship-nurse3.jpg"></a><a 
  href="http://www.idiaper.com/mens-diapers"><img alt="for men button" src="http://www.idiaper.com/assets/images/men-nurse.jpg"></a><a 
  href="http://www.idiaper.com/overnight-adult-diapers"><img alt="overnight products button" src="http://www.idiaper.com/assets/images/overnight-nurse2.jpg"></a><a 
  href="http://www.idiaper.com/adult-pullups"><img alt="pull ups button" src="http://www.idiaper.com/assets/images/pull-ups-nurse2.jpg"></a><a 
  href="http://www.idiaper.com/adult-cloth-diapers-briefs"><img alt="adult cloth diapers button" src="http://www.idiaper.com/assets/images/acd-nurse2.jpg"></a>

</div> 
</div>

Open in new window

0
 
weikelbobAuthor Commented:
Juana,

It looks like your solution would have worked, sorry about that!

Slick812 - You are awesome! It looks great. Thank you so much.

Trying to understand your code. Why did display:inline-block fix it?

Thanks.
0
 
weikelbobAuthor Commented:
Wait, one problem,

When I put back the banner underneath, it looks like mobile

<div id="iconDiv-nurse">
<a id="nurseImg" href="http://www.idiaper.com/Ask-A-Nurse_ep_29.html"><img id="left-nurse1" alt="ask a nurse button" src="http://www.idiaper.com/assets/images/left-nurse2.jpg"></a>
<div id="nurseLinks">
  <a href="http://www.idiaper.com/womens-diapers"><img alt="for women button" src="http://www.idiaper.com/assets/images/women-nurse2.jpg"></a><a 
  href="http://www.idiaper.com/Auto-Reorder_ep_43-1.html"><img alt="auto-reorder button button" src="http://www.idiaper.com/assets/images/auto-ship-nurse3.jpg"></a><a 
  href="http://www.idiaper.com/mens-diapers"><img alt="for men button" src="http://www.idiaper.com/assets/images/men-nurse.jpg"></a><a 
  href="http://www.idiaper.com/overnight-adult-diapers"><img alt="overnight products button" src="http://www.idiaper.com/assets/images/overnight-nurse2.jpg"></a><a 
  href="http://www.idiaper.com/adult-pullups"><img alt="pull ups button" src="http://www.idiaper.com/assets/images/pull-ups-nurse2.jpg"></a><a 
  href="http://www.idiaper.com/adult-cloth-diapers-briefs"><img alt="adult cloth diapers button" src="http://www.idiaper.com/assets/images/acd-nurse2.jpg"></a>

</div> 
</div>

<br>
   <img class="responsive-left" alt="free shipping no tax" src="/assets/images/free-shipping-no-tax-peach.gif" /><br />

Open in new window

0
 
weikelbobAuthor Commented:
Got it, sorry about that.

Now to Slick :)

Why does display:inline-block fix it in this case?
0
 
Slick812Commented:
OK, The CSS for "inline-block" was based on how Images <img> are displayed and sized, as images can have a width and height, AND can be placed "side by side" without any "float", if they are side by side, and you need them on a new line, you have to place a <br> between them. In a <div> which as a display of "block", they always go to the next line, and can not be "side by side", UNLESS you change the CSS in some way. Web page builders 20 years ago (before the "inline-block" was available to use) found that they could "FOOL" the browser and get <div> to go side by side if they used the CSS of
     float: left;
so that's what was done for horizontal stacking, BUT It was a terrible way to do that, with many problems. about 10 years ago the CSS added the "inline-block" for display, which for most is a MUCH BETTER way to get some <div> to be side by side for  horizontal stacking.
HOWEVER
due to so many page builders doing "Copy and Paste" from OLD now out of date code tutorials and examples that use the OLD  float: left;  CSS, You still see many page code (especially Menus with <ul> <li>) that would be less code if the  "inline-block" was used instead.

= = = = = = = = = = =
you could have used the "float: left;" in your code work to get a view as you wanted, BUT Not anything like the way you tried to use it, you seemed to put float: left; on everything, which can not work.
The first <a> in your code had the Nurse <img> inside of it SO - - I gave the <a> a CSS of   display: inline-block;  because I needed to define it's width in CSS (you cant do CSS width effectively on an <a> without inline-block ), so now you can do CSS on the width and it's still goes side by side.

I gave the "nurseLinks" <div> the   "display: inline-block;"  so it will go side by side with the <a> before it, I used width on both as a % so the widths would change with the withds responsively,.
0
 
weikelbobAuthor Commented:
What an awesome coder you are.

I'll try to take these learnings into account from now on.

Thanks so much!

Bob
0
 
weikelbobAuthor Commented:
Thanks everyone!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 7
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now