There a few HTML elements that I want to put in a line. This is the code I have used.
<input type = "text" className="search" placeholder="Search"></input>
<a href="/">
<img src="logo.svg"></img>
<h3>NameOfTheWebsite</h3>
</a>
SignIn
SignOut
But the output for this code is like this.
I want to put those elements in the same line and the logo should be top of the website name. How do I achieve this?
FlexBox is a really useful thing in such situations. In the following snippet, I have used some flexboxes just to get you familiar with it. But this is something that you should definitely master and use in your CSS layouts. MDN Web docs have a really great tutorial for that.
.home-page{
display:flex;
margin:15px;
}
.controls{
display:flex;
justify-content:space-between;
align-items:center;
}
.signing-buttons{
display:flex;
}
.signing-buttons a{
margin:5px;
padding:10px;
border:2px solid red;
border-radius:4px;
}
<a class="home-page" href="/">
<h3>NameOfTheWebsite</h3>
<img src="logo.svg"></img>
</a>
<div class="controls">
<input type = "text" className="search" placeholder="Search"></input>
<div class="signing-buttons">
SignIn
SignOut
</div>
</div>
You can use flexbox to achieve this. Just a minimalistic example to illustrate my point is shown below. You can control how much space each item will occupy and a lot of other things.
.row {
display:flex;
}
.search {
flex:1;
border:1px solid black
}
.name {
flex:1;
border:1px solid black
}
<div class='row'>
<div class='search'>Search Box</div>
<div class = 'name'>Name</div>
</div>
<div class='row'>Next line</>
Related
Sorry for my poor English.
I have a span (like $) and an input, when user inputs something, the span and input should always stay centered horizontally.
I want it looks like the row 1 in the code below. But in fact I can just code it like row 2.
I want a solution, it will be better to be without js.
I've read about this article(HTML text input field with currency symbol) but it doesn't solve my problem for it doesn't center anything.
.main{
display:flex;
align-items:center;
justify-content:center;
}
.this-should-be-input{
font-size:36px;
}
.the-input{
border:none;
text-align:center;
}
<div class="main">
<span style="font-size:24px;">$</span>
<div class="this-should-be-input">
12345
</div>
</div>
<div class="main">
<span style="font-size:24px;">$</span>
<input class="this-should-be-input the-input" value="12345"/>
</div>
You could just put the $ in the value, and it will move with the value.
.main{
display:flex;
align-items:center;
justify-content:center;
}
.this-should-be-input{
font-size:36px;
}
.the-input{
border:none;
text-align:center;
}
<div class="main">
<span style="font-size:24px;">$</span>
<div class="this-should-be-input">
12345
</div>
</div>
<div class="main">
<input class="this-should-be-input the-input" value="$12345"/>
</div>
But if you wanted it there permanently you wouldn't be able to center your input field without javascript
Your code is center aligning both the $ sign and the text input. The problem is that you have not specified any width for the input field. You can fix this by specifying the width to the input field.
Hope it helps!
.main{
display:flex;
align-items:center;
justify-content:center;
}
.this-should-be-input{
font-size:36px;
}
.the-input{
border:none;
text-align:center;
width:24%;
}
<div class="main">
<span style="font-size:24px;">$</span>
<div class="this-should-be-input">
12345
</div>
</div>
<div class="main">
<span style="font-size:24px;">$</span>
<input class="this-should-be-input the-input" value="12345"/>
</div>
this is my first question and I hope I would get some help here.
I have made this HTML page that has 5 DIV's mainly:
Header
Content
Footer
Content contains
Left
Right
The Left and Right Div's float on Left and right respectively.When I put something content div with an H1 tag the div's get somewhat disorted and I get a approx. 10px space between the header and content section, somewhat like this:
Disorted
However the original one should be:
Original
<body>
<a target="_blank"><div id="main" >
<div id="header" >
<a style="color:#000000" href="home.html">Home</a>
<a style="color:#000000" href="about.html">about</a>
<a style="color:#000000" href="Our customers.html">Our Customers</a>
<a style="color:#000000" href="Career.html">Careers</a>
<a style="color:#000000" href="Contact us.html">Contact us</a>
</div>
<div id="content">
<div id="left" ></div>
<div id="right" ></div>
Home
</div>
<div id="footer">
<a style="color:#FFFFFF" href="home.html">Privacy Policy</a>|
<a style="color:#FFFFFF" href="Feedback.html">Feedback</a>|
<a style="color:#FFFFFF" href="disclaimer.html">Disclaimer</a>|
<a style="color:#FFFFFF" href="Manadatory.html">Manadatory Disclosure</a>|
<a style="color:#FFFFFF" href="sitemap.html">Site Map</a>|
</div>
</div></body>
Here is my CSS Code:
#main
{
height:900px;
background-color:#000000;
}
#header
{
height:100px;
background-color:#00FF00;
padding:70px;
padding-right:70px;
font-size:30px;
text-align:center;
background-image:url(Images/text3.jpg);
padding: 50px;
}
#content
{
height:700px;
background-color:#FFFFFF;
}
#left
{
float:left;
height:700px;
background-color:#FF0000;
width:150px;
background-image:url(Images/navbar2.jpg);
}
#right
{
float:right;
height:700px;
background-color:#FF0000;
width:150px;
background-image:url(Images/navbar2.jpg);
}
#footer
{
padding:50px;
padding-right:70px;
font-size:20px;
text-align:center;
height:100px;
background-image:url(Images/footer.jpg);
}
Fixing position of the div's using position hasn't helped. Thanks for any help in advance :)
Right click and inspect element on your browser and check the divs. You should see what's happening to it. Most likely it will be some default styling that's giving some margins. That's why most people use some kind of reset.css as a clean base. I imagine the default css is applying margins to the <p> and <h1> tags.
Maybe try adding something like:
h1 {
margin:0;
}
Obviously you could specify only certain margins rather than all or .content h1{} to just apply styling to the headers within the content block.
I'm working on a webpage and I want it to look like those magnets (or tiles, whatever you like to call them) in the start menu of Windows 8. After some work, I got the following:
html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="styles.css" />
<link href='http://fonts.googleapis.com/css?family=Bad+Script|Architects+Daughter|Comfortaa|Handlee' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="banner-div">
</div>
<div class="row">
<div class="magnets">
Some text
</div>
<div class="magnets">
</div>
<div class="magnets">
</div>
</div>
<div class="row">
<div class="magnets">
</div>
<div class="magnets">
</div>
<div class="magnets">
</div>
</div>
</body>
</html>
styles.css
html, body {
background:#f8e4e4;
font-family:'Bad Script';
font-size:medium;
text-align:center;
width:100%;
}
.magnets {
border:5px solid black;
height:300px;
width:300px;
text-align:center;
margin-right:2%;
margin-top:2%;
display:inline-block;
}
.row {
width:100%;
margin-top:1%;
}
But when I open it with IE, something weird happens. The first magnet (The one with Some text) does not align with the other magnets. When I delete the text and run it again it's back to normal again. It seems like that it is the text that pulls the magnet downwards. I think this is very abnormal and clearly this should not happen.
I also tried this with Google Chrome but the result is the same as that of IE.
Add overflow:hidden; in .magnetsDemo
.magnets {
border:5px solid black;
height:300px;
width:300px;
text-align:center;
margin-right:2%;
margin-top:2%;
display:inline-block;
overflow:hidden;
}
I tested the output in Chrome, Mozilla and IE, It worked fine. If you remove width:100%; from html, body , Its giving similar output
Or you could set vertical-align: bottom; on the .magnet class.
EDIT:
The reason for this is that, because the .magnet classed blocks are redefined as being inline-blocks, the blocks are treated as though they were text, so they all have their bottoms line up on a base line by default.
Whenever one of these blocks contains text, the default "anchor" to the base line shifts from the bottom of the block itself to the text inside the block, and the block itself just becomes a kind of border around the text without meaningful anchor points. To force the block to realign with its siblings, you need to override this default behaviour by explicitly defining vertical-align: bottom; on the block so that it will align to the bottom of the base line, just like text will align itself to the bottom of the base line by default, since text is also displayed inline.
Some more reading on this:
http://phrogz.net/css/vertical-align/
https://css-tricks.com/almanac/properties/v/vertical-align/
/EDIT
Link to the result: http://jsfiddle.net/e1og1m8v/, or a local runnable snippet to elaborate:
html, body {
background:#f8e4e4;
font-family:'Bad Script';
font-size:medium;
text-align:center;
width:100%;
}
.magnets {
border:5px solid black;
height:100px;
width:100px;
text-align:center;
margin-right:2%;
margin-top:2%;
display:inline-block;
vertical-align: bottom;
}
.row {
width:100%;
margin-top:1%;
}
<body>
<div id="banner-div">
</div>
<div class="row">
<div class="magnets">
Some text
</div>
<div class="magnets">
</div>
<div class="magnets">
</div>
</div>
<div class="row">
<div class="magnets">
</div>
<div class="magnets">
</div>
<div class="magnets">
</div>
</div>
</body>
I'm developing an application with Ionic and Angular, and i'm trying to rewrite the css of the list items to display data the way I want.
Here is what I want it to look like :
But I'm having some problem setting the padding between the images, it doesn't work at all.
and also the automatic height, I'm using ng-if for wether display the news or not, when not displaying the news I have this empty div showing
Here is my code :
<div class="list">
<div class="item item-divider">
Teams
</div>
<div class="item" style="height:150px;" ng-repeat="team in teams">
<img ng-src="https://upload.wikimedia.org/wikipedia/en/thumb/4/47/FC_Barcelona_(crest).svg/1010px-FC_Barcelona_(crest).svg.png" style="position:absolute; top:10px; left:10px; width:25px; height:25px" >
<p style="left:50px; position:absolute; color:black; font-size:16px; top:12px">{{team.name}}</p> <p style="right:30px; position:absolute; top:12px"> Tout</p>
<i class="icon ion-chevron-right" style="position:absolute; right:10px; color:grey; top:12px"></i>
<ion-scroll direction="x" scrollbar-x="false" style="width:100%; position:absolute; top:50px" ng-if="team.news=='true'">
<div style="height:85px; width:500px; position:relative " >
<div style="width:110px; display: inline-block; position:static; padding-right:5px" ng-repeat="item in items">
<img src="http://fr.starafrica.com/football/wp-content/blogs.dir/2/files/2015/07/sporever/272576_PALERME_LAZAAR_220215-615x340.jpg" style="height:65px; width:110px">
<p style="font-size:9px; color:black">News1</p>
</div>
</div>
</ion-scroll>
</div>
Here is also a plunker DEMO
You can give padding-right to img.
Hi Now you can used to this css i see your demo and suggest to you used to this css
.scroll > div > div + div {
margin-left: 5px;
}
You can do what others have said or
Try this.
.scroll img {
padding-left: 2px;
}
Demo here:http://codepen.io/anon/pen/LVXeRy
I am trying to create a simple menu using the following html setup:
<div class="container">
<div class="container-cell">
<a href="play.html">
<div class="menu-option no-margintop">
<div class="play-icon">
<span class="helper"></span><img src="./img/icon_1.png"/>
</div>
<div class="menu-text"><span>Play</span></div>
</div>
</a>
<a href="index.html">
<div class="menu-option">
<div class="play-icon">
<span class="helper"></span><img src="./img/icon_3.png"/>
</div>
<div class="menu-text"><span>Highscore</span></div>
</div>
</a>
<a href="index.html">
<div class="menu-option">
<div class="play-icon">
<span class="helper"></span><img src="./img/icon_2.png"/>
</div>
<div class="menu-text"><span>FAQ</span></div>
</div>
</a>
</div>
</div>
In the process of creating this, I made a switch from hard pixels to percentages. Whereas the pixel version of setting hights works, it does not seem to work in percentages. The hight for one particular class, menu-option, does not seem to get picked up by the browser.
I have been searching for a while, and the only solutions I came across, was setting a height to both the body and html (100%). I have also set a height to any of the container-elements.
See css below:
html, body{
height:100%;
}
.container {
display:table;
width:100%;
height:70%;
}
.container-cell {
display:table-cell;
vertical-align: middle;
height:100%;
}
.menu-option{
width:90%;
margin-left:5%;
border-radius:10px;
background-color:rgba(17,23,28,0.2);
height:6.94%;
margin-top:5%;
font-size:150%;
}
Why is the browser not picking up on the height in percentage and how can make it use the height in percentage?
Add display: inline-block; to your menu-option class for the height property to work. Something like this:
.menu-option{
display: inline-block;
width:90%;
margin-left:5%;
border-radius:10px;
background-color:rgba(17,23,28,0.2);
height:6.94%;
margin-top:5%;
font-size:150%;
}
Here's a jsfiddle of the above: https://jsfiddle.net/AndrewL32/e0d8my79/17/