I have been trying to centre/center my HTML audio player to be in the centre/center of my GitHub Pages static website. I have tried this in HTML and CSS. I have deleted my cache a few times to make sure that isn't the root of my problems. Chrome Browser / Mac OS 10.14.
<div class="audio">
<audio controls>
<source src="etc.mp3" type="audio/mpeg"/>
</audio>
</div>
Top of code (in style tags):
.center {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
Bottom of code: <source src="etc.mp3" type="audio/mpeg" class="center"/>
Top of code (in style tags) :
#audio {
text-align: center;
}
Bottom of code: <source id="audio" src="etc.mp3" type="audio/mpeg"/>
Top of code (in style tags):
#audio {
text-align: center;
}
Bottom of code:
<div class="audio">
<audio controls>
<source src="etc.mp3" type="audio/mpeg"/>
</audio>
</div>
Top of code (in style tags):
#audio {
vertical-align: center;
}
Bottom of code:
<div class="audio">
<audio controls>
<source src="etc.mp3" type="audio/mpeg"/>
</audio>
</div>
Top of code (in style tags):
#audio {
justify-content: center;
}
Bottom of code:
<div class="audio">
<audio controls>
<source src="etc.mp3" type="audio/mpeg"/>
</audio>
</div>
Top of code (in style tags):
#audio {
align-self: center;
}
Bottom of code:
<div class="audio">
<audio controls>
<source src="etc.mp3" type="audio/mpeg"/>
</audio>
</div>
Top of code (in style tags):
#audio {
align-self: center;
display: inline-block;
}
Bottom of code:
<div class="audio">
<audio controls>
<source src="etc.mp3" type="audio/mpeg"/>
</audio>
</div>
<div style="margin: 0 auto; display: table;">
<audio controls>
<source src="etc.mp3" type="audio/mpeg"/>
</audio>
</div>
Top of code (in style tags):
.audio-container {
display: flex;
justify-content: center;
align-items: center
}
Bottom of code:
<div class='audio-container'>
<audio controls>
<source src="etc.mp3" type="audio/mpeg"/>
</audio>
</div>
From Sandip Nirmal's answer in this thread - also attempt #9 after deleting cache
Top of code (in style tags):
.audio-container {
display: flex;
justify-content: center;
align-items: center
}
Bottom of code:
<div class="audio-container">
<audio controls>
<source src="etc.mp3" type="audio/mpeg"/>
</audio>
</div>
Try with the css like this:
.audio{
width:100%;
}
.audio audio{
margin: 0 auto;
display: table;
}
The "display: table;" is what does the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With