text positioning in header section - html

is there any solution how to move text around in header section?
I have an <h1> tag whith email and I would like to move like 20% from left side of page and 50% form right side but all I can found is text-align:right,left, etc.
I add image so you can see on top of page there is this dark box whith email and view basket. How can I move that text the way I like?

There's a couple of ways you can position things like that...
Positioning
You are able to position elements using absolute and relative positioning, as seen in the example below, you can use position: relative for the parent container and position: absolute for the child and then use: top, right, bottom or left and define how far away you want the child element to be from its parent. As seen in my example below.
http://jsfiddle.net/8aL05tey/4/
header.header {
position: relative;
}
header.header h1 {
position: absolute;
left: 20%;
}
<header class="header">
<h1>
email#email.com
</h1>
</header>
Flexbox
You can also responsively position elements with flexbox. Flexbox can be relatively hard to understand if you've never messed around with it, there are plenty of SO questions with explanations in it. You can also read a bit about the properties here.
Floats
Alongside with positioning, you can float divs and other elements left and right using float: left and float: right. You can ready more about floats here. :)
There are plenty of options for what you want to achieve and no real "right" answer, it's about exploring what works for you!
Have a great day!

Related

Add image to the bottom of a adjustable height section

I am trying to created a CSS design on my web app. I am going for a banner that is flapping in the wind. I want the banner to expand/scroll its height so all text will be displayed on the banner but regardless of how tall the banner is, I want to add a ripped section of the banner at the bottom of it. The banner will be the same width in all cases.
Something like the example below (forgive the horrible Paint screenshot):
I can't seem to wrap my brain around how to accomplish this. Any of you smart people have any ideas?
First, I think it'd be helpful if you could provide an example of what you have so far. For example, what's your HTML & CSS for the adjustable-height divs, just without the image at the bottom? Easier to add onto that.
I believe the best way would be to add an image element at the bottom of your adjustable element (assuming it's a <div>). Position it as absolute, and set it relative to the bottom of its parent container. You may have to fiddle with it a bit to get it to work. Don't forget to also set the position of the parent to relative.
If you'd like to see the shoddiest example ever, go here: https://jsfiddle.net/c2ptfv8o/
Good further reading on position: https://developer.mozilla.org/en-US/docs/Web/CSS/position
Give the container element "position:relative" (to create a new positioning context) and some bottom padding (to make space for the image). Then you can either use a background image set to be at the bottom of the container and not repeat vertically or absolutely position an image to the bottom.
You can use pseudo-elements for this. This way you don't require extra markup for each element.
.myDiv {
position: relative;
}
.myDiv::after {
content: url(image.jpg);
display: block;
position: absolute;
left: 0;
top: 100%; /* will be placed immediately where the div ends */
width: 100%;
}
Based on the height of the 'banner curls', set a margin-bottom on .myDiv.
Or directly, without absolute, as long as you don't have paddings:
.myDiv::after {
content: url(image.jpg);
display: block;
width: 100%;
}

how to make a button responsive which is placed on the image in html?

I have a banner-image, on that image I've placed a link. This page is not getting aligned properly when I zoom-in or zoom-out the browser window or when I resize it.
The link is not getting aligned properly with respect to the image as it was showing in the default view(100% zoom ).
How to make this link responsive? I want the Read More button to be aligned exactly below the text Driving Value creation with ..... text, and the Read More link to be responsive with respect to the image on which it is present. How can I do that?
Here's my JSFiddle
<p class="homeImageLink">
<span>Read More</span>
</p>
Please help.
I am not sure this will work, but I think it would:
.image_container span
{
margin-left:-100px;
}
DEMO
DEMO1
You need to tweak your css so that the positioning is a bit more clear, I've fixed it somewhat here.
The important parts are here:
.image_container {
position: relative;
}
.homeImageLink {
position: absolute;
bottom: 10%;
right: 3%;
}
On the container, position: relative; means that any internal positioning will work from this container. Any positioning apart from static would do here and it's important no intermediate elements in the tree have position set or it will work from that element instead.
The the link container itself is position: absolute; with % values used to keep it proportional to the size of the container. Note also that right is used instead of left so the element appears relative to the right of the container. Now it will never go off the right hand side of the image.
To make this clearer I've removed all the other css from the example and as you can see it still demonstrates the effect you desire.

Make sure content ends up below absolute positioned element

So, I have a number of buttons that will expand a div with some content below it.
I want to place them in an order so that the expanded content is right after the button that will expand it. This is because I want the tab order to be:
tab to a button and click it
tab through the expanded content
tab to the next button or tab to content below
To achieve this I've made the expanding content to be position absolute. So far so good. The problem now is that the content after the expanded container does not get pushed down.
See page and code here: http://niklasholmberg.se/temp/tab1.html
My first solution to this was to measure the height of the expanded div and add that as padding to a container that is before the content that should be pushed down.
See page and code here: http://niklasholmberg.se/temp/tab2.html
I don't quite like the solution and want something that does not require scripting to get the layout right.
Can I somehow make the div with class group also "wrap" the container that is positioned absolute?
Can I somehow position the expanded div in another way that doesn't use position absolute but achieves the same result?
Or maybe someone has a complete other solution to this case.
Thanks
Okay,
you can use position relative to expanded div, ie article in this case.
<article id="content1" class="expandarticle">
<h1>Content 1</h1>
aa
<button>bb</button>
<input type="text">
</article>
your css should be
.expandarticle {
background: none repeat scroll 0 0 #ccc;
display: table;
left: 0;
padding: 10px;
position: relative;
right: 0;
}

Unordered list menu unable to position it correctly + unable to center the list items within the unordered list

Take a look at the fiddle below:
Fiddle: http://jsfiddle.net/TE8hD/
In it you can see my problems:
The list items within the <ul> are not centered as there is a big margin to the left while there is no gap at all to the right.
Also the <ul> itself cannot be properly positioned the way I want it to. I want it to be 200px from the right and 0px from the bottom. However when I try this I can only get the right property to work.
I've been trying to fix this for the past 2 hours, changing everything from position, float, display, margin, padding etc. Nothing seems to do the trick, if I could get some help solving this it would make my day.
Add:
padding: 0;
margin: 0;
To your .dropdown class.
And look into implementing a reset.css file, which typically resets margin, padding, and other properties on a lot of elements so that you have a blank slate when creating your CSS.
Also, you seem to lack an understanding of what position: relative and position: absolute do. Do some research on that. But if you want your UL to be positioned absolutely at the bottom of its containing element (.header), then .header needs to have position: relative and .dropdown needs position: absolute;
Fiddle: http://jsfiddle.net/TE8hD/2/

How do I make a header that remains in the top at all times?

I want to make a header like http://www.chacha.com (doesn't move, is about that wide and that height, and able to fit divs inside it and also has to be an image)
I am starting off with a blank html document and a blank css page, so there I haven't currently written any code.
I've been trying two days straight to do this now so I would really appreciate any help anyone can provide.
I have gimp so if anyone could also give me image dimensions for a perfect header and perfect background size I would appreciate it even more.
CSS:
#header {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 10px;
background: url(yourimage.png) repeat-x;
}
<!--html -->
<div id="header"></div>
That should give you a starting place, I can't tell you more without seeing exactly what the layout's supposed to be.
The CSS property you're looking for is position: fixed which will position the element relative to the viewport. This is good breakdown of positioning: https://developer.mozilla.org/en-US/docs/CSS/position
In this specific case, what you've got is an element with styles roughly along these lines:
#header_id {
position: fixed;
width: 100%;
height: 35px;
}
You don't have to set the height, but unless there is content in the fixed element, it will collapse if there is no height specified. They also appear to have put a drop-shadow on the element toget the neat floating effect.
If you want to have an image inside, you can just put the <img> inside the header element, or use it as the background-image url in the CSS and position it with background-position (see also: https://developer.mozilla.org/en-US/docs/CSS/background-position although the compatability table at the bottom is important if you want to do anything too specific with this property).
You can do this with any block-level element (or any element with display:block set on it). In your example they are using the HTML5 <header> tag; a <div> would work, too, if <header> wasn't appropriate for your page.
I would recommend using the Firebug addon with Firefox (or similar developer consoles with other modern browsers) -- you can right click on an element on the page and select 'Inspect element' from the dropdown menu and get a breakdown of both the markup and styling to see how other websites are constructed. Very useful for when you're browsing the internet and you see something and think, 'that's a neat trick, how does it work?'
FOR FULL WIDTH FIXED HEADER
header {
width:100%;
background:green;
height:60px;
margin:-8px;
position:fixed;
}
FOR NONFULL WIDTH FIXED HEADER
Create a div and set width and height (you can also set it left or right by float:left, float:right)
then in this div put the code above but without margin:-8px; and change the width to the width that your div has.
Here is a test