I'm trying to align multiple images in a single div element which is <nav_bar>. These images will act as navigation links to the different webpages on the website. The problem is, initially I was able to position the (home) image using values I put into the css. However, when I put the second image (computericon), it went behind the (home) image. TO fix this, I gave them position: inline; property. Now I can't move either of the images to my liking. They're just stuck there. No amount of padding or margin adjustment is making them move. The fix to this is surely easy but I'm quite new to website design and development and so I cannot seem to get around this issue. Any sort of help would be greatly appreciated.
Thank You.
Here's the html code:
<div id = "nav_bar">
<img id= "home" src= "home.png" height= "50px" width= "70px">
<img id= "pc" src= "computericon.png" height= "50px" width= "70px">
</div>
And here's the CSS code:
#home {
left: 188px;
position: inline;
}
#MAIN_CONTENT_CONTAINER {
padding-top: 20px;
}
#nav_bar {
height: 60px;
background-color: #3c3c3c;
margin-left: 10px;
}
#home:hover {
background-color: #b4e1cf;
position: inline;
}
#computericon {
left: 80px;
position: inline;
}
Image is attached.The two icons are just stuck there.
Try:
position: relative;
float: left;
Add div with style display:block;clear:both right after these images (to clear floats).
Remove the left property.
There is no such thing as position: inline;.
You should use position: relative; but then the left coordinate will count from the box-side of the previous element.
Depending on what you need to achieve, it may be better to use
display: inline-block;
vertical-align: middle;
on them, use only margins or paddings and forget left and such.
I think that one of your problems is that you were calling your second image with the wrong id. I changed the id to what you were calling it as in the css and then added a class to both of the nav items. Is this what you were looking for?
#MAIN_CONTENT_CONTAINER {
padding-top: 20px;
}
#nav_bar {
height: 60px;
background-color: #3c3c3c;
margin-left: 10px;
}
.navItem {
margin-left: 20px;
margin-top: 5px
}
.navItem:hover {
background-color: #b4e1cf;
}
<div id = "nav_bar">
<img id="home" class="navItem" src= "home.png" height= "50px" width= "70px">
<img id="computericon" class="navItem" src= "computericon.png" height= "50px" width= "70px">
</div>
Hope this helped!
First off, it's always a good idea when you're asking something to include a JSFiddle instead of just pasting the whole code in the answer. I did it for you and took the liberty of changing the images to better show the result: https://jsfiddle.net/2fjg6g3r/
The right choice would be inline-block, what I used in the fiddle.
#nav_bar > img {
display: inline-block;
height: 100%;
width: auto;
margin-right: 5px;
}
I also noticed you're selecting a single element at a time, so I'd suggest taking a look at more CSS selectors to make your code cleaner and less repetitive.
Related
I have shop on Prestashop 1.6. I created a third view in product list. With one thing, I can't handle by myself. When You move cursor over image (in third view), it display next to it with large size and this is ok. How can I move this image a little bit more to right. If I use margin-left or padding-left, image is flashes. I hope You know what I mean.
<div class="left image">
<a href="#">
<img class="replace-2x img-responsive" src="/1-home_default/faded-short-sleeve-tshirts.jpg" width="250" height="250"></a></div>
.left {
float: left;
margin-left: 10px;
}
.img-responsive {
display: block;
max-width: 100%;
height: auto;
}
.image{
width:32px;
height:32px;
}
.image a:hover img{
display: block;
position: absolute;
z-index: 999;
}
Thanks for help.
Kind regards
Try using an invisible border on the image that loads.
border-left: 10px transparent;
This should give you the space you need, and stop the flashing that occurs when using margin. However the image will still show when hovering this border. It really depends what outcome you desire.
I'm writing to ask if there is any simpler method to do exactly the same thing like in this code:
jsfiddle.net/t9euvoe9/5/
I'm trying to do friends list. I noticed that simple using of built borders isn't enough here. I found some way which in EVERY friend is divided by custom single line (botttom).
I want lines to dissapear when I'm hovering friend (BOTTOM line of PREVIOUS friend, and BOTTOM line of actually HOVERING friend).
Also, these paddings are not working properly right now (when hovering).
edit:
I want to create friends list. Actually I have <div> which contains all another <div class="friend">. I want to separate every <div class="friend"> with a single line, which will be hidden after hoovering friend element
The way I'm actually doing this:
Position of <div class="friend"> element is set to relative. I'm creative custom border line using:before and :after pseudo-selectors.
When some <div class="friend"> is hovered, I'm hiding this border using display:none. This hides bottom border. To hide top border I'm moving <div class="friend"> little bit higher by setting margin-top: 1% and padding-top: 6% to overcome this move.
Example:
.friend {
position: relative;
width: 100px;
padding-top: 5%;
padding-bottom: 5%;
}
.friend:hover {
margin-top: -1%;
padding-top: 6%;
height: calc(100% + 1px);
background-color: red;
}
.friend:hover:after {
display:none;
}
.friend img {
vertical-align: middle;
}
.friend:first-child:before {
content: '';
display: block;
width: 100%;
left: 10%;
height: 1px;
position: absolute;
background-color: #ccc;
top: 0;
}
.friend:after {
content: '';
display: block;
width: 100%;
left: 10%;
height: 1px;
position: absolute;
background-color: #ccc;
bottom: 0;
}
<div class="friend">
<img class="img-circle" src="http://www.zerohedge.com/sites/default/files/pictures/picture-197359.gif" alt="" width="40" height="40">
<span class="name">Ania</span>
</div>
<div class="friend">
<img class="img-circle" src="http://www.zerohedge.com/sites/default/files/pictures/picture-197359.gif" alt="" width="40" height="40">
<span class="name">Ania</span>
</div>
Although this question could definetely be better (see the comment BSMP left), I gave a shot at answering.
http://jsfiddle.net/tw32r0L6/
What I did was remove a bunch of extra stuff, and simplify a little. You should really be using the CSS border property, because it is the built in way of doing something like this. Using pseudo-elements isn't required for this basic of a task.
So after removing the CSS you had for pseudo elements, you can see that I added this:
.friend:not(:first-of-type){
border-top: 2px #000 solid;
}
.friend:hover + .friend, .friend:hover{
border-top-color: transparent;
}
The first part selects the .friend divs, that are not the first one, as you can see by :not(:first-of-type). You can read more about CSS pseudo-classes here. You can see that the only style I added was a top border.
Then the second selector hides the top border from all .friend divs that are hovered, and the first .friend div following one that was hovered. This is done using the + selector which selects the next sibling of an element.
The last thing I did was remove some stuff you had in the other .friend:hover part, because that wasn't needed after these fixes.
I wrote picture width in property class to put price 15 pixels from the right edge of the picture.
Now right works correctly, but if I remove it, price will be placed at 15px from the right edge of page..
html:
<div class = "property">
<img src = "http://preview.byaviators.com/template/realia/assets/img/tmp/property-small-1.png"/>
<div class = "type">House</div>
<div class = "price">90 000 €</div>
</div>
css:
.property {
position: relative;
width: 270px;
}
.price {
position: absolute;
bottom: 15px;
right: 15px;
}
Can you suggest a way, in which I will avoid writing of picture width and right will work as it should be? Thanks, p.s. code
You can try this https://jsfiddle.net/ht80y82y/1/
CSS
.property {
display: inline-block;
position: relative;
width: auto;
}
div element(.property) has display:block; by default. It means the element width will be inherited from its parent. However, you can solve your problem by giving display:inline-block; and so on.
Jsfiddle
Or change div to span.
Jsfiddle
I'm trying to learn HTML/CSS and JavaScript+jQuery by using Codeacademy and working on my own little project to practice. However, I am stuck with a very simple problem:
I want a parent div to be displayed across the entire page. I can do this successfully (see fiddler). When I resize the browser screen, however; my parent div no longer fits across the entire page, which causes its right most child div to be displayed outside of the parent div (see fiddler). Basically, I want my parent div to always wrap its child divs, and to always be displayed across the entire screen.
Fiddler Links:
Link 1
Link 2
Relevant HTML:
<div id="topnav">
<a id="logo" class="navlink clearfix">DreamTeam</a>
<a id="logo" class="navlink clearfix">Strikers</a>
<a id="logo" class="navlink clearfix">Midfielders</a>
<a id="logo" class="navlink clearfix"><div class="navlink clearfix">Defenders</a>
<a id="logo" class="navlink clearfix">Goalkeepers</a>
</div>
Relevant CSS:
/* ID FOR PARENT DIV */
#topnav {
position: relative;
background-color: #EDEDED;
height: 70px;
width: 100%;
white-space: nowrap;
}
#logo {
width: 300px;
font-weight: bold;
margin-left: 5px;
font-size: 28px;
height: auto;
}
#lastlink {
border: none;
}
/* CLASS FOR CHILD DIVS */
.navlink {
position: relative;
font-family: Century Gothic;
height: auto;
font-size: 24px;
text-align: left;
line-height: 65px;
width: 175px;
border-right: 1px solid #bdbdbd;
}
Any help would be appreciated. I've gone through many Google searches and other stackoverflow posts, but nothing seems to work for me unless I completely missed an appropriate post. Using things like "overflow: hidden" or creating a wrapper div didn't really work for me. Thank you in advance for any suggestions. It would be great if anyone could point me to an appropriate post that I might have missed too.
How about get rid of the div tag inside a tag. Because you can use class with a tag.
Look at the following example provided by StackOverflow user starx
CSS
a.divlink {
display:block;
width:500px;
height:500px;
float:left;
}
HTML
<div>
<a class="divlink" href="yourlink.html">
The text or elements inside the elements
</a>
<a class="divlink" href="yourlink2.html">
Another text or element
</a>
</div>
Click here for more details
I managed to find a solution to my problem. The problem was not my invalid markup; it was actually the CSS for my #topnav ID. Here's how I changed that ID to get the result I wanted:
#topnav {
background-color: #EDEDED;
height: 50px;
min-width: 1050px;
position: absolute;
left: 0;
right: 0;
top: 0;
}
The key changes are below the height property.
I have images that are also links, coded like this:
<img src="pages/squirrely.png" />
They work fine, but I want it to be a link, only if you click the general middle of the photo. If you click on the outer regions of the image, I don't want any linking to happen.
I tried changing the width and height of the lin, but it didn't work. My css is:
#magazine a {
width: 100px;
height: 100px;
border: 5px solid #fff;
}
I would not work with an imagemap in this case, but do something like this:
The HTML:
<div class='container'>
<img .../>
<a ... ></a>
</div>
The CSS:
.container {
position: relative;
}
.container img {
width: 100px;
height: 100px;
border: 5px solid #fff;
}
.container a {
display: block;
width: 60px;
height: 60px;
position: absolute;
top: 25px;
left: 25px;
}
Basicly this puts your link on top of your image. I find it much easier to play with the positioning and the dimensions of the link this way. (I did not test the code, but i think it should work)
There are several web applications that'll allow you to choose the coordinates for the mapping. I've tried this one with great success:
http://www.maschek.hu/imagemap/imgmap
I hope this helps you with your project!