CSS > Div float - css

I'm trying to design a layout like:
But as you can see on here: http://codepen.io/amonello/pen/zxemxb
<ul>
<li>
<div class="picture"></div>
<div class="name">name</div>
<div class="title">title</div>
<div class="title2">title2</div>
<div class="title3">title3</div>
<div class="phone">phone</div>
<div class="email">email</div>
</li>
</ul>
I've got some trouble doing it. I have a hard time understanding the float and the display.
Could any of you point me in the right direction?
I cannot add a wrapper around name/titles and phone/email.

Maybe this way
http://codepen.io/kazup/pen/raPRXz
ul, li {
margin: 0;
padding: 0;
list-style: none;
}
.picture {
float: left;
width: 73px;
height: 100px;
background: gray;
border: 1px solid black;
}
.name,
.title,
.title2,
.title3,
.phone,
.email {
float: left;
clear: left;
width: 90%;
border: 1px solid green;
}
#media screen and (min-width: 600px) {
.picture {
position: absolute;
float: none;
}
.name,
.title,
.title2,
.title3 {
margin-left: 90px;
width: 35%;
}
.phone,
.email {
float: none;
clear: none;
margin-left: 55%;
width: 35%;
border: 1px solid red;
}
}
<ul>
<li>
<div class="picture"></div>
<div class="name">name</div>
<div class="title">title</div>
<div class="title2">title2</div>
<div class="title3">title3</div>
<div class="phone">phone</div>
<div class="email">email</div>
</li>
</ul>
Only the .picture has absolute positioning, divs are floated, except for the phone and email in desktop view.
Don't care about the widths of the divs, it's just nicer this way.

Related

Menu move effect in CSS

Yo.
I have some question to you guys.
Here is my test code:
*{
border:1px solid #333;
width:100%;
max-width: 1240px;
margin: 0 auto;
}
.menu{
width:60%;
border:1px solid #444;
float:left;
text-align:center
}
.menu ul{
display:flex;
justify-content: center;
flex-flow: row;
float:left;
}
.topnav{
width:50px;
float:left;
}
.topnav:hover,.topnav:focus{
transition: 0.6s linear;
width: 100px;
float:left;
}
.something{
border:1px solid #000;
width: 50px;
float:right;
}
.topnav-something{
display: block;
width: auto;
float:right;
margin-right:20%;
}
<div class="content">
<div class= "menu">
<ul>
<li>ONE</li>
<li>Second</li>
<li>Third</li>
</ul>
</div>
<div>
<div class="topnav-something">
<div class="topnav">
<input type="text" placeholder="Search..">
</div>
<div class="something">
SOME TEXT
</div>
</div>
</div>
How can I receive move-menu effect like on this page?(search hover)
http://kindsgut.de/
And why when I clicked on this input he decreases?
Somebody know how to fix it?
I dont know what I doing wrong.
Have a nice day!
First, you set the transition only on the hovered event, that's why when you mouseout the animation has no transition. So you need to set the transition on the default state not on the hover state of the element.
Second, you should add the hover event on the outer div that contains both the some text and the input . So in your case on the .topnav-something
Also, add width:0 to your input (.topnav) as a initial value. So it can transition from 0 to 100px.
So in the end your code will look like this
( i removed the margin-right:20% from topnav-something so it will fit the small screen of the snippet )
* {
border: 1px solid #333;
width: 100%;
max-width: 1240px;
margin: 0 auto;
}
.menu {
width: 60%;
border: 1px solid #444;
float: left;
text-align: center
}
.menu ul {
display: flex;
justify-content: center;
flex-flow: row;
float: left;
}
.something {
border: 1px solid #000;
width: 50px;
float: right;
}
.topnav-something {
display: block;
width: auto;
float: right;
margin-right: 0%;
}
.topnav {
width: 0px; /*added*/
float: left;
transition: 0.6s linear; /*added*/
}
/*added*/
.topnav-something:hover .topnav {
width: 100px;
}
<div class="content">
<div class="menu">
<ul>
<li>ONE</li>
<li>Second</li>
<li>Third</li>
</ul>
</div>
<div>
<div class="topnav-something">
<div class="topnav">
<input type="text" placeholder="Search..">
</div>
<div class="something">
SOME TEXT
</div>
</div>
</div>
You'd need to set your input to a width of 0 , then depending what you want to trigger it (text, or the container) you define the width on hover.
You can also apply a transition to the container, and to the input for the slide effect.
<div class="content">
<div class="menu">
<ul>
<li>ONE</li>
<li>Second</li>
<li>Third</li>
</ul>
</div>
<div>
<div class="topnav-something">
<div class="topnav">
<input class="search-field" type="text" placeholder="Search..">
</div>
<div class="something">
SOME TEXT
</div>
</div>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.menu {
width: 60%;
float: left;
text-align: right;
outline: 1px solid red;
}
.menu ul {
display: flex;
justify-content: right;
flex-flow: row nowrap;
/* float: left; */
}
.menu li {
display: inline;
padding: 10px;
}
.topnav-something {
/* display: block; */
padding: 10px;
width: 40%;
float: right;
/* margin-right: 20%; */
transition: width 0.5s;
outline: 1px solid blue;
}
.search-field {
width: 0;
transition: all 0.5s;
}
.topnav-something:hover input,
.topnav-something:focus input {
width: 140px;
}
.topnav {
display: inline-block;
}
/* .topnav {
width: 50px;
float: left;
} */
/* .topnav:hover,
.topnav:focus {
transition: 0.6s linear;
width: 100px;
float: left;
} */
.something {
display: inline-block;
/* border: 1px solid #000; */
/* width: 50px; */
/* float: right; */
}
I've created a demo for you here: https://codepen.io/blueocto/pen/zWoNZj
#Mihal If my answer did help solve your issue, I'd really appreciate the upvote, thank you.

Faking left and right margins for webkit scrollbar?

I have a dropdown that needs a scrollbar with left and right margins. I'm using -webkit-scrollbar, but as far as I can tell, it only supports margins along the scroll axis, so I've been approximating horizontal margins with a right margin on the items inside the container, and some right padding on the outer div, as you can see in my code.
However, this creates unsightly extra-wide right padding when the container doesn't have enough items to be scrollable (see the second dropdown in my example). I want the right edge to look the same as all the other edges when there's no scrollbar.
.dropdown {
width: 360px;
padding-right: 10px; /* pseudo-right-margin for scrollbar */
background-color: green;
padding-bottom: 10px;
max-height: 365px;
margin-bottom: 20px;
}
.itemContainer {
max-height: 355px;
overflow-y: auto;
padding-left: 10px;
padding-top: 10px;
}
.item {
background-color: white;
height: 51px;
padding: 10px;
margin-bottom: 10px;
margin-right: 10px; /* pseudo-left-margin for scrollbar */
}
.item:last-of-type {
margin-bottom: 0px;
}
#media screen {
.itemContainer::-webkit-scrollbar {
width: 6px;
border-radius: 2px;
}
.itemContainer::-webkit-scrollbar-thumb {
border-radius: 2px;
background-color: black;
border: solid red 10px;
}
.itemContainer::-webkit-scrollbar-track {
margin-top: 10px;
background-color: yellow;
width: 6px;
}
}
<div class="dropdown">
<div class="itemContainer">
<div class="item">thing</div>
<div class="item">thing</div>
<div class="item">thing</div>
<div class="item">thing</div>
<div class="item">thing</div>
</div>
</div>
<div class="dropdown">
<div class="itemContainer">
<div class="item">thing</div>
<div class="item">thing</div>
<div class="item">thing</div>
<div class="item">thing</div>
</div>
</div>
My only idea for a css-only solution is somehow using an .item:nth-child(5) pseudo-selector, since the dropdown becomes scrollable with 5 or more items, but I don't know what property I would give it.
I already have a javascript solution but I want to do this with just css, if that's possible. (Also, always showing the scrollbar is not an acceptable solution.)
All right. Was not so hard, but unfortunately there is a lot of extra html in my solution. Please tell if need comments and/or explanation of something.
Result is below.
.dropdown {
width: 360px;
background-color: green;
padding-bottom: 10px;
max-height: 365px;
margin-bottom: 20px;
}
.itemContainer {
max-height: 355px;
overflow-y: auto;
padding-left: 10px;
padding-top: 10px;
margin-right: 10px;
}
.itemContainer>div {
display: table;
width: 100%;
}
.item {
display: table-row;
}
.item>div{
display: table-cell;
vertical-align: top;
padding-bottom: 10px;
}
.item:last-child>div {
padding-bottom: 0;
}
.item > div:nth-child(1) {
width: 100%;
}
.item>div:nth-child(1)>div{
background-color: white;
padding: 10px;
height: 51px;
}
.item:nth-child(5) > div:nth-child(2) > div {
width: 10px;
}
#media screen {
.itemContainer::-webkit-scrollbar {
width: 6px;
border-radius: 2px;
}
.itemContainer::-webkit-scrollbar-thumb {
border-radius: 2px;
background-color: black;
border: solid red 10px;
}
.itemContainer::-webkit-scrollbar-track {
margin-top: 10px;
background-color: yellow;
width: 6px;
}
}
<div class="dropdown">
<div class="itemContainer"><div>
<div class="item"><div><div>thing</div></div><div><div></div></div></div>
<div class="item"><div><div>thing</div></div><div><div></div></div></div>
<div class="item"><div><div>thing</div></div><div><div></div></div></div>
<div class="item"><div><div>thing</div></div><div><div></div></div></div>
<div class="item"><div><div>thing</div></div><div><div></div></div></div>
</div></div>
</div>
<div class="dropdown">
<div class="itemContainer"><div>
<div class="item"><div><div>thing</div></div><div><div></div></div></div>
<div class="item"><div><div>thing</div></div><div><div></div></div></div>
<div class="item"><div><div>thing</div></div><div><div></div></div></div>
<div class="item"><div><div>thing</div></div><div><div></div></div></div>
</div></div>
</div>
In a few words, I added table layout. When there are more than 4 rows, the second column's width is set to 10px.

How to make image buttons stay in place when re sizing web browser

This is my image-button for my website. http://puu.sh/cK7Sf/6309c39cdb.jpg When I re-size my browser it goes over here http://puu.sh/cK7VU/f17dafcc41.jpg
Here is my code
HTML
<div class="Nav">
<div id="buttons">
<div id="home_button"></div>
CSS
#home_button {
background-image: url("home.png");
background-repeat:no-repeat;
background-size: 100%;
width: 150px;
height: 60px;
position: absolute;
top: 196px;
left: 502px;
z-index: 10;
}
I am new to web developing so please don't hate :)
I've created an example to show you what a basic nav bar styling looks like.
Demo on dabblet
HTML:
<body>
<!--Navigation-Bar-Container-->
<div class="nav-container">
<!--Navigation-Bar-Item-Wrapper-->
<div class="nav">
<!--Items-->
<div id="menu-item-1" class="menu-item">Item 1</div>
<div id="menu-item-2" class="menu-item">Item 2</div>
<div id="menu-item-3" class="menu-item">Item 3</div>
<div id="menu-item-4" class="menu-item">Item 4</div>
<div id="menu-item-5" class="menu-item">Item 5</div>
<hr />
</div>
</div>
<!--Content-->
</body>
CSS:
body {
background: url(http://s25.postimg.org/b6q25p4p7/black_thread.png) repeat black;
}
hr {
color: #777777;
}
.nav-container {
top: 20px;
position: relative;
width: 100%;
height: 40px;
text-align: center;
}
.nav {
width: 100%;
height: 40px;
maring: 0 auto;
text-align: center;
}
.menu-item {
display: inline-block;
width: 50px;
padding-left: 30px;
padding-right: 30px;
padding-top: 10px;
padding-bottom: 10px;
color: #777777;
}
.menu-item:hover {
background-color: black;
cursor: pointer;
border-radius: 2px;
}
Here is what I would do, some adjustment needed, not sure why the button is absolutely positioned, or what the background image is for, but here goes:
HTML:
<ul class='menu'>
<li>Link 1</li>
<li>Link 2</li>
</ul>
CSS:
.menu {
list-style-type: none;
}
.menu li {
display: inline-block;
border: 0.2em solid black;
border-radius: 10%;
padding: .5em;
background: linear-gradient(lightblue, blue);
}
.menu li a {
text-decoration: none;
color: black;
}

How can I center my logo in the navigation using the Responsive Grid System?

I'm wondering how to properly center my Logo having it within the top navigation. When it condenses everything gets messed up. I want it to turn into one of those 'square' drop down menus.
I want the links to be 'even' on either side.
HTML:
<div id="navigationcontainer">
<nav>
<ul>
<div class="col span_1_of_9">
<li>home</li>
</div>
<div class="col span_1_of_9">
<li>about</li>
</div>
<div class="col span_1_of_9">
<li>services</li>
</div>
<div class="col span_3_of_10">
<li><a id="logo" href="/"><img src="images/CarpetRepair_Logo.png" alt="Logo"></a></li>
</div>
<div class="col span_1_of_9">
<li>photos</li>
</div>
<div class="col span_1_of_9">
<li>contact</li>
</div>
<div class="col span_1_of_9">
<li><a id="FB" href="/"><img src="images/FB_Logo.jpg" alt="Facebook"></a></li>
</div>
</div>
</ul>
</nav>
CSS:
#logo {
width: 254px;
height: 170px;
margin: 0 auto;
margin-top: -34px;
padding-top: 0px;
}
a#logo {
float:left;
min-width: 50%;
width:100%; }
#FB {
}
#navigationcontainer {
width: 100%;
height: 74px;
border-bottom: 1px solid #000;
background: #06060C left top;
}
nav {
clear: both;
width: 80%; /* 1000px / 1250px */
font-size: 0.8125em; /* 13 / 16 */
max-width: 92.3em; /* 1200px / 13 */
margin: 0 auto;
margin-top: 34px;
color: #c39a6e;
}
nav ul {
font-family: 'ostrich_sansmedium';
font-size: 1.45em;
font-weight: 500;
letter-spacing: 4px;
list-style: none;
}
nav ul li {
display: block;
position: relative;
float: left;
}
nav li ul {
display: none;
}
nav ul li a {
margin-top: 8px;
display: block;
padding: 7px 15px 3px 15px;
text-align: center;
}
Thank You!
Try this
#logo {
margin-top: -34px;
padding-top: 0px;
margin: auto;
left: 0;
right: 0;
}
a#logo {
float: left;
min-width: 50%;
width: 100%;
position: fixed;
}
HTML:
<li><a id="logo" href="/"><img src="/images/srpr/logo11w.png" alt="Logo" width="170px"></a></li>
jsfiddle: http://jsfiddle.net/yka0kgvz/

Inner div aren't pushing other div, cant get clear: both; to work

I have some problems with <div>s. The inner <div> (content div) won't push the outer <div> (wrap_content).
Let me post the code so that you have a chance to see what could be wrong.
style.css
* {
padding: 0px;
margin: 0px;
}
body {
background: #e2e2e2;
color: #f2f2f2;
font-family: Arial;
}
#wrap_design {
width: 1139px;
}
#wrap_content {
float: right;
max-width: 963px;
height: 100%;
border-right: 8px solid #2d2828;
border-left: 8px solid #2d2828;
border-bottom: 8px solid #2d2828;
padding-bottom: 10px;
}
#header {
height: 236px;
width: 963px;
background-color: #2d2828;
}
#headerimg{
z-index: 1;
margin-left: -26px;
}
#loggedin_box {
min-height: 230px;
width: 160px;
background: #2d2828;
float: left;
margin-top: 236px;
position: static;
padding-bottom: 5px;
}
#loggedin_box_green {
height: 30px:
width: 150px;
background: #73aa09;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 5px;
padding-right: 5px;
margin-left: 10px;
margin-top: 10px;
margin-bottom: 10px;
margin-right: 10px;
letter-spacing: 2px;
}
#loggedin_box ul {
border: none;
}
#loggedin_box ul li {
list-style: none;
text-align: left;
}
#loggedin_box ul li a {
font-family: Arial;
font-size: 14px;
color: #b1b2b2;
text-decoration: none;
padding-left: 5px;
}
#menu_container {
margin: 0px 0px 0px 0px;
background: #2d2828;
font-family: Arial;
width: 100%;
margin: 0px auto;
height: 65px;
}
#content {
color: black;
vertical-align: top;
height: 100%;
margin-bottom: 10px;
clear: both;
}
#content-sidebar {
border-left: 2px solid #2d2828;
float: right;
width: 285px;
max-width: 285px;
height: 100%;
}
index.php
<html>
<head>
<link rel="shortcut icon" href="images/nfgico.ico" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="/style/style.css" type="text/css" />
</head>
<body>
<CENTER>
<div id="wrap_design">
<div id="loggedin_box">
<?php
if($_SESSION['username'] == "") {
?>
<div id="loggedin_box_green">Log ind</div>
<div style="text-align: left; padding-left: 10px;">
<form action="login_check.php" method="post">
<input type="text" value="Brugernavn" name="username" style="width: 140px;" onclick="this.value=''"><br /><br />
<input type="password" value="password" name="password" style="width: 140px;" onclick="this.value=''"><br /><br />
<font style="font-family: Arial; font-size: 12px;">Husk mig:</font><input style="margin-left:15px;" type="checkbox" name="rememberme" class="checkbox" value="1" /><br /><br />
<input type="submit" value="Log ind"><br /><br />
</form>
<ul>
<li>Glemt kodeord</li>
<li>Opret bruger</li>
</ul>
</div>
<?php
} else {
?>
<div id="loggedin_box_green">Network</div>
<ul>
<li>Wall</li>
<li>Profil</li>
<li>Chat</li>
<li>Achievements</li>
<li>Clanside</li>
<li>Søg modstander</li>
<li>Søg spil</li>
<li>Log ud</li>
</ul>
<?php
}
?>
</div>
<div id="wrap_content"> <!-- This is the one that needs to be pushed -->
<div id="header">
<img src="/images/banner.png" id="headerimg">
</div>
<div id="menu_container">
<div id="droplinetabs1" class="droplinetabs">
<ul>
<li><span>Forside</span></li>
<li><span>Nyheder</span>
<ul>
<li>Seneste</li>
<li>lol</li>
<li>loool</li>
<li>loool</li>
</ul>
</li>
<li><span>Artikler</span></li>
<li><span>Spil</span></li>
<li><span>Turneringer</span></li>
<li><span>Clan</span></li>
<li><span>Streams</span></li>
<li><span>Webshop</span></li>
</ul>
</div>
</div>
<!-- Content/brødtekst -->
<div id="content">
CONTENT GOES HERE THIS IS WHAT NEED TO PUSH
</div>
</div>
</CENTER>
</body>
</html>
There is some part of the code from index.php that I didn't post because I hope you don't need it :)
I really hope someone can help me!
ps. I have done some research on the internet, and learned that I should use clear: both; but I really can't get it to work.
Remove the height: 100% from your #wrap_content style (it's causing problems), and then to ensure it wraps around any float elements, add width and overflow as folows:
#wrap_content {
float: right;
max-width: 963px;
border-right: 8px solid #2d2828;
border-left: 8px solid #2d2828;
border-bottom: 8px solid #2d2828;
padding-bottom: 10px;
width: auto; /* Must use this for overflow to do what you want */
overflow: hidden; /* This, plus width, causes box to stretch around floated elements inside of it */
}
Just as a little note, there's a fair amount of unnecessary css going on in there. I'd encourage you to go through it carefully and modify/remove it. You could do what you are after with half of the amount of css.
REMOVE all of the "height:100%;" everywhere - if does not do what you think it does.
I would suggest removing your CENTER and making your #wrap_design be like this:
#wrap_design
{
margin: 0 auto;
width: 1139px;
}
This will center your wrapper - I'd strongly advise against CENTER. If you want to change the margin top of this wrapper (ie 20px from top and bottom) do this margin: 20px auto;.
You don't need to use clear: both; necessarily. In a wrapper of a float (or multiple floats) you can just put overflow: hidden (same effect) and no additional markup is needed:
<style type="text/css">
.container
{
background: #CCC;
border: 1px solid #ddd;
overflow: hidden;
width: 400px;
}
.left
{
float: left;
}
.right
{
float: right;
}
</style>
<div class="container">
<div class="left">
this will float left
</div>
<div class="right">
this will float left
</div>
</div>
If you didn't have the "overflow: hidden" in this example you wouldn't see the "#CCC" background color in the .container.
This is the same as doing clear way (but again above is better because less markup):
<style type="text/css">
.container
{
background: #CCC;
border: 1px solid #ddd;
width: 400px;
}
.left
{
float: left;
}
.right
{
float: right;
}
.clear
{
clear: both;
}
</style>
<div class="container">
<div class="left">
this will float left
</div>
<div class="right">
this will float left
</div>
<div class="clear"></div>
</div>
Clear method is good in a case like this (when you want a child "outside of the parent"):
<style type="text/css">
.container
{
background: #CCC;
border: 1px solid #ddd;
margin: 50px auto;
width: 400px;
}
.left
{
float: left;
}
.right
{
background-color: #333;
color: #FFF;
float: right;
margin: -10px -40px 0 0;
}
.clear
{
clear: both;
}
</style>
<div class="container">
<div class="left">
this will float left
</div>
<div class="right">
this will float left
</div>
<div class="clear"></div>
</div>
But again, I wouldn't recommend that markup, if your design could be different you can use clear like this too:
<style type="text/css">
.container
{
background: #CCC;
border: 1px solid #ddd;
margin: 50px auto;
width: 400px;
}
.left
{
float: left;
width: 200px;
}
.right
{
background-color: #333;
color: #FFF;
float: right;
margin: -10px -40px 0 0;
width: 240px;
}
.full
{
background: #f5f5f5;
clear: both;
margin: 20px auto;
text-align: center;
width: 90%;
}
</style>
<div class="container">
<div class="left">
this will float left
</div>
<div class="right">
this will float left
</div>
<div class="full">
this is full sized
</div>
</div>
If you follow these example, you should solve your problem :)

Resources