HTML, CSS aligning text inside DIV with text in parallel div - html

I was wondering if someone could help me with some HTML/CSS. I'm trying to line up text in a sidebar div to match the content in the content div but the only way I can see possible is adding loads of <p> </p> to html. I am wondering if there is an easier way.
Fiddle
HTML:
<div class="header">
<h3><a name="comb"></a>The combined INSPECT</h3>
</div>
<div class="left">
<p>Syntax</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>To top of page
</p>
</div>
<div class="content">
<p>
<img src="CombInspect.gif" width="649" height="338" alt="combined" />
</p>
<p>This format of the INSPECT combines the syntactic elements of the previous two formats allowing both counting and replacing to be done in one statement.</p>
</div>
CSS:
div.header {
padding: 0.5em;
color: #FFFF00;
background-color: #993300;
clear: left;
line-height: 0px;
}
div.content {
margin-left: 300px;
border-left: 1px solid gray;
padding: 1em;
background-color: #FFFFFF;
}
div.left {
float: left;
width: 270px;
padding: 1em;
background-color: #FFFFCC;
color: #5F021F;
font-size: 17px;
font-weight: bold;
}

Are you totally opposed to using jQuery (and I'm not trying to be rude, just asking if you prefer not to use it)? Otherwise, I'd suggest you get the height of your content div with .height() and set the length of your sidebar that way.
var adjustedHeight = $(".content").height()
$(".left").css("height", adjustedHeight)
Check out the fiddle here
Hope that helps :)
edit: fixed the fiddle link.

If you want To top of page to appear at the bottom, you can put your divs in a container div, with this style:
div.container {
position: relative;
}
Add a bottom class to To top of page, with these styles:
.bottom {
position: absolute;
bottom: 0px;
}
Fiddle

When you float an element it is taken out of the normal document flow. In order to achieve what you are after you can make the left sidebar position:absolute with height:100% as in this fiddle:
http://jsfiddle.net/Lze4pj61/3/
CSS:
div.header
{
padding: 0.5em;
color: #FFFF00;
background-color: #993300;
clear: left;
line-height: 0px;
}
div.content
{
margin-left: 300px;
border-left: 1px solid gray;
padding: 1em;
background-color: #FFFFFF;
}
div.left
{
position: absolute;
width: 270px;
padding: 1em;
background-color: #FFFFCC;
color: #5F021F;
font-size:17px;
font-weight:bold;
height:100%;
}
div.left .to_top {
position:absolute;
bottom:10px;
text-align:center;
}
HTML:
<div class="header">
<h3 ><a name="comb"></a>The combined INSPECT</h3>
</div>
<div class="left">
<p>Syntax</p>
<div class="to_top">
To top of page
</div>
</div>
<div class="content">
<p><img src="CombInspect.gif" width="300" height="150" alt="combined" /></p>
<p>This format of the INSPECT combines the syntactic elements of the previous two formats allowing both counting and replacing to be done in one statement.</p>
</div>

If your content div has a varying dynamic height you could use jquery in a function like this
$(document).ready(function(){
var header = $(".header");
var left = $(".left");
var content = $(".content");
if(left.height() < content.height()){
left.height(content.height())
}
$( ".thisOffSet" ).offset({ top: content.height()+header.height() });
});
You can see on this JSFIDDLE how it works by changing the window size and clicking run for it to readjust.
Hope this helps

Related

HTML div element not allocates new line if sibling div element has <a href> alone

I am new to HTML and CSS.
In first div I want to display elements and in second div I want to display text over background image.
But in the result element is displaying over background image. I want to display element and in below line I want to display background image. How to achieve this?
Below is my code. I am using HTML and CSS.
.navbar {
width: 100%;
}
.nav-left {
float: right;
width: 25%;
position: absolute;
padding-top: 14px;
}
.feature {
border: 2px solid black;
padding: 25px;
background: url(https://static3.depositphotos.com/1005590/206/i/950/depositphotos_2068887-stock-photo-lightbulb.jpg);
background-repeat: no-repeat;
background-size: 100% 100%;
}
.navbar-Logo {
float: right;
color: #dd845a;
text-decoration: none;
}
<div class="navbar">
<div class="nav-left">
<a class="navbar-Logo" href="#">LOGO</a>
</div>
</div>
<div class="feature">
<h1> Sample Text</h1>
<p>Sample Text Sample Text Sample Text Sample Text Sample Text Sample Text.</p>
<p>Engage Now</p>
</div>
Seems you're not understanding the CSS you're using:
Remove the floats, replace the float:right with text-align: right in .nav-left
Remove position: absolute from .nav-left
Result below:
.navbar {
width: 100%;
}
.nav-left {
text-align: right;
width: 25%;
padding-top: 14px;
}
.feature {
border: 2px solid black;
padding: 25px;
background: url(https://static3.depositphotos.com/1005590/206/i/950/depositphotos_2068887-stock-photo-lightbulb.jpg);
background-repeat: no-repeat;
background-size: 100% 100%;
}
.navbar-Logo {
color: #dd845a;
text-decoration: none;
}
<div class="navbar">
<div class="nav-left">
<a class="navbar-Logo" href="#">LOGO</a>
</div>
</div>
<div class="feature">
<h1> Sample Text</h1>
<p>Sample Text Sample Text Sample Text Sample Text Sample Text Sample Text.</p>
<p>Engage Now</p>
</div>
Setting your .nav-bar element to position: absolute makes it leave the document flow, and so it will be rendered on top of the next <div>.
Using only float elements inside a block will make it 0-height with elements overflowing, and so rendered over following elements in document flow.
Change your .navbar css code to this:
.navbar
{
height: 120px;
}
I think what you are trying to do is that you like to position your link in the navbar to the right within the navbar and the feature div below it.
But the issue is the float property you are using here is taking the applied element out of the document flow, thus pushing the proceeding elements to take it's space.
Here you can use flexbox with justify content property set to flex end to achieve this. Never use float unless it's absolutely necessary.
<!DOCTYPE html>
<html>
<head>
<style>
.navbar
{
width: 100%;
border: 2px solid black;
padding: 35px;
}
.nav-left {
float: right;
width: 25%;
position: absolute;
padding-top: 10px;
}
.feature {
border: 2px solid black;
padding: 25px;
background: url(light_bulb.jpg);
background-repeat: no-repeat;
background-size: 100% 100%;
}
.navbar-Logo {
float:right;
color: #dd845a;
text-decoration: none;
}
</style>
</head>
<body>
<div class="navbar">
<div class="nav-left">
<a class="navbar-Logo" href="#">LOGO</a>
</div>
</div>
<div class="feature">
<h1> Sample Text</h1>
<p>Sample Text Sample Text Sample Text Sample Text Sample Text Sample Text.</p>
<p>Engage Now</p>
</div>
</body>
</html>

Align a button at the bottom of a grid

I am trying to assign the button : called 'go to form' right at the bottom of the grid i have done in CSS.
I have messed around with the relative position but this seems not to want to work. Any ideas guys ?
.item {
border: 1px rgb(160,160,255) solid;
}
img {
border-radius: 2px;
border: 1px solid #ddd;
height : 100px;
width : 80%;
}
p {
font-size: 18px;
}
h1 {
font-size: 14px;
}
</style>
<div class="grid-container">
<div class="item">
<img src="/sites/TeamSite/SiteAssets/placeholder.jpg" alt="Paris"/>​
<p> Sheep Dipper </p>
</div>
<div class="item">​<img src="/sites/TeamSite/SiteAssets/placeholder.jpg" alt="Paris"/>​​
<p> Laptop Request​ </p>
<h4> Use this form to request a new laptop</h4>
<button>Go to Form</button> </div>
<div class="item">​
<img src="/sites/TeamSite/SiteAssets/placeholder.jpg" alt="Paris"/>​
<p> New User Request </p>
</div>
<div class="item">
<img src="/sites/TeamSite/SiteAssets/placeholder.jpg" alt="Paris"/>​ ​​
<p> Permissions Management </p>
</div>
<div class="item">​​​
<img src="/sites/TeamSite/SiteAssets/placeholder.jpg" alt="Paris"/>​ ​<br/>​<br/>​<br/>​​<br/>​<br/></div>
</div>
try this one :
.grid-container{
position: relative;
}
.youBtnClass {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
}
Try this. Position absolute will place the button with respect to its immediate parent, and bottom attribute makes sure it starts at the very bottom of the parent.
You may add top margin in case your button lacks a gap on top of it.
.grid-container{
position: relative;
}
.youBtnClass {
position: absolute;
bottom: 0;
margin: 0 auto;
}

Two paragraphs changing positions inside a DIV

Hi! I am trying to place two paragraphs inside a DIV (a Name and a Job Position) for a responsive site.
.header {
min-height: 56px;
transition: min-height 0.3s;
max-width: 800px;
}
.header__inner {
margin-left: auto;
margin-right: auto;
float: left;
border: 3px solid #73AD21;
display: inline;
}
.header__text {
float: right;
border: 3px solid #73AD21;
display: inline;
}
<header class="header">
<div class="header">
<div class="header__inner">
<img class="header__logo" src="logo.jpg" alt="Logo">
</div>
<div class="header__text">
<p class="header__title">
NAME
</p>
<p class="header__subtitle">
CURRENT POSITION
</p>
</div>
</div>
</header>
Whenever I start playing with different sizes of screen both paragraphs switch places randomly. How can I make sure that they will stay in order?
This is how the page looks
Page with misplaced texts
And this is what I would like to accomplish
what I want to do
It seems you didn't post the CSS for the two elements whose position you want to switch, header__title and header__subtitle. But apparently they are both floated right. To make sure header__subtitle is NOT displayed to the left of header__title even if there is enough space, you can add this:
.header__subtitle {
clear: right;
}

Page layout gets messed up in different computers, auto-adjustment issue

This is probably has a really easy solution, since it is one of the most basic things in web design.
After a lot research and not finding the answer decided to ask it. Basically my webpage looks perfectly fine on my 13" Macbook but all the elements get messed up when I try to display it on my 27" desktop. I understand the core of the problem is that, when I set something to 300px, it covers much of the screen in 13" but just a little in 27" thus causing everything to sit on top of each other but I failed at finding a solution. Just to be clear, this is not a 100% issue of responsiveness, I don't want different layouts for different screens but I just want the same layout to look ok in many screens, just like you are resizing the page from the corners. Here is some of the code that I hope will be helpful. Also things that I have tried:
Using em instead of px. Not really helpful.
Using % instead of px. Not really helpful in cases like the first jumbotron where parent element doesnt have a defined height
HTML :
<body>
<div class="jumbotron">
<img src="images/banner.jpg" >
</div>
<div id="menu">
<ul class="nav nav-pills navbar-left">
<li> <p> 1 </p></li>
<li> <p> 2 </p> </li>
<li> <p> 3 </p></li>
<li> <p> 4 </p></li>
</ul>
<ul class="nav nav-pills navbar-right">
<li id="toleft"> <p> 5 </p> </li>
<li> <p> 6 </p></li>
<li> <p> 7 </p> </li>
<li> <p> 8 </p> </li>
</ul>
</div>
<!-- Script to fix navbar-->
<script>
$(document).ready(function(){
$(window).bind('scroll', function() {
var navHeight = $( window ).height() - 450;
if ($(window).scrollTop() > navHeight) {
$('#menu').addClass('fixed');
}
else {
$('#menu').removeClass('fixed');
}
});
});
</script>
<div id="displayframe">
<div id="display">
<img id="mainimage" src="images/col1.jpg" height="420" width="960" />
</div>
</div>
<!-- Script for changing images with time-->
<script>
$(document).ready(function(){
var imageArray = ["images/col2.jpg", "images/col3.jpg", "images/col4.jpg", "images/col5.jpg", "images/ban.jpg"];
var count = 0;
function loadImage(){
$("#mainimage").attr("src", imageArray[count]);
if(count == imageArray.length){
count = 0;
}else{
count = count + 1;
}
}
setInterval(function(){
loadImage();
}, 3000);
})
</script>
<div class="container">
<div id="head">
<p> RECENT NEWS </p>
</div>
</div>
<div class="newsfeed">
<ul>
<li>
<p style="float: left;"> <img src="images/chris.jpg" width="190px" /> </p>
<h2></h2>
<p id="bodypart">
</p>
</li>
<li class="newselement"><p style="float: left;"> <img src="images/city.jpg" width="190px" height="280px" /> </p>
<h2></h2>
<p id="bodypart">
</p></li>
<li class="newselement"><p style="float: left;"> <img src="images/alex.jpg" width="190px" height="280px" /> </p>
<h2></h2>
<p id="bodypart">
</p></li>
</ul>
</div>
CSS:
body{
background-color: black !important;
}
.jumbotron{
height: 320px;
background-color: black !important;
}
.jumbotron > img{
width: 100%;
margin-top: -50px;
}
#toleft{
left: -10px;
position: relative;
}
.nav p{
font-family: "Crimson Text";
font-size: 28px;
font-weight: bold;
z-index: 2;
}
.navbar-left{
margin-left: 20px;
position: relative;
}
.navbar-left li{
width: 120px;
}
.navbar-right{
left: -50px;
margin-left: 0px;
position: relative;
}
.navbar-right li{
width: 140px;
}
#menu{
background-color: black;
width: 99%;
margin-top: -110px;
}
.nav li p{
padding-left: 15px;
}
.fixed {
position: fixed;
top: 110px;
height: 50px;
z-index: 1;
background-color: black;
}
#display{
width: 960px;
height: 420px;
overflow: hidden;
margin: 30px auto 0px auto;
margin-top: 130px !important;
border-radius: 4px;
background-color: white;
}
#display ul{
position: relative;
margin: 0;
padding: 0;
height: 960px;
width: 420px;
list-style: none;
}
#display ul li{
position: relative;
display: block;
float: left;
margin: 0;
padding: 0;
width: 960px;
height: 420px;
}
#head > p{
font-family: "Crimson Text";
font-size: 30px;
font-weight: bold;
}
#head{
margin-top: 30px;
margin-left: 85px;
}
.tweets{
background-color: rgba(247,12,12,0.3);
margin-top: -800px;
margin-right: 50px;
border: 1px solid white;
border-color: white;
}
.newsfeed{
margin-left: 100px;
width: 60%;
height: 800px;
}
.newsfeed > ul{
list-style: none;
}
.newsfeed > img{
list-style: none;
display: inline-block;
position: absolute;
float: left;
}
.newsfeed > h2{
display: inline-block;
position: absolute;
margin-top: -50px;
margin-left: 50px;
float: right;
}
.newsfeed > li{
border-bottom: 1px white;
border-top: 1px white;
border-color: white;
height: 400px;
}
#bodypart{
font-size: 17px;
}
.newselement{
border-top: 1px solid white;
}
Actually this is responsive issue only because you are viewing your page on different screen or resolution. So if you want to create responsive website you have to add #media queries for different resolution.
-- #media queries
-- Outer div should keep fixed (px) or in percentage (%).
-- And inner div or content should wrap according to outer div width eg(width:100%).
-- Finally depend on different resolution change your css in #media queries.
Why use Px (pixels) which are pre-fixed? Instead play around with % (percents) which allow you to scale your webpage based on the user's screen. You could make your image 1600px wide which would be the full length of your MBP but for example on your Imac it only shows your image 1600px wide when really the Imac has 2880px for the screens width. Therefore you have another 1280px remaining to fill. If you were to use 100% it would fill 100% of who's ever screen is viewing your webpage. Hope this some what helps. You lost me on the 300px off.
I have setup a JSfiddle here.
I found a few things that you could add/modify to help improve your code and get things aligning better.
<img src="images/banner.jpg" > was not closed correctly you missed the / <img src="images/banner.jpg" />. Also you have no clearing tags anywhere in your code so of course when the width of your page scales out the elements on the page are going to stack up beside each other. I created a class;
<div class="clear"/>
.clear{
clear:both;
}
This i placed below each of your element sections so it will return them to the next line.
Next i placed a wrapper and a content div around your whole page content to center-align the content and make the page width 1000px (which is standard among most websites).
The images were not rendered into the JSfiddle becaise the paths are relative to your computer so i left them blank. If you want to see it working better please update the JSfiddle and i can help further.
-Epik

position of layers when resizing browser

when I'm resizing my browser-window the blue buttons go below the logo on the left, on the same line as the text "Welkom Bart" although they are two different layers. I want the text "Welkom Bart" to lower as well, so they are not on the same line. What do I need to add to my css?
html e.g.
<div id="mainmenu">
<div id="logo"><img ... /></div>
<div id="usermenu">Buttons</div>
</div>
<div id="maintitle">
<h2>Welkom Bart</h2>
<hr />
</div>
css
#mainmenu {
height: 100px;
position: relative;
}
#logo {
float: left;
width: 200px;
margin-right: 20px;
}
#usermenu {
float: right;
}
#maintitle {
margin-bottom: 20px;
}
#maintitle hr {
color: #56c2e1;
display: block;
height: 1px;
border: 0;
border-top: 1px solid #56c2e1;
margin: 10px 0;
}
Add clear:both to #maintitle =)
Add overflow:hidden to #mainmenu. This will cause its height to include all floated elements, such as your #usermenu element, allowing flow to continue underneath it.
Use this
<div id="maintitle" style="width:100%">
<h2>Welkom Bart</h2>
<hr />