I have the following fiddle - here I am trying to align the 'click' and <h3> in the same line
I am facing 2 issues here -
when the h3 content is too long it is pushing 'click' -
and on click when it shows the content it is moving sideways. Any ideas on how to acheive this - new to CSS.
Tried giving display:inline to <h3> but that did not help in this scenario.
http://jsfiddle.net/92spd439/
$('#ttt a#iimarrow').css({
cursor: "pointer"
}).on('click', function() {
$(this).next('ul').toggle();
});
ul {
display: none;
}
#ttt {
float: right;
}
a#iimarrow {
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<h3><a> tdhfkjshdfhsdfsdflkshdlflskfjl</a><h3>
<span id="ttt">
<a id="iimarrow">click</a>
<ul>
<li>12</li>
<li>13</li>
</ul>
</span>
The problem here is actually the h3 element which defaults to a display: block;. So if you just remove a#iimarrow{display:inline-block;} (since a tags default to display: inline; as #mikelt21 pointed out) and add the CSS below, then your problem will be fixed.
h3 {
display: inline;
}
JSFiddle
I believe something like this might be what you are looking for.
What I did was add float:left to the first <a>.
As following:
<h3>
<a style="float:left"> tdhfkjshdfhsdfsdflkshdlflskfjl</a>
</h3>
You could achieve this by placing the right-floated <a> element ahead of the <h3> in the HTML:
$('#ttt a#iimarrow').css({
cursor: "pointer"
}).on('click', function() {
$(this).next('ul').toggle();
});
ul {
display: none;
}
#ttt {
float: right;
}
a#iimarrow {
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="ttt"><a id="iimarrow">click</a>
<ul>
<li>12</li>
<li>13</li>
</ul>
</div>
<h3><a>tdhfkjshdfhsdfsdflkshdlflskfjl</a><h3>
Note that a <span> cannot contain the block-level <ul> element, so I've used a <div> in place of that, otherwise the only change is rearranging so the <div> (#ttt) comes ahead of the <h3>.
Related
I'm new to BEM and i'm trying to implement this:
.details-header {
margin-top: 10px;
padding-bottom: 0;
display: block;
&__heading-panel {
margin-top: 10px;
}
&__heading {
display: inline-block;
}
}
Defining the same margin-top inside details-header__heading-panel is wrong, i know, but because there is element between details-header and details-header__heading-panel, i need this margin, how do i solve this, and also keep the code DRY?
EDIT: Here is the html:
<div class="details-header">
<div>Something</div>
<div class="details-header__heading-panel">
<h1 class="details-header__heading">
<span>something</span>
</h1>
<a>
Link
</a>
</div>
</div>
I need margin between that div between details-header and details-header__heading-panel
There's nothing wrong with defining the same margin-top inside details-header and details-header__heading-panel. Just keep going with your original code.
It's not copy-paste but just coincidence.
I have this web page
http://hashgurus.com/htmlpage7.html which lists items in
<li> </li>
vertically. But I need it to display horizontally. Which element in css should I use to display items horizontally rather than vertically?
this is the code:
<ul class="jobs">
<li>
<img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />
<div class="company">desc1</div></li>
<li>
<img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />
<div class="company">desc2</div></li>
</ul>
demo page:
http://hashgurus.com/htmlpage7.html
.jobs {
list-style-type: none;
padding:0;
margin:0;
}
.jobs > li {
display: inline-block;
}
Something like that perhaps?
You can make your list elements align horizontally by specifying the display property with inline.
An example of this below:
li{display:inline}
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
use
li {
float: left;
}
for floating the list elements to the left.
You can use float but you need to clear after it or will have layout problems.
Example :
.jobs {
list-style: none;
}
.jobs li {
float: left;
margin-left: 12px;
}
.jobs::after {
content: "";
display: table;
clear: both;
}
<ul class="jobs">
<li>
<img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />
<div class="company">desc1</div>
</li>
<li>
<img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />
<div class="company">desc2</div>
</li>
</ul>
You should not use floats for layout unless absolutely necessary. They are horribly buggy. Floats should be used for removing an element from the "normal" document flow while allowing content to flow around the element. A good example would be an image in a paragraph.
Instead set the font size: 0 on the container to remove unwanted white space between items, and white-space: nowrap to keep them inline when the container is bigger than the window. Reset the font and white-space in the child and set to display: inline-block.
Using inline-block instead of inline allows you to change the width and height of each element.
Note if you set the font for html to reference that font-size later you can use rem units which refer to the font size of the root element. In this example I use 1rem to reset the font size to that of the root element.
ul {
font-size: 0;
white-space: nowrap;
}
li {
display: inline-block;
font-size: 1rem;
white-space: initial;
}
You could use a table:
<table>
<tr>
<td>
<img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />
<div class="company">desc1</div></li>
</td>
<td>
<img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />
<div class="company">desc2</div></li>
</td>
</tr>
</table>
Following is the html structure, that is repeating inside my html page.
<article class="tweet-inner">
<div class="tweet">
<div class="text">
<p>Coming down! Time for Croation BBQ </p>
</div>
<p class="last">
<span class="pull-right">
<small> Hello this is first text </small>
<small> Hello this is second text </small>
</span>
</p>
</div>
</article>
The above is one unit of repeating structure inside my HTML.
The functionality I want is, when you hover over the tweet text, .tweet .text p then the content of .last should show.
I did the following :
.last{
display: none;
}
.tweet .text p:hover .last{
display: block;
}
Two doubts :
You should be able to see the .last of only the element upon which you have hovered.
The above is not working, the fiddle is http://jsfiddle.net/EymLT/
Thanks!
Your CSS selector is incorrect. Firstly .last is not a child of .text, and the p element cannot be hovered because it is invisble. Try this:
.tweet:hover .last{
display : block;
}
Updated fiddle
Replace your last style with this:
.tweet .text:hover + .last{
display : block;
}
You can use ~ in CSS
DEMO http://jsfiddle.net/kevinPHPkevin/EymLT/4/
.last{
display:none;
}
.text:hover ~ .last{
display : block;
}
If you replace my ~ with > it will be more browser compatable. The > ensures only the child is seleted so you can use a parent div as the hover target.
.last{
display:none;
}
.tweet:hover > .last{
display : block;
}
i have 2 images.My constraint is that I have to put a new div after the end of the 1st image.But they come on different lines.I googled a lot and found that float:left does the trick
I am already using it,but still they are coming in different lines.I dont know where I am going wrong.
Jsfiddle
span.tab {
padding: 0 50px; /* Or desired space*/
}
.span.tab {
display: inline-block;
float:left;
}
#div23 {
display: inline-block;
float: left;
}
#topdiv1 {
display: inline-block;
float: left;
}
#topdiv3 {
display: inline-block;
float:left;
}
html
<br />
<div id='topdiv1'><div id="widget1" class="sticky1">
<div id='topdiv3'>
<img src="https://lh3.googleusercontent.com/-TrGnsESMpDc/AAAAAAAAAAI/AAAAAAAAAAA/lcUg6MaCxmg/photo.jpg?sz=50" />
<div id='div23'>
<span class="tab"></span>
<img src='https://lh3.googleusercontent.com/-TrGnsESMpDc/AAAAAAAAAAI/AAAAAAAAAAA/lcUg6MaCxmg/photo.jpg?sz=50'/>
</div> </div>
Please help.
You don't apply the float to the parent container. You apply the float to the child elements:
#topdiv3 > * {
float:left;
}
http://jsfiddle.net/samliew/b9TWE/1/
If you want to remove the space between the images, remove the span.
http://jsfiddle.net/b9TWE/2/ this fixes it, you just need to have the <a> containing the first image to float
#topdiv3 > a{
float: left;
}
More on how floats work (great article)
By floating the first <a> containing the image you remove it from the regular document flow. the <div> containing the seconds image will resume the normal flow and position itself next to the <a>
Your topdiv3 must be closed before div div23.
<div id='topdiv1'>
<div id="widget1" class="sticky1">
<div id='topdiv3'>
<img src="https://lh3.googleusercontent.com/-TrGnsESMpDc/AAAAAAAAAAI/AAAAAAAAAAA/lcUg6MaCxmg/photo.jpg?sz=50" />
</div>
<div id='div23'>
<img src='https://lh3.googleusercontent.com/-TrGnsESMpDc/AAAAAAAAAAI/AAAAAAAAAAA/lcUg6MaCxmg/photo.jpg?sz=50'/>
</div>
</div>
</div>
http://jsfiddle.net/arunu/8gvvr/
I've tested it on firefox and it worked the way you did.
But anyway, your html markup is a little bit confuse, doesn´t it?
I have created CSS onHover popup as given here. but problem is, User should be able to click the Register link in the example. here, Popup disappears as I move the mouse aware form the link.
Can anyone tell how it could be achieved ?
HTML:
<div class="how f-left">
<h7>How does this work?</h7>
<div class="how-works bubble-outer">
<div class="navigation-up-arrow"></div>
<div class="body">
<h4>How It Works</h4>
<ol class="bubble-inner">
<li>Tell Us What's Wrong </li>
<li class=""> Register to Get Quotes from Local Shopshere </li>
<li class=" bold-txt ">Call Shop / Get Vehicle Serviced </li>
<li>Get Cash Back </li>
</ol>
</div>
</div>
</div>
Below CSS is used for onHover PopUp:
.how h7:hover + .how-works {
display: block;
}
You can make it display on hovering the parent (.how), not just its preceding sibling. Hovering the parent happens when you are hovering any of its descendants (the link, .how-works, any of the children of .how-works).
To do this, change:
.how h7:hover + .how-works {
display: block;
}
to:
.how:hover .how-works {
display: block;
}
DEMO
Also, if you want to make it work for touchscreens (no hover there), you could adjust a bit your HTML. Change
<h7>How does this work?</h7>
to
<a class="how-it-works" href="#" tabindex="1"><h7>How does this work?</h7></a>
and add this to the CSS as well:
.how-it-works:focus + .how-works {
display: block;
}
DEMO
Add this to your CSS:
.how-works:hover {
display: block;
}
Modified version of your demo: little link.
Here is a working example link.
Put
.how:hover .how-works {
display: block;
}
instead of
.how h7:hover + .how-works {
display: block;
}
and add position: relative; top: 0px; css properties to .how .how-works.bubble-outer{ ... }