What's the simplest way to achieve the following with HTML/CSS:
+---------+---------------------------------------------------+
| my | Home About Categories Donate |
| best +---------------------------------------------------+
| website | Search __________ |
+---------+---------------------------------------------------+
Constraints:
"my best website" is text, not an image, so cannot specify height of "masthead" in px
The height of each of the two long rectangles should take up 50% of the height of the square box
The two long rectangles should stretch "all the way" to the right
Here is my best attempt:
#masthead {
background-color:red;
}
#masthead-sitename {
font-size:3em;
float:left;
color:white;
padding:20px;
background-color:black;
width:188px;
}
#masthead-twobars {
float:left;
background-color:green;
}
#masthead-menu {
float:left;
width:100%;
font-size:x-large;
color:white;
padding:20px;
background-color:gray;
}
#masthead-search {
float:left;
width:100%;
font-size:x-large;
color:white;
padding:20px;
background-color:yellow;
}
<div id="masthead">
<div id="masthead-sitename" >
my<br/>best<br/>website
</div>
<div id="masthead-twobars" >
<div id="masthead-menu">
Home About Categories Donate
</div>
<div id="masthead-search">
Search
</div>
</div>
</div>
It fails because the two long rectangles do not stretch all the way to the right, and the heights of the two long rectangles do not add up to the height of "masthead-sitename"
Give the masthead left padding as wide as the site name, then position the sitename absolutely over the padding. Don't float the bars, don't give them width. They'll just naturally fill the container without overlapping the left padding. Set the sitename's height to 100% and make the bars tall enough to fully display the site name.
Demo: http://jsfiddle.net/d6xsQ/1/
.masthead {
padding-left: 218px;
background-color:red;
position: relative;
}
.masthead .sitename {
position:absolute;
left: 0;
top: 0;
font-size:3em;
color:white;
background-color:black;
width:218px;
height: 100%;
overflow: hidden;
}
.masthead .sitename > div {
padding:20px;
}
.masthead .bar {
font-size:x-large;
padding:40px 20px;
}
.masthead .menu {
background-color:gray;
color:white;
}
.masthead .search {
background-color:yellow;
}
<div class="masthead">
<div class="sitename" >
<div>
my<br/>best<br/>website
</div>
</div>
<div class="bar menu">
Home About Categories Donate
</div>
<div class="bar search">
Search
</div>
</div>
http://jsfiddle.net/4cn7q/3/
Basically, let the site name dictate the box height, and absolutely position the two "rows" within the wrapper.
(You can then choose to vertically center content in the rows if you like, using a variety of techniques.)
The "easiest" (although probably not the best way) is to use a table:
<table>
<tr>
<td rowspan="2">my best website</td>
<td>Home About Categories Donate</td>
</tr>
<tr>
<td>Content goes here</td>
</tr>
</table>
However I know a lot of people who would lynch me for suggesting this. Hey, I just want to not have to spend five hours getting the CSS to work, okay? :p
Related
I am having an issue structuring and styling my sidebar and header using the genesis theme.
I want a full width article header area with a sidebar that is aligned next to the entry content.
I have tried moving the header area to the genesis_before_content hook, but this causes the title and post info to be outside the article tag and associated schema, which is not ideal.
I have tried specifying the entry-header content to be full width in css, then setting the top of the sidebar to start x number of pixels down the page to align it with the entry-content. This has the problem that if the header text encompasses more than one line, the sidebar is misaligned to the entry-content.
Here is a fiddle of how I currently have the css arranged:
.wrapper {
background-color:#f9f9f9;
width:600px;
height:800px;
font-size:40px;
color: #FFF;
}
.content {
background-color:blue;
opacity:0.2;
float:left;
position:relative;
width:300px;
height:100%;
}
.header {
background-color:red;
opacity:0.5;
position:relative;
width:600px;
height:200px;
display:inline-block;
text-align:center;
}
.sidebar {
background-color: green;
opacity: 0.2;
width: 300px;
height: calc(100% - 200px);
float: right;
position: relative;
top: 200px;
}
<div class="wrapper">
<div class="content">
<div class="header">Title</div>
<div class="entry">Entry content</div>
</div>
<div class="sidebar">Sidebar widgets</div>
</div>
https://jsfiddle.net/j9z4tjod/
Can anyone help me find a solution?
Thanks
I want to archive this img layout with CSS:
http://666kb.com/i/czotlngmz2miu66q1.gif
1 & 2 & 3 have the same height of 911px
2 must be centered and has a fixed width of 800px
img 1 & 3 should be stretched to fill the remaining space on left and right side
the imgs should not overlay each other
My HTML Code is a bunch of div tags, nothing special, so I don't think there's need to post it.
For me this sounded like a simple task at first time, but ended up wasting 20h and archived nothing.
has anyone a idea to make this?
Edit1:
All asked for code so I’ll show u what i just came up with:
#page {
display:table-row;
height:911px
}
#logo {
background:url(../images/logo.png) top center no-repeat;
width:800px;
height:293px;
position:absolute
}
#side_L {
display:table-cell;
background:url(../images/bg_L.png) no-repeat right top / 100% 911px;
min-width:50%;
height:911px
}
#mid {
display:table-cell;
background:url(../images/main_bg.png) top center no-repeat;
width:800px;
height:911px;
max-width:800px
}
#side_R {
display:table-cell;
background:url(../images/bg_R.png) no-repeat left top / 100% 911px;
min-width:50%;
height:911px
}
<div id="page">
<div id="side_L"></div>
<div id="mid">
<div id="logo"></div>
<div id="content"></div>
<div id="foot"></div>
</div>
<div id="side_R"></div>
</div>
problem here --> it somehow works but I looks dirty anyway.
Is there a better solution?
All stuff from now on like logo, content & foot and such need a ->margin-top: -911px...
that can't be the best way.
Simulating a table is one way, but in this case, you can simply float the first two divs to the left, leaving the last div to take up the remaining space. The trick is the calc function that is used to give the left div half the width of what is left over when you put an 800px div in the window, so that the right div will have the same width.
Note that the sizes of the divs are too large to show in the snippet window correctly, so you'll have to go full screen to see it in all its glory.
Also note that I replaced the background pictures (which wouldn't show) with background colors.
#side_L {
float: left;
background: #DFD;
width: calc(50% - 400px);
height: 911px;
}
#mid {
background: #DFF;
float: left;
width: 800px;
height: 911px;
max-width: 800px;
}
#side_R {
background: #DDF;
height: 911px;
}
<center>
<div id="page">
<div id="side_L"></div>
<div id="mid">
<div id="logo"></div>
<div id="content"></div>
<div id="foot"></div>
</div>
<div id="side_R"></div>
</div>
</center>
How about this template?
#header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
#nav_left {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
#nav_right {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float: right;
padding:5px;
}
#section {
width:800px;
float:left;
padding:10px;
}
#footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
<div id="header">
<h1>City Gallery</h1>
</div>
<div id="nav_left">
London<br>
Paris<br>
Tokyo<br>
</div>
<div id="section">
<h2>London</h2>
<p>London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.
</p>
<p>Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.
</p>
</div>
<div id="nav_right">
London<br>
Paris<br>
Tokyo<br>
</div>
<div id="footer">
Copyright © W3Schools.com
</div>
I'm trying to work out the best way using CSS to keep Block 2 centred in the remaining space that exists to the right of Block 1. This space could increase or decrease with the size of the browser window / orientation of device. Block1's position does not move.
I was hoping to be able to use a combination of float, margin-left:auto and margin-right:auto as way of keep Block2 centred, however, sadly my CSS is still in it's infancy.
Any guidance / help would be greatly appreciated.
#block1 {
position:relative;
top:10px;
left:0px;
width:50px;
height:100px;
background-color:#009;
}
#block2 {
position:relative;
width:100px;
height:100px;
top:10px;
float:right;
margin-left:auto;
margin-right:auto;
background-color:#999;
}
<div id="block1"></div>
<div id="block2"></div>
http://jsfiddle.net/d4agp0h6/
Thanks in advance
An easier way to do this would be to use nested divs rather than trying to position two within the same block element.
Here's the updated jsFiddle
So, you create a wrapper (#block1) which is the size of the entire page so you can move stuff around inside. Position each subsequent piece of content within this area so you can set margins, position, etc.
HTML
<div id="block1">
<div id="block2">
<div id="content">
<p>This is some text</p>
</div>
</div>
</div>
Then, with your CSS, set the positions relative to one another so you can use margins and percentage spacing to keep things fluid.
CSS
#block1 {
position:relative;
top:10px;
left:0px;
width:200px;
height:400px;
background:#555;
}
#block2 {
position:relative;
width:75%;
height:100%;
float:right;
margin:0 auto;
background-color:#999;
}
#content {
margin:0 auto;
border:1px solid black;
position:relative;
top:45%;
}
#content p {
text-align:center;
}
It appears you want a fixed side bar and a fluid content area.
DEMO: http://jsfiddle.net/fem4uf6c/1/
CSS:
body, html {padding:0;margin:0;}
#side {
width: 50px;
background-color: red;
box-sizing: border-box;
float: left;
height: 500px;
position: relative;
z-index: 1;
}
.content {
position: relative;
box-sizing: border-box;
width: 100%;
padding: 20px 20px 20px 70px;
text-align: center;
}
#box2 {
width: 50%;
height: 300px;
background: purple;
margin: 0 auto;
}
HTML:
<div id="side"></div>
<div class="content">
<p>This is the content box. Text inside here centers. Block items need margin: 0 auto; inline and inline-blocks will auto center.</p>
<div id="box2"></div>
</div>
Here is my take on a solution. I used Brian Bennett's fiddle as a base, since I agreed with how he laid out the markup and was going to do something similar myself.
Link to JSFiddle
Where I differed is to add a container section:
<section id='container'>
<div id="block1"></div>
<div id="block2">
<div id="content">
<p>This is some text</p>
</div>
</div>
</section>
I also used percentages to determine widths instead of px values - with the exception of #container. Changing the width of the container should demonstrate that the relevant content is always centered.
Option 1
Here is one of the correct way of putting Block side by side... where one Block is on the Top Left... and the other Block is Top Center
Working Demo 1 : http://jsfiddle.net/wjtnddy5/
HTML
<div id="mainBlock">
<div id="block1">
<div class="box"></div>
</div>
<div id="block2">
<div class="box"></div>
</div>
</div>
CSS:
html, body {
height:100%;
margin:0;
padding:0;
}
#mainBlock {
height:98%;
width:98.9%;
border:5px solid #000;
}
#block1 {
width:10%;
height:100px;
display:inline-block;
border:1px solid #ff0000;
overflow:hidden;
}
#block2 {
width:89.2%;
height:100px;
margin-left:auto;
margin-right:auto;
border:1px solid #ff0000;
display:inline-block;
}
.box {
margin:0 auto;
background-color:#009;
width:100px;
height:100px;
}
Its using the "display:inline-block;" to put Blocks side by side which is better than using Float technique... let me know incase you need only Float!
Option 2
Here is the Other technique using "float: left" incase you need this only...
For this I have just replaced "display:inline-block" with "float: left" for both Blocks.... rest is same..
Working Demo 2 : http://jsfiddle.net/h78poh52/
Hope this will help!!!
I am trying to position the second image inline next to the one before, the second image is smaller and i want it to sit on the same bottom line next to the larger one next to it. this will create a gap above the second image where i can put a small bit of text.
My problem is when i play around with background-size:, height: and width: to change the size of the image it just goes to the top left hand corner of its surrounding div.
I plan on having 4 more small image next to the small one so I'm asking please could anyone sort out the positioning of the divs and css so that i can easily add more next to the prior one,
Here is an image to give you an understanding of what i am trying to achieve, The red box shows where i want it to be positioned, and the other red box is where i will have the next skin.
LINK
Things i have tried:
Bottom:0
margin-top ( to push it down ) though this does not leave room for me to add text above the smaller images
padding-top:
Here is my current CSS:
#secondinner {
width:980px;
margin:0 auto;
overflow: hidden;
}
#dailyskin {
width:120px;
height:20px;
background-color:#336699;
color:white;
font-size:14px;
text-align:center;
padding-top:1px;
}
#topskin {
background-image:url(images/topskins/1f.png);
background-size:110px;
height:220px;
background-repeat:no-repeat;
width:110px;
dislpay:inline-block;
float:left;
margin-top:5px;
}
#topskin2 {
background-image:url(images/topskins/1f.png);
background-size:80px;
height:150px;
background-repeat:no-repeat;
width:80px;
dislpay:inline-block;
float:left;
margin-top:5px;
}
#downloadbutton1 {
width:100%;
}
#firstskin {
width:110px;
overflow:hidden;
float:left;
}
#secondskin {
width:100px;
overflow:hidden;
float:left;
padding-left:10px;
}
Here is the HTML:
<div id="secondinner">
<div id="dailyskin">Todays Daily Skin!</div>
<div id="firstskin">
<div id="topskin"></div>
<button id="downloadbutton1" type = "button" name = "Download"> Download </button>
</div>
<div id="secondskin">
<div id="topskin2"></div>
<button id="downloadbutton1" type = "button" name = "Download"> Download </button>
</div>
</div>
This is the third section to the index page.
</div>
Here is a JS fiddle to show you what i mean,
http://jsfiddle.net/bjbear123/qdwgpaqc/
display: table-cell; with a vertical-align: bottom could be a good solution.
Have a jsBin!
HTML
<div class="skin-wrap">
<div>
<img src="http://www.placehold.it/100X300" />
<button>Download</button>
</div>
<div>
<p>text above </p>
<img src="http://www.placehold.it/100X200" />
<button>Download</button>
</div>
</div>
This is the third section to the index page.
CSS
.skin-wrap {
display: table;
}
.skin-wrap > div {
display: table-cell;
width: 100px;
vertical-align: bottom;
padding: 10px;
}
And if you don't want / are not able to use table-cell as misterManSam answered you can use nested divs with position absolute.
.wrapper{
position: relative;
height: 200px;
width: 100px;
}
.content{
position: absolute;
bottom: 0;
}
<div class="wrapper">
<div class="content">
<img src="whatever.jpg" />
</div>
</div>
And there you have a little jsbin http://jsbin.com/jiqakefu/1/
One easy solution is to increase the top margin of topskin2.
#topskin2 {
background-image:url(images/topskins/1f.png);
background-size:80px;
height:150px;
background-repeat:no-repeat;
width:80px;
dislpay:inline-block;
float:left;
margin-top:75px;
i tried this on jsfiddle both download button were inline.
You can set margin as per your need, if you want space between both then you can use margin-left to create gap.
you were right doing it through bottom:0;
The thing you missed was to set position:absolute; and for outer div position:relative;
Here's a fiddle: http://jsfiddle.net/Nive00/qdwgpaqc/2/
Hi to all,
I'm trying to make 3 divs equidistant from each other. The DIV width is determined by the IMG file in it.
I have succeeded in making a container div 80% width of the page and is centered.
However, the DIVs inside this are equidistant to each other (for as far I can see) but do not center themselves according to the div they are in.
HTML:
<div class="slide" id="slide5" data-slide="5" data-stellar-background-ratio="0">
<div class="slide5_wrapper">
<div class="slide5_recd2011">
<img src="images/RECD2011_thumbnail.png">
</div>
<div class="slide5_recd2012">
<img src="images/RECD2011_thumbnail.png">
</div>
<div class="slide5_recd2013">
<img src="images/RECD2011_thumbnail.png">
</div>
</div>
And the CSS:
.slide5_wrapper{
margin: 0 auto;
width:80%;
position: relative;
max-height:80%;
top:10%;
text-align:justify;
}
.slide5_recd2011, .slide5_recd2012, .slide5_recd2013 {
margin: 10px;
height:auto;
border-radius:15px;
vertical-align: top;
display:inline-block;
}
#slide5_wrapper:after {
content: '';
width:100%;
display:inline-block;
}
Excuse me for my horrible use of terminology (wrappers /containters w/e) just want this to work.
I'm not a real website coder, just trying to learn and I have this project I have taken on while not being too qualified for it (it's a temporary non-corporate website and not going to be my business so I'm not destroying the work field or anything).
Thanks in advance
Here is the link with explanation, here is the working sample.
#slide5_wrapper{
text-align: justify;
}
#slide5_wrapper:after{
content:'';
width:100%;
display:inline-block;
}
#slide5_wrapper div{
display: inline-block;
}
Hope it helps.
What's just about this:
.slide5_recd2012{
width: 33%;
float:left;
box-sizing: border-box;
padding: /*some padding you need */ 0;
}
?