I'm tyring to put an 'edit' link on the same line as a heading, off the right of the page and the link text aligned with the bottom of the heading text. I want something like:
want
My first attempt was:
<div>
<div style="float: left; width:600px;background-color: red">
<h1>Something</h1>
</div>
<div style="float: left; background-color: yellow ">
<a href=#>Edit</a>
</div>
</div>
but that gave me:
got
I've tried quite a few things to get the 'Edit' to be aligned along the bottom with the 'Something', but none seem to work.
Has anyone got any suggestions? Is wrapping everything in divs like this the wrong way to go about it?
Thanks in advance for any help.
Edit - arghh, sorry I mixed the two images the wrong way round. The text was correct though, I want the link text to be bottom aligned with the heading text. Fixed now.
Update
Thanks to those who made suggestions and comments.
I've come up with with a few more possibilities (although I realise in stepping back and asking if there's a better approach, in some options I've consequently relaxed the original spec somewhat):
Solution 1: similar to chipcullen's suggestion, but set width in outer div. This has the advantage of bringing the link to within the 600px width:
<div style="position: relative; width: 600px">
<h1>Solution 1</h1>
<a style="position: absolute; bottom: 0; right: 0;href="#">Edit</a>
</div><br/>
Solution 2: as with (1) but, but use my own class rather than H1, and allow the link to float right. This has the advantage (?) of not having to use position: absolute, but you still
need to set margin-top.
<div style="width: 600px">
<span class="myHeader">Solution 2</span>
<a style="float: right; margin-top:14px;" href="#">Edit</a>
</div><br/>
Solution 3: as with (2) but use h1 and override the display attribute. Has the advantage of making using of other attributes defined elsewhere on h1:
<div style="width: 600px">
<h1 style="display:inline;">Solution 3</h1>
<a style="float: right; margin-top:14px;" href="#">Edit</a>
</div><br/>
Solution 4: nest the link element in the h1, and style the link, in this case by specifying a
Twitter Bootstrap button:
<div style="width: 600px">
<h1>Solution 4
<a class="btn" style="margin-top:4px;float: right;" href="#">Edit</a>
</h1>
</div>
They all seem to work, has anyone got any thoughts on which is preferable? Solutions 2 - 4 I guess are a bit more fragile as the hard-wired margin-top setting depends on the h1 line height, but at the same time they feel a bit more concise to me.
You probably don't need the all of the div's. If you really want to get this to behave, you could always use position: absolute;
Markup:
<header>
<h1>Something</h1>
<a class="edit_link" href="#">Edit</a>
</header>
CSS:
header {
position: relative;
}
h1 {
width: 600px;
}
.edit_link {
position: absolute;
top: 0;
right: 0;
}
I'm not saying it's the only right way, but a way.
Try adding this css to the edit float
{
margin:0px;
padding:0px;
border:0px;
}
You could also use two classes for your <div> tag. such as #header and #header-right. It's what I usually use.
Example:
#header {
width: 98%;
min-width: 750px;
height : 45px;
margin : 0 auto;
padding-left: 1%;
padding-right: 1%;
padding-bottom : 4px;
color : #ffffff;
background: #999999;
border-bottom: 1px solid #000000;
}
#header-right {
padding-top: 10px;
padding-right: 10px;
float: right;
}
HTML:
<div id="header">
<h1 >MySite.com</h1>
<p>A site for me. Not you.</p>
<div id="header-right">
<p>Because who wants to share a website...</p>
</div>
</div>
This worked for me:
HTML:
<div class="header">
<h1>Title</h1>
<div>Edit</div>
</div>
CSS:
.header *{
display: inline-block;
}
.header {
text-align: left;
}
You could also set widths etc.
A much simpler way of doing it is:
<div>
<a style="float:right; clear:left" href=#>Edit</a>
<h1>Something</h1>
</div>
Be sure to put the heading after the link, so the link doesn't disappear into the html below that.
Related
I've been looking all over for an answer to this but I can't find a fix anywhere. I'm just trying to move the h1 tag right over top of the icons but whenever I use margin-top or padding-top to move the h1 down the page it moves the column down as well. I put borders around all of the columns around there to see if maybe the borders were touching but that was no help. Is there like some sort of default padding around h1's or columns that you can't see?
Here is a link to my codepen: https://codepen.io/4eller/pen/eVmxeM
HTML:
<hr width="35%">
<div class="container maincon2">
<h1 class="wwd">Social Media Has Never Been Easier</h1>
<hr class="hr1">
<h1 class="whatwedo">What makes us stand out from the rest</h1>
<div class="row topicons">
<div class="col-md-4 maintab1">
<img src="images/graph.png" class="barimg">
<hr width="50%" id="hr2">
</div>
<div class="col-md-4 maintab2">
<img src="images/piggy-bank.png" class="pigimg">
<hr width="50%" id="hr2">
</div>
<div class="col-md-4 maintab3">
<img src="images/support.png" class="supportimg">
<hr width="50%" id="hr2">
</div>
</div>
</div>
</div>
</div>
<div class="container maincon3">
<div class="row">
<div class="col-lg-12 mediumcon2">
<hr class="hrgreen">
CSS:
.maincon2 {
width: 100%;
height: 500px;
background: #424242;
margin-left: auto;
margin-right: auto;
margin-top: 100px;
border: 1px solid orange;
}
.topicons {
border: 1px solid red;
margin-top: 70px;
height: 250px;
table-layout: fixed;
}
If I understand correctly what you want (not really 100% clear), you can apply position: relative to that tag and use top to move it down without affecting anything else, since position: relative plus position settings cause an element to be moved in relation to its original (static) position, but elements before and after it will remain were they are:
h1.whatwedo {
position: relative;
top:30px;
}
Changed codepen: https://codepen.io/anon/pen/MQYRKY
Give the h1 tag position:absolute; and then move it left with left:200px(replace 200 with whatever number you want)
The reason why when using margin, padding or position:relative, it will move other elements, is because then they are considered part of the "flow" of the page, meaning they will interact with and bump other elements around. position:absolute, removes the target element from the flow of the page, thus allowing you to put it wherever without moving other elements.
So to start this off I would like to just say that any help is appreciated, I'm not looking for the entire code laid out for me. I have tried to create this but fail every time as something disappears of it breaks the entire layout of the page. I am fairly new to programming but I have a pretty good grasp of concepts and I'm open to learning new things.
I would like to create a top bar like in this website, with the logo and social icons. No search bar.
http://www.complex.com/
Thank you to anyone for any help
First, as a general tip: Whenever you see something you want to recreate, right click on it in chrome and select "inspect element". Then you can look at the css used to create it.
To have social icons up like your example site, they've simple floated them right.
So HTML:
<div class="header">
<div class="leftThing">
</div>
<div class="rightThing">
</div>
</div>
CSS:
.leftThing { float:left;}
.rightThing { float:right;}
The float will cause the element to go as far to the side you select as it can, then sit there. Here is a good css tricks article on the concept: http://css-tricks.com/all-about-floats/
I made you a litte JS-Fiddle to show you how to fix the header on top of the screen when you scroll down. Hope it helps a bit!
HTML:
<div id="WebContent" class="Content">
<img src='http://apod.nasa.gov/apod/image/9712/orionfull_jcc_big.jpg'></img>
</div>
CSS:
.Header{
top: 0px;
left: 0px;
min-height: 50px;
max-height: 50px;
min-width: 1024px;
background-color: #2C2C2C;
color: white;
position: fixed;
}
.icon{
height: 50px;
}
.Content{
max-width: 300;
max-height: 300;
overflow-y: auto;
}
Fiddle: http://jsfiddle.net/wujood/pgqeLr7s/
Or you can just insert a fixed position to your header:
<div class="header" style="position:fixed">
<div class="leftThing">
</div>
<div class="rightThing">
</div>
</div>
Apply either CSS float: left or display: inline-block to your elements.
http://jsfiddle.net/njoh7x73/
CSS code
.menu {
background-color: #333;
}
.menu div.item {
width: 64px;
height: 16px;
background-color: #888;
}
.menu .item {
float: left;
padding: 10px;
margin: 5px;
}
.menu .item:hover {
background-color: #555;
}
HTML code
<div class="menu">
<a class="item" href="#">LINK</a>
<div class="item"></div>
<a class="item" href="#">LINK</a>
<div class="item"></div>
<div style="clear:both"></div>
</div
If you use this approach (floating elements), don't forget to clear them.
So I'm trying to make a user comment thing in HTML. I would like it to look similar to vimeo's comments, with the user icon and the text aligned to the right of it. Here is my markup(using a bootstrap container but i dont really think that is the problem):
<div class="comment">
<img src="{{comment.poster.profile.avatar.url}}" alt="...">
<span>poster name time</span>
<p>comment body</p>
</div>
and my CSS:
.comment{
margin-left: auto;
margin-right: auto;
margin-bottom: 10px;
text-align: left;
width: 800px;
padding: 10px;
background-color: #secondary;
img{
width: 55px;
height: 55px;
vertical-align: top;
}
The <span>poster name time</span> aligns with the top right of the image just how I want it to, but the body text ends up under the image, not under the info like where I want it to be. Here is an image of it, arrow is pointing where I want the text to go:
Any idea how I should do this? I'm real bad at aligning things, so sorry if this is a simple mistake. Thanks.
Here is how you canc achieve this:
<div class="pic">
<img src="http://placekitten.com/100/100">
</div>
<div class="pic-meta">
<span>
poster name
time
</span>
<span class="comment">comment</span>
</div>
and css:
.pic, .pic-meta {
float: left;
}
.comment {
display: block;
}
http://jsfiddle.net/p4K7u/
Trying to float an image to the left of some text. The image needs to be linked to something. The link, however, is only working on parts of the image.
See code here: http://jsfiddle.net/JaUXp/
#rightImg {
float: right;
width: 45%;
margin: 0 0 15px 15px;
}
#leftTxt {
position: relative;
}
<div id="rightImg">
<a href="http://google.com">
<img src="myimg.jpg" />
</a>
</div>
<div id="leftTxt">
<p>my text</p>
</div>
The reason my left DIV had a position property set to "relative" was because of normalize.css. My solution was to set the position property on the DIV to "static".
you maybe looking for something as follows:
http://jsfiddle.net/DJruJ/
HTML
<div id="container">
<a href="http://google.com" target="_new">
<img src="http://image.yaymicro.com/rz_512x512/0/4fd/pile-from-dominoes-on-black-background-4fd987.jpg" />
</a>
</div>
<div id="description">
<p>One late author did indeed venture to assert, and to prove, that the tendency to move, the power or force that produces actual motion, is </p>
</div>
css
#container {
float: left;
width: 45%;
margin: 0 10px 15px 0;
}
#container img{
width:100%;
}
#description {
position: relative;
float:left;
width:50%;
}
you are using "rightImg" and "leftTxt" as element id's. Its not recomended to use such kind of naming conventions because in future your left text may become right text and vice versa your image. in that case it might be a bit confusing
hope this helps
I'm using a table for the footer of my web page. I really don't know much about tables because I've always used CSS. The following is the only table I've ever made. It seems to work in Opera, Chrome, and Firefox, but everything goes to the left in IE. I'm not sure what I'm doing wrong with the table because I don't know much about tables. Here is the HTML:
<div id="framecontentBottom">
<div id="container">
<div id="row">
<div id="left">
<!-- Counter Code START --><img src="http://www.e-zeeinternet.com/count.php?page=760915&style=LED_g&nbdigits=4&reloads=1" alt="Web Counter" border="0" ><br>Page Views<!-- Counter Code END -->
</div>
<div id="middle">
Contact me at jacksterdavis<img src="images/#white.png">gmail.com
</div>
<div id="right">
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4f302421558e3fc2"></script>
<!-- AddThis Button END -->
</div>
</div>
<div id="row">
<div id="left">
</div>
<div id="middle">
<p>The internet is the printing press of the 21'st century.</p>
</div>
<div id="right">
</div>
</div>
And here is the CSS:
#container {
display: table;
width: 100%;
}
#row {
display: table-row;
}
#middle {
width:50%;
text-align:center;
display: table-cell;
}
}
#left
{
width:25%;
text-align:left;
display: table-cell;
}
#right
{
width:25%;
text-align:right;
display: table-cell;
padding: 5px;
}
#quote
{
text-align:center;
width:100%;
}
#logoBtm
{
align:middle;
text-align:center;
}
#logoBtmLeft
{
align:left;
}
#logoBtmRight
{
align:right;
}
#framecontentBottom{
clear: both;
position: relative;
z-index: 10;
margin-top: -3em;
top: auto;
bottom: 0;
height: 80px; /*Height of bottom frame div*/
overflow: hidden; /*Disable scrollbars. Set to "scroll" to enable*/
background-color: #585858;
color: white;
width: 100%;
}
If you point out everything wrong with my table it's appreciated, thanks. A CSS fix would be the best but if the HTML must be edited it's fine.
the problem most likely lies in the fact that you have two divs with the same id. use classes for row instead.removed for the comfort of others. This line doesnt help the solution at hand.
also, in referring to your comment, ie 7 does not support table display CSS.
http://caniuse.com/#search=table-cell
use a combination of inline block or float. but beware, as inline block has its own issues with ie7
http://flipc.blogspot.com/2009/02/damn-ie7-and-inline-block.html
Here is a working, valid, example.
http://jsfiddle.net/mRHnW/2/
A couple changes: Ive styled every div inside of .row so that it gets applied once (and if it needs to be fixed, it can be, in one place. Even in CSS, it needs to be DRY.
I removed the margin-top from the #frameContentBottom selector because it was screwing with jsfiddle giving me visible results. Feel free to re-instate it if its important to your layout.
I adjusted the width of your 'columns' to be slightly less than 100%, because you've also included padding. The way the CSS Box Model as specified by W3C works is that the width declaration does not include padding, border, and margin. Thus, if you're creating a 100% div, and want 5px padding, then you need to specify less than 100% to get the padding within the 100% confines.
On a sufficiently wide screen (something bigger than jsfiddle default panes), your footer should look about what you expect.