How to align an image to the right with in CSS and HTML?

-1

@charset="UTF-8";
@import url('https://fonts.googleapis.com/css?family=Krub');
@import url('https://fonts.googleapis.com/css?family=Varela+Round');
/* CSS Document */

header {
	width:1900px;
	height:100px;
	margin:auto;
	background-color:black;
	font-family: 'Krub', sans-serif;
	color:white;
}
body{
    background-color: #363636;
}

nav {
	width:1900px;
	height:50px;
	margin:auto;
	background-color:#ff4425;
	font-family: 'Krub', sans-serif;
	position:absolute;
	display:table;
	top:100px;
	right:0px;
    border:none;
}

.button{
	float:left;
	color:black;
	border:none;
	background-color:#ff4425;
	transition-duration:1s;
	height:50px;
	width:100px;
	font-family: 'Krub', sans-serif;
	align-content: center;
    margin-left: auto;
    margin-right: auto;
}

.computadores{
	float:left;
	color:black;
	border:none;
	background-color:#ff4425;
	transition-duration:1s;
	height:50px;
	width:150px;
	font-family: 'Krub', sans-serif;
	
}

.computadores:hover{
	background-color:white;
	color:black;
	border: 0.5px solid #2f3542;
	font-family: 'Krub', sans-serif;
	cursor:pointer;
}

.button:hover{
	background-color:white;
	color:black;
	border: 0.5px solid #2f3542;
	font-family: 'Krub', sans-serif;
	cursor:pointer;
	-webkit-transition:1s; /*Chrome e Safari */
}

#crono {
    color:#F26B38 ;
    background-color:#2A2A2A;
    font-family: 'Varela Round', sans-serif;
    font-size: 30px;
    border:none;
    
}
    
}

#destaque {
    font-family: 'Varela Round', sans-serif;
    background-color:white;
    color:black;
    display:table;
}

section{
	height:1000px; 
	width:600px;
	color:white;
}
atricle.crono{
	height:500px;
	width:300px;
	
	font-family: 'Krub', sans-serif;
}

.saiba{
    background-color:white;
    color:black;
    border:none;
    width:200px;
    height:100px;
    font-size: 28px;
    font-family: 'Krub', sans-serif;
    transition:0.5s;
    border:5px solid black;
    
}

.saiba:hover{
    color:white;
    background-color:black;
    border:none;
    width:200px;
    height:100px;
}

#bulldog{
    color:#e84118;
    background-color:#2A2A2A;
    font-family: 'Varela Round', sans-serif;
    border:none;
    margin-left:800px;
    
    
}
<!Doctype HTML>
<html>
<head>

<meta charset= "UTF-8"/>
<title>Alfa Hardware</title>

<link rel="stylesheet" type="text/css" href="_css/style.css">

</head>
<body>
<div>

<header>
<h1 align="center" >ALFA HARDWARE</h1>
</header>

<nav>
<a href="index.html"><button class="button">INÍCIO</button></a>
<a href="_sections\computers.html"><button class="computadores">COMPUTADORES</button></a>
<a href="index.html"><button class="button">NOTEBOOKS</button></a>
<a href="index.html"><button class="button">CELULARES</button></a>
<a href="index.html"><button class="button">PERIFÉRICOS</button></a>
<a href="index.html"><button class="button">SOFTWARES</button></a>


</nav>

<section>
    <div id="destaque">
    <article style="float:left;">
    
    <div id="crono">
        <h1 style="display:block;">
        NZXT CRONOS
        </h1>
        <br>
    <span>A NOVA GERAÇÃO DE COMPUTADORES</span>
        
    <img style = "height:500px; width: 700px;"src= "_images/crono.png">
        <a href=""><button class="saiba">SAIBA MAIS </button></a>
        
    </div>
    </article>
    
    <article style="float:left;">
        
        <div id="bulldog">
        <img style= "height:500px; width: 700px;" src="_images/bulldog.png">
            
            
            
    </div>
    </article>
        
    </div>
</section>

</div>
</body>
</html>
Hello, I have a question in CSS, where I try to align an image to the right, I already tried the "float: left;" command, and I even used the "margin-left" command where I was able to move the image to the side but not aligned. How can I align the image? Anyone who could help me would be very grateful. NOTE: I am a beginner in HTML.

    
asked by anonymous 30.10.2018 / 16:04

2 answers

4

Lucas your code is very strange ... in fact it has CSS properties applied in the wrong way, for example its section is 600px, wide, and each image is 700px wide ... so no has to stand side by side ... In addition, the word article was spelled wrong and the css was not being applied to the element.

I'm going to be honest with you, I'm seeing that you're starting. I think the basicão you already know, but stop a bit to study the fundamentals. FlexBox, Position and Display study of CSS that will help you for the rest of your life. And do not be afraid to start this project again from 0, but in a more organized way in CSS.

Look at your code, run on the whole screen that you will see that now stands next to each other, simply because they now fit both on the same line ... But if I were you, I would delete everything and stop to study a little more before I go on, because this layout will never be good and will give you trouble in the future ...

@charset="UTF-8";
@import url('https://fonts.googleapis.com/css?family=Krub');
@import url('https://fonts.googleapis.com/css?family=Varela+Round');
/* CSS Document */

header {
	width:1900px;
	height:100px;
	margin:auto;
	background-color:black;
	font-family: 'Krub', sans-serif;
	color:white;
}
body{
    background-color: #363636;
}

nav {
	width:1900px;
	height:50px;
	margin:auto;
	background-color:#ff4425;
	font-family: 'Krub', sans-serif;
	position:absolute;
	display:table;
	top:100px;
	right:0px;
    border:none;
}

.button{
	float:left;
	color:black;
	border:none;
	background-color:#ff4425;
	transition-duration:1s;
	height:50px;
	width:100px;
	font-family: 'Krub', sans-serif;
	align-content: center;
    margin-left: auto;
    margin-right: auto;
}

.computadores{
	float:left;
	color:black;
	border:none;
	background-color:#ff4425;
	transition-duration:1s;
	height:50px;
	width:150px;
	font-family: 'Krub', sans-serif;
	
}

.computadores:hover{
	background-color:white;
	color:black;
	border: 0.5px solid #2f3542;
	font-family: 'Krub', sans-serif;
	cursor:pointer;
}

.button:hover{
	background-color:white;
	color:black;
	border: 0.5px solid #2f3542;
	font-family: 'Krub', sans-serif;
	cursor:pointer;
	-webkit-transition:1s; /*Chrome e Safari */
}

#crono {
    color:#F26B38 ;
    background-color:#2A2A2A;
    font-family: 'Varela Round', sans-serif;
    font-size: 30px;
    border:none;
    
}
    
}

#destaque {
    font-family: 'Varela Round', sans-serif;
    background-color:white;
    color:black;
    display:table;
}

section{
	height:1000px; 

	color:white;
}
article.crono{
	height:500px;
	width:300px;
	
	font-family: 'Krub', sans-serif;
}

.saiba{
    background-color:white;
    color:black;
    border:none;
    width:200px;
    height:100px;
    font-size: 28px;
    font-family: 'Krub', sans-serif;
    transition:0.5s;
    border:5px solid black;
    
}

.saiba:hover{
    color:white;
    background-color:black;
    border:none;
    width:200px;
    height:100px;
}

#bulldog{
    color:#e84118;
    background-color:#2A2A2A;
    font-family: 'Varela Round', sans-serif;
    border:none;
    /* margin-left:800px; */
    
    
}
<div>

<header>
<h1 align="center" >ALFA HARDWARE</h1>
</header>

<nav>
<a href="index.html"><button class="button">INÍCIO</button></a>
<a href="_sections\computers.html"><button class="computadores">COMPUTADORES</button></a>
<a href="index.html"><button class="button">NOTEBOOKS</button></a>
<a href="index.html"><button class="button">CELULARES</button></a>
<a href="index.html"><button class="button">PERIFÉRICOS</button></a>
<a href="index.html"><button class="button">SOFTWARES</button></a>


</nav>

<section>
    <div id="destaque">
    <article style="float:left;">
    
    <div id="crono">
        <h1 style="display:block;">
        NZXT CRONOS
        </h1>
        <br>
    <span>A NOVA GERAÇÃO DE COMPUTADORES</span><br>
        
    <img style = "height:500px; width: 300px;"src= "_images/crono.png"><br>
        <a href=""><button class="saiba">SAIBA MAIS </button></a>
        
    </div>
    </article>
    
    <article style="float:left;">
        
        <div id="bulldog">
        <img style= "height:500px; width: 300px;" src="_images/bulldog.png">
            
            
            
    </div>
    </article>
        
    </div>
</section>
    
30.10.2018 / 17:04
0

I understand that's what you need.

Look at the code below.

<style type="text/css">
#esquerda{
 	float: left;
}	
#direita{
		float: right;
	}
</style>

<div id="banner">
	<img src="seulogo.jpg" id="esquerda"/>
	<img src="seutexto.jpg" id="direita"/>
</div>

CODE

    
30.10.2018 / 16:15