I'm using CSS to create a header graphic:
#header {
height:125px;
background:url(/Content/images/header_footer.jpg) -0 0 no-repeat;
}
then:
<div id="header">
<!-- navigation START -->
<ul id="main_navigation">
Is there a way to make the graphic (space above the nav UL) into a clickable link?
thx
I don't think this is a good approach. If you want only the graphic to be a link put in a separate element:
CSS :
#header{
height:125px;
}
#headerImg{
display:block;
height:100px;
background:url(/Content/images/header_footer.jpg) -0 0 no-repeat;
}
HTML :
<div id="header">
<span id="headerImg"></span>
<ul id="main_navigation">
Certainly: add a link tag. CSS is great at adding graphics and visual elements to pages, but if you want the page to do anything (e.g., to link somewhere) that has to be expressed somewhere in the HTML.
A common solution to what you're trying to do is to add an empty <a> tag, styled with a width and height that match the graphic you're using.
The above answers are correct in that you need an anchor tag in your HTML, but how that plays out depends entirely on what the image is that you are linking.
I don't see any reason to ever have an empty anchor tag. That's meaningless. Most likely you are either linking a logo or wordmark or site title or some combination. That should go in your HTML code, even if you plan to replace it with an image.
The first consideration is whether your header image itself is content or design. In the case of logos, it sometimes is content. In the case of site titles or wordmarks I would more often say the image is simply design, and the text is content.
For an image that is content in it's own right:
<div id="header">
<img src="logo.png" alt="My company">
<!-- navigation START -->
<ul id="main_navigation">
For an image that is replacing content:
<div id="header">
<h1>My Company</h1>
<!-- navigation START -->
<ul id="main_navigation">
and style:
#header h1 a {
display: block;
text-indent: -999em;
height: ??px;
background-image: url(path/to/image.png);
}
In either case, you have given semantic meaning to the area used as a link. I can't quite imagine a situation where you would want a meaningless link.
Keep everything the same, move the tags within the div so it validates. Add a class to the tag.
Class then is display:block and then height and width required. Job done, validating complete.
Erm, wouldn't this do it (or have I misunderstood?):
<div id="header">
You'll probably also want to add border:none to your #header
<a href="/whereever.php">
<div id="header">
<!-- navigation START -->
<ul id="main_navigation">
Is that what you wanted?
But I agree that the above answer is a better method
just do like this:
<div style=" height: 100px; background: url('logo.png')" >
<a href="/link" style="display: block; width: 100%; height: 100%" />
</div>
You can style your hyperlink attribute directly:
Example:
<a href="<your-link>" target="_blank" style="content: ''; width: 10px; height: 10px; background-image: url('<your-image-path>'); background-repeat: no-repeat; background-size: 10px 10px; display: flex">
Related
I'm kinda stuck with this small issue that's breaking my layout. On the home page I have a blue box which is serving as my main container. Within my main container there are two more boxes which are on the right side of the screen which contain contact info. Also within the headline-container there is an H2 which say's -- "Satisfaction is our strongest point"
So what's wrong? Well nothing looks wrong atm but what if wanted to accurately center the H2 "Satisfaction is our strongest point" within it's headline-container which is the light blue large rectangle. So I write this CSS to try accurately center the text within headline-container
%align {
position: relative;
top: 50%;
-webkit-transform:translateY(-50%);
-ms-transform:translateY(-50%);
transform:translateY(-50%);
}
Hold my breath and bang crash..
My entire layout breaks..I'm thinking this due to a parenting issue with the H2. In my HTML I am inserting the h2 class just bellow the div class for large-8 columns which in this case is not the correct parent to (center the text within.) The element that I want to center the text within is headline-container (light blue box). To simply put it -- My layout seems to be breaking as soon as I change the h2's parent to headline-container and add the styles above.
Here is the HTML
<div class="headline-container">
<div class="row">
<div class="large-8 columns">
<h2 class="satisfaction">Satisfaction is,</br>Our Strongest Point</h2>
</div>
<div id="contact-info" class="large-4 columns">
<div class="phone-box">
<div class="number">
<a id="phone-number" href="tel:808-848-8821">808-848-8821</a>
</div>
</div>
<div class="email">
<div class="email-box"><a id="email-contact" href="mailto:etoile#hawaii.rr.com">etoile#hawaii.rr.com</a>
</div>
</div>
</div>
</div>
</div>
I've used a temporary not so accurate way of centering my H2 by applying this padding to the text. It looks fine but something deep down tells me it's not 100% accurate and that bothers me..Any suggestions on why my layout is breaking?
padding-top: 40px;
Here's the link
http://kapena.github.io/pp_web/
Thax for reading and I look forward to you're suggestions and comments.
Setting a fixed height to the container (div.columns) of the h2 fixes this.
Example
<div class="large-8 columns">
<h2 class="satisfaction">Satisfaction is,</br>Our Strongest Point</h2>
</div>
CSS
.columns {
height: 218px;
}
.satisfaction {
position: relative;
top: 50%;
transform: translateY(-50%);
}
You could just use h2{text-align: center} or failing that .row{display: block; position: relative; margin: 0 auto; width: 100%;} you dont need the translates
try this for h1 element
h2{
display:inline-block;
margin: 0 auto;
}
I am trying to create my own website from scratch, now i ran into a problem considering the HTML/CSS bit.
I am trying to create this standard "header, navigation, content" layout where the header is at the top, the navigation is at the left and the content starts below the header and to the right of the navigation
I use the following piece of code:
<div id="head">
<img src="..." id="logo" style="float:left">
</div>
<div id="nav">
{some elements}
</div>
<div id="content">
{some elements}
</div>
But as soon as the "style='float:left'" is added to my code, the "content" and "nav" DIV automatically moves to the right of the "head" DIV, is it possible somehow to make the "head" DIV "reserve" the remaining space, so that the "content" and "nav" DIV wont move up to the right of it, but stay below?
This problem is called "Collapsed Parent". To prevent this you must clear float.
Add this CSS to your style sheet:
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
And add the class "clearfix" to your header, like
<div id="head" class="clearfix">
<img src="..." id="logo" style="float:left">
</div>
For more information on clearing floats you can check out this url - http://www.tutorialrepublic.com/css-tutorial/css-alignment.php
<div style="width:250px;">
<div id="head" style="width:100%; border:1px solid red;">
<img src="..." id="logo"> Header-Logo
</div>
<div id="nav" style="float:left;width:47%;border:1px solid blue;">
Navigation-Left
</div>
<div id="content" style="float:right; width:50%;border:1px solid blue;">
Content-Right
</div>
</div>
-I think the reason is "float:left" inside tag id="head". Because you want to put the header in the top of website so no need to use "float:left" for it.
-You can use "float:left" for tag id="nav" and "float:right" for tag id="content"
Here is the result: http://jsfiddle.net/4JgA4/119/
=> No need to notice to all my information inside some tags (Just for decorations :D)
Clearing the floats will do.
You need to add a class to your div and in your css as below:
.clear
{
clear:both;
}
Add overflow:hidden to the #head element. I don't know why it works, but it ensures that all floated elements are contained inside the parent.
I want to create a simple thumbnail grid for showing images from the Europeana API. However for some weird, probably very obvious, reason I get random rows in this grid with large spaces as if the floating isn't working. However the same layout with random images (http://placehold.it/250x350) does not seem to have this problem. See result of html and css here: http://jsfiddle.net/VqJzK/1/ .
CSS of the grid
.thumb {
width: 200px;
background-color: #F5F5F5;
border-radius: 5px;
margin-bottom: 0.5em;
margin-top: 0.5em;
text-align: left;
position: relative;
display: inline-block;
float: left;
}
.thumb img {
width: 150px;
vertical-align: middle;
}
and the html:
<div class="thumb">
<img alt="test" src="http://europeanastatic.eu/api/image?uri=http%3A%2F%2Fhdl.handle.net%2F10796%2FKOEKOEK_JG1_26_19311105%3Flocatt%3Dview%3Aderivative2&size=LARGE&type=TEXT"/>
</div>
<div class="thumb">
<img alt="test" src="http://europeanastatic.eu/api/image?uri=http%3A%2F%2Fhdl.handle.net%2F10796%2FKOEKOEK_JG1_02_19310521%3Flocatt%3Dview%3Aderivative2&size=LARGE&type=TEXT"/>
</div>
....
The broken formatting is because some images are taller in the second example. The taller images take up more space and because the thumbnails have float:left set, they flow around the taller one. This explains why the first example works, since they all have the same height.
That said, float:left is also overriding the display:inline-block with display:block - see css display property when a float is applied
If you remove float:left or set the height of the .thumb class the thumbnails will also line up as expected.
sounds like the standard inline-block bug, simple fix is to change your code to this:
<div class="thumb">
<img alt="test" src="http://europeanastatic.eu/api/image?uri=http%3A%2F%2Fhdl.handle.net%2F10796%2FKOEKOEK_JG1_26_19311105%3Flocatt%3Dview%3Aderivative2&size=LARGE&type=TEXT"/>
</div><div class="thumb">
<img alt="test" src="http://europeanastatic.eu/api/image?uri=http%3A%2F%2Fhdl.handle.net%2F10796%2FKOEKOEK_JG1_02_19310521%3Flocatt%3Dview%3Aderivative2&size=LARGE&type=TEXT"/>
</div>
butt the elements right up next to each other, because it's treated as inline spaces between elements matter, because text itself is inline
alternatively you could use comments like this:
<div class="thumb">
<img alt="test" src="http://europeanastatic.eu/api/image?uri=http%3A%2F%2Fhdl.handle.net%2F10796%2FKOEKOEK_JG1_26_19311105%3Flocatt%3Dview%3Aderivative2&size=LARGE&type=TEXT"/>
</div><!--
--><div class="thumb">
<img alt="test" src="http://europeanastatic.eu/api/image?uri=http%3A%2F%2Fhdl.handle.net%2F10796%2FKOEKOEK_JG1_02_19310521%3Flocatt%3Dview%3Aderivative2&size=LARGE&type=TEXT"/>
</div>
I am trying to create a CSS-based layout that has:
- A dynamically sized banner.
- A content area that should use all available space.
- A footer that aligns against the bottom of the page.
Currently, I have this. However, my challenge is working in the content area. Within the content area, I need to show:
- A dynamically sized header.
- A content area that uses all available space.
- A footer that aligns at the bottom of the content area, but above the footer mentioned above.
Altogether, I want to create a screen that looks like this:
+------------------------------------+
| Banner |
| |
|------------------------------------|
| Header |
|------------------------------------|
| Some Content |
| This needs to be dynamically sized |
| to fill all remaining content |
|-------------------------------------
| Toolbar |
|------------------------------------|
| Footer |
+------------------------------------+
Currently, I have the following
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"></script>
<style type="text/css">
html, body{
height: 100%;
overflow: hidden;
}
body {
padding: 0;
margin: 0;
font-size: .85em;
font-family: Arial, Verdana;
color: #232323;
background-color: #fff;
}
</style>
</head>
<body>
<div id="banner" style="width:100%; background-color:Black; color:White;">[Banner]</div>
<div id="content" style="width:100%; height:100%; background-color:Gray; margin:0px 8px 0px 8px;">
<h2>Header</h2>
<div id="contentArea">
<div id="mainContent" style="background-color:Silver;">The main content goes here.</div>
</div>
<div id="toolbar" style="padding:8px 0px 8px 8px;">
<input type="button" id="refreshButton" value="Refresh" />
<input type="button" id="addButton" value="Add" />
</div>
</div>
<div id="statusBar" style="background-color:black; color:White; width:100%; position:fixed; bottom:0;">
<table border="0" cellpadding="0" cellspacing="0" style="width:100%;">
<tr>
<td style="width:33%;">Info</td>
<td style="text-align:center; width:34%;">Message</td>
<td style="text-align:right; width:33%;">Miscellaneous</td>
</tr>
</table>
</div>
</body>
</html>
This screen does not render as desired though. From what I can tell, when I set the "content" div height to 100%, it means 100% of the entire screen. In addition, I can't seem to get the "contentArea" div to take up the remaining space, nor can I get the toolbar to be aligned to the bottom. What am I doing wrong? How do I accomplish this?
This "sticky footer" technique should help with your footer problems. It will make it stick to the bottom, but will not overlap content like a position:absolute will if the page scrolls.
http://ryanfait.com/sticky-footer/
I believe you are asking how to make a side bar and the content section of a webpage appear to be equal in height without concern for the actual height of the content in either of the aforementioned div sections. If this is true, I believe I have what I perceive to be an easy answer to your dilemma.
Using HTML 5 and CSS 3, this is my proposal.
Starting with the CSS:
body{/*enter in your parameters */ }
.container{/*this div surrounds all the other divs and allows you to give percentage based widths in subsequent divs*/ max-width: 1000px; min-width: 760px; maergin: 0, auto, 0, auto; background-color: #000;}
.extraheight{float: left; width: 100%; height: 100%; background-color: #ccc;}
.header{width: 100%; color: #FFF; background-color: #00f; /*just for demo purposes*/ }
.sidebar{float: left; width: 30%; background-color: #ccc; /*match the background of the extraheight div*/ }
.content{float: left; width: 70%; background-color: #ccc; /*matches extraheight and siderbar colors */ }
.footer{color: #FFF; /* must make sure you clear the floats above */ position: relative; /* IE6 to properly clear */ clear: both; /* this clear property forces the .container to understand where the columns end and contain them */ }
Some basic HTML Using the above CSS to illustrate how it works:
<div class="container">
<div class="extraheight">
<div class="header"><h1>THIS IS MY WEBSITE</h1></div>
<div class="sidebar">
<p>This where you put your feed or whatever sidebar content you desire</p>
</div><!-- ENDS SIDEBAR -->
<div class="content">
<h2>This is where you place your content</h2>
<p>My site is the product of my effort and desire to provide each user with an enjoyable visit. We strive to exceed expectation without comprimising any needs. Check back often as our content is constantly changing.</p>
</div><!-- ENDS CONTENT -->
</div><!-- ENDS EXTRAHEIGHT -->
<div class="footer"><p>Put your footer content here</p></div>
</div><!-- ENDS CONTAINER -->
I don't have enough points yet to provide you with screenshots of how the page displays but I encourage you to give it a try. Most important issue to is to either make the extraheight div the background you want for the sidebar and content divs while making the background transparent in those divs or to make the sidebar and content divs the same background as the extraheight div. The latter being very easy when a solid color is used as the background but the former is necessary with a background that is any but extremely basic.
I hope this provided you with at least a portion of the information you were interested in when you posted. I am still trying to learn how to properly interpret the questions asked by our colleagues that post to this forum. Alas, I am new to this forum, but a quick learner!
Best wishes and success,
Steve K
uparrow.gif and downarrow.gif
So, it would look like so:
How can I create 3 divs and style them with CSS so those arrows are positions with the top arrow above the bottom arrow?
<div class="vote">
<div class="uparrow" />
<div class="downarrow" />
</div>
Should I create a "vote" div with restricted width? Would I float: top and float: bottom the two arrow divs with the background set as my two images? I plan on having content directly to the right of the vote arrows so it needs to be restricted and tight.
Don't use divs for an image - there's already a perfectly good img tag!
<div class="vote">
<img alt="^" title="vote up" src="/images/up.arrow.png" />
<img alt="v" title="vote down" src="/images/down.arrow.png" />
</div>
And then simply:
.vote
{
width: 15px;
float: left; clear: left;
}
.vote img
{
display: block;
float: none; clear: both;
}
You may want to add some margin to the .vote to separate it from the content it will be next to.
By default, <div> elements are block-level meaning they are one-per-line and will expand horizontally to fill their container.
Adding the click handling is another problem. You could include the <a> and <img> elements in the uparrow and downarrow elements or you do it in CSS as you suggested (the less compatible way). Another option is registering DOM events with Javascript.
HTML:
<div class="vote">
<div class="uparrow" />
<div class="downarrow" />
</div>
CSS:
div.vote {
width: 50px;
float: left;
}
div.uparrow {
background-image: url(...);
}
div.downarrow {
background-image: url(...);
}
Use 2 divs. Float the text div left and put the two images in a single div. use display: block on the images to force one below the other.
A more semantic and efficient solution than divs would be this, which also takes care of positioning the vote box.
.content-item {padding-left:110px;position:relative; width:500px;border:1px solid red;}
.vote{width:100px;position:absolute; top:0; left:0;border:1px solid red;}
.vote h4 {style heading how you like}
.vote img{width:100px;height:30px;background:black;}
<div class="content-item"> content
<div class="vote">
<h4>Vote</h4>
<img alt="vote up" src="..." />
<img alt="vote down" src="..." />
</div>
</div>